#根据索引获取Excel表格中的数据 参数:file:Excel文件路径 colnameindex:表头列名所在行的所以 ,by_index:表的索引 def excel_table_byindex(file='test.xlsx', colnameindex=0, by_index=0): data = open_excel(file) table = data.sheets()[by_index] nrows = table.nrows #行数 ncols = table.ncols #列数 colnames = table.row_values(colnameindex) #某一行数据 for rownum in range(1, nrows): row = table.row_values(rownum) if row: app = [] for i in range(len(colnames)): if (2 == table.cell_type(rownum, i)): if (colnames[i] == "month"): row[i] = int(row[i]) insert(row[0],row[1],row[2])
insert 方法就是用 pyodbc 的 cursor.execute 然后commit,这里目前是没读取一行就commit了,跑了下大概时间好像30分钟了,是不是太慢了点
excel是有30列
宝慕林4294392
相关分类