为了完成这项任务,我编写了以下函数。
def write_file(url,count):
book = xlwt.Workbook(encoding="utf-8")
sheet1 = book.add_sheet("Python Sheet 1")
colx = 1
for rowx in range(1):
# Write the data to rox, column
sheet1.write(rowx,colx, url)
sheet1.write(rowx,colx+1, count)
book.save("D:\Komal\MyPrograms\python_spreadsheet.xls")
对于从给定的.txt文件中获取的每个url,我希望能够计算标记的数量并将其打印到每个excel文件中。我想覆盖每个url的文件,然后追加到excel文件。
您应该使用
xlrd.open_workbook()
加载现有的Excel文件,使用xlutils.copy
创建一个可写副本,然后进行所有更改并将其另存为。像这样的:
相关问题 更多 >
编程相关推荐