简体   繁体   中英

I want to update the last row in an excel spreadsheet, daily. OpenPyXl

The following is an excerpt from a function (whose remaining body has been excluded; nothing to do with this issue and has already been tested to make sure has no faults).

Objective: Get "val1a" (a dollar value acquired from another part of the function) and "t" to update daily to an excel spreadsheet.

Right now, I have them mapped to the A2 and B2 cells, respectively. I can't figure out how to make them populate the latest row, whenever the function is run. (A2:B2, A3:B3, and so on...)

t = date.today()
ts = datetime.time(datetime.now())
wb = load_workbook('val1a.xlsx')
sheet = wb.worksheets[0]
# grab the active worksheet
ws = wb.active

ws['A1'] = 'PRICE'
ws['B1'] = 'DATE'
ws['C1'] = 'FED'
ws['D1'] = 'CTD'

ws['A2'] = val1a
ws['B2'] = t


# Save the file
wb.save('a1 ' + str(t) + ".xlsx")
# how to read values in excel
read1 = ws['A2'].value

ws.append()始终将值放在电子表格的下一行中。

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