Python Forum
openpyxl issue - How to reset sheet.ins_row to the real last row ...
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
openpyxl issue - How to reset sheet.ins_row to the real last row ...
#1
Hi,

I have a utility running on a Raspberry Pi which is powered from battery and is powered off and on through a 24 hour period to run this utility before a limited number of tasks are performed, then before closing creates log entries into a .xlsx sheet, due to the nature of the setup i have to run the following code to sequentially store the log entries,
sheet = wb['Sheet1']
    sheet.ins_row = str(len(sheet['A']) + 1 )
    print(sheet.ins_row)
    if (drywet)=="Wet":
        row = (cdate,ctime,drywet,"N/A","N/A")
    else:
        row = (cdate,ctime,drywet,opentime1,valveonoff)
    sheet.append(row)
    wb.save(fpath)sheet = wb['Sheet1']
    sheet.ins_row = str(len(sheet['A']) + 1 )
Then to ensure that the cells are in an orderly format i run the following.

sheet = wb['Sheet1']
rows=range(1,100)
columns=range(1,10)
for row in rows:
    for col in columns:
        sheet.cell(row,col).alignment=Alignment(horizontal='center',vertical='center',wrap_text=True)
The very first time i do this the first lines of code work OK but the second time i run it they fail as the code in the second code snippet have reset the
"last row" to 101 as the alignment above is in rows 1 thru 100

Is there a way to allow me to still format the .xlsx sheet and keep the REAL last line so the sheet.append(row) still work and possibly does the alignment at the same time? is it possible to add the alignment to the following line for example?

row = (cdate,ctime,drywet,"N/A","N/A")
Thank You
JohnW
Reply


Messages In This Thread
openpyxl issue - How to reset sheet.ins_row to the real last row ... - by ejwjohn - Nov-07-2023, 11:11 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  openpyxl rename sheet acting strange Pedroski55 1 2,096 Sep-26-2022, 08:56 AM
Last Post: buran
  Append excel sheet using openpyxl TammyP 1 2,524 Feb-02-2021, 06:32 PM
Last Post: nilamo
  Excel: Apply formating of a sheet(file1) to another sheet(file2) lowermoon 1 2,131 May-26-2020, 07:57 AM
Last Post: buran
  Openpyxl - When save existing xlsx sheet, images/drawing does not get saved shubhamjainj 2 8,686 Apr-16-2019, 07:09 AM
Last Post: shubhamjainj
  inserting photos in 1 sheet of a 6 sheet excel file fails Pedroski55 0 2,439 Mar-03-2018, 01:53 AM
Last Post: Pedroski55
  openpyxl saving files issue Pedroski55 1 6,807 Sep-16-2017, 02:05 AM
Last Post: Pedroski55

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020