我编写了以下函数来完成此任务。
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 文件中。
book
对象的问题。 - Igor Hataristsheet1 = book.get_sheet(0)
。 - Igor Hatarist