我目前正在编写一个python脚本,它将获取任意数量的csv文件并从中创建.xls文件。不幸的是,其中一些csv文件的行数大于65536,这意味着它们不能存在于一个.xls工作表中。我想做的是想出一种方法,当达到这个行数时生成一个新的工作表。以下是我当前使用的代码,供参考:import csv, xlwt, glob, ntpath
files = glob.glob("C:/Users/waldiesamuel/326/*.csv")
bold = xlwt.easyxf('font: bold on')
for i in files:
org_file = open(i, 'r')
reader = csv.reader((org_file), delimiter=",")
workbook = xlwt.Workbook()
sheet = workbook.add_sheet("SQL Results")
path = ntpath.dirname(i)
file = ntpath.basename(i)
for rowi, row in enumerate(reader):
for coli, value in enumerate(row):
if coli == 0:
sheet.write(rowi,coli,value,bold)
else:
sheet.write(rowi,coli,value)
workbook.save(path + file + '.xls')
我的想法是
^