0

There are two sheets in the excel file: SheetA and SheetB

My SheetA has formula linking data to SheetB. I want to update SheetB on daily basis so that SheetA's info could be updated on daily basis as well.

My code is as follows but it deletes SheetA.

path1 = <file location>
book = load_workbook(path1)
writer = pd.ExcelWriter(path1, engine = 'openpyxl')
writer.book = book
df.to_excel(writer, "SheetB", index = False)
writer.save()
writer.close() 
Pranav Hosangadi
  • 23,755
  • 7
  • 44
  • 70
palapara
  • 15
  • 1
  • 1
    Does this answer your question? [Save list of DataFrames to multisheet Excel spreadsheet](https://stackoverflow.com/questions/14225676/save-list-of-dataframes-to-multisheet-excel-spreadsheet) – Pranav Hosangadi Oct 28 '20 at 15:25
  • Thanks! I just tried, but my SheetA is still deleted. Is there a way to keep SheetA while replacing SheeB? – palapara Oct 28 '20 at 15:42
  • Did you read both sheets? Once you read in both sheets, you can make your changes to the second one and write them both using the technique from the link – Pranav Hosangadi Oct 28 '20 at 15:44
  • you mean read SheetA and then write SheetA again? wouldn't that break the formulas besides I also have some charts on that sheet. – palapara Oct 28 '20 at 15:56

0 Answers0