简体   繁体   中英

auto increment row in xls and update it's values using python

Facing issue while automatically updating an xls file ( Row and column) using python.

Example: ( This is for first and second row, want to automatically increase the row values and correspondingly update it's values )

For first row

sheet1.write(0, 0, Number)
sheet1.write(0, 1, algo_type.tag)
sheet1.write(0, 2, ref_slope)
sheet1.write(0, 3, opt_slope)
sheet1.write(0, 4, angle)

For second row

sheet1.write(1, 0, Number)
sheet1.write(1, 1, algo_type.tag)
sheet1.write(1, 2, ref_slope)
sheet1.write(1, 3, opt_slope)
sheet1.write(1, 4, angle)

Please suggest how to takel this type of situations.

Thanks, Niraj

You could put the write in a loop to increment the row number.

maxRows = 10   # or however many rows you want
for rowNumber in range(maxRows):
    sheet1.write(rowNumber, 0, Number)
    sheet1.write(rowNumber, 1, algo_type.tag)
    sheet1.write(rowNumber, 2, ref_slope)
    sheet1.write(rowNumber, 3, opt_slope)
    sheet1.write(rowNumber, 4, angle)

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.

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