I would like to print a series in my excel which goes like
OUTPUT
Data Set 1 copy.jpg
Data Set 2 copy.jpg
This is the code that I have written:
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()
but it does not create any excel file after i run this code. Thank you
That's because there is an error in your code. Below are the error and corrected code -
You cannot concatenate 'str' and 'int' objects
#erroneous line of code
ch = 'Data Set '+ a +' copy.jpg'
#use below code instead
ch = 'Data Set {} copy.jpg'.format(a)
You can also change a
to str()
for that concatenation:
ch = 'Data Set ' + str(a) + ' copy.jpg'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.