0

ive got a problem.

I want to write a dataframe to an existing Excel-List which contains formulas. When i Open a workbook and use a writer with pandas, it always says there is unreadable content in it and i need to repair it when i open the Excel-List.

Do you know how to resolve this?

Here is my code to write the list:

def Writer():
    book = load_workbook(r'C:\Users\List.xlsx')
    writer = pd.ExcelWriter(r'C:\Users\List.xlsx',header=None,
     index=False, data_only=True)
    
    writer.book = book

    writer.sheets = dict((ws.title, ws) for ws in book.worksheets)
    datafin=FindReqdata.datafin
    datafin.to_excel(writer, sheet_name="SheetName", startrow=2,
     startcol=5, index=None, header=None)
    writer.save()

    



Writer()
Thorte
  • 31
  • 5
  • 1
    Does this answer your question? [How to write to an existing excel file without overwriting data (using pandas)?](https://stackoverflow.com/questions/20219254/how-to-write-to-an-existing-excel-file-without-overwriting-data-using-pandas) – Warcupine Mar 25 '21 at 12:41
  • Thats where i got the middlepart from but sadly it damages my excel-file – Thorte Mar 25 '21 at 12:45

2 Answers2

0

have a look at this: https://stackoverflow.com/a/38075046/14367973

If i understood your question, you want to append more rows to a .xlsx file. The new rows are from a dataFrame that have the same number of columns than the excel file. If it is what you are trying to do the answer above should help you.

Keep the xlsx files closed while the script run sometimes it can break it.

0

Ok so apparently openpyxl has a problem with connection in the excel spreadsheet. Because one Sheet has connections in it, the file is broken after editing it. I am still trying to fix this bug.

Thorte
  • 31
  • 5