Last active
December 21, 2017 09:16
-
-
Save shikaiwen/6a7e3eb53c9cf86d979e90b2ba2035be to your computer and use it in GitHub Desktop.
parse excel with openpyxl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding:utf-8 | |
''' | |
Created on 2017/12/20 | |
@author: shikw | |
''' | |
import sys | |
import unittest | |
import openpyxl | |
from openpyxl.xml.constants import MAX_ROW | |
wb = openpyxl.load_workbook('C:/Users/shikw/Desktop/ドキュメント/data.xlsx') | |
sheet = wb.get_sheet_by_name(wb.get_sheet_names()[0]) | |
sheet = wb.get_sheet_by_name('Sheet1') | |
maxrow = sheet.max_row | |
maxcol = sheet.max_column | |
pattern = """{ field: 'index_{0}', caption: '{1}', size: '10%',type: "text",hidden:false, render:function(record, index, column_index){ | |
return record[{2}] | |
}}, | |
""" | |
for i in range(1,21): | |
title = (sheet.cell(row=3,column=i).value or "") | |
mystr = pattern.replace("{0}", str(i-1)).replace("{1}", title).replace("{2}", str(i-1)) | |
print(mystr, end="") | |
exit() | |
for i in range(1,maxrow): | |
print("\n") | |
# print("j" + i) | |
for j in range(1,maxcol): | |
print((sheet.cell(row=i,column=j).value or "" )+ "\t" , end="") | |
# print("j" + str(j)+ "\t") | |
# sys.stdout.write(".") | |
# sys.stdout.flush() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment