繁体   English   中英

想使用 python 在 excel 中打印一系列字符串

[英]want to print a series of string in excel using python

我想在我的 excel 中打印一个系列,就像

OUTPUT

Data Set 1 copy.jpg

Data Set 2 copy.jpg

这是我写的代码:

import itertools
import xlsxwriter

book = xlsxwriter.Workbook(r'E:\license8.xlsx')
sh = book.add_worksheet()
a = 1

for a in range (1,1320):
    ch = 'Data Set '+ a +' copy.jpg'
    sh.write(a,0,ch)
    a = a+1
book.close()

但在我运行此代码后,它不会创建任何 excel 文件。 谢谢

那是因为您的代码中有错误。 以下是错误和更正的代码 -

您不能连接 'str' 和 'int' 对象

#erroneous line of code
ch = 'Data Set '+ a +' copy.jpg'

#use below code instead
ch = 'Data Set {} copy.jpg'.format(a)

您还可以将该连接a更改为str()

ch = 'Data Set ' + str(a) + ' copy.jpg'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM