-1

For the report I use this code:

from openpyxl import load_workbook

ReportName = "tets.xlsx"
new_row_data = [
    ["value", 'value2', "value3"]] 
wb = load_workbook(ReportName)

# Select Second Worksheet 
ws = wb.worksheets[1]

# Append 1 or 2(if multiple) new Rows - Columns A - D
for row_data in new_row_data:
     # Append Row Values
     ws.append(row_data)
wb.save(ReportName) #save the file

It has no errors, but I don't understand why sometimes it doesn't make the report inside the excel file, it saves the excel file, then when I open it, I don't see the values. Do you know a better way or more solid way to make the auto report?

Pren Ven
  • 177
  • 1
  • 10
  • I use Pandas for saving xlsx, never had any issue. However if I was you I would dig in why bug occures. Is it data dependent? – jacekblaz Mar 03 '22 at 09:35
  • Are you sure the file you are saving is the same one you are subsequently checking? – khelwood Mar 03 '22 at 09:35
  • @jacekblaz Yes, I have to write some "float" and "string" values previously defined. Maybe I sould use pandas too – Pren Ven Mar 03 '22 at 09:39
  • @khelwood yes because i have only one excel file inside the directiory, and sometimes the report works. – Pren Ven Mar 03 '22 at 09:40
  • You also need to check that you are looking in the correct directory. You do not specify a directory in your code. – khelwood Mar 03 '22 at 09:54
  • @khelwood I don't need to specify it because I run the code using Jupyter Lab. I will check again my datas. – Pren Ven Mar 03 '22 at 10:02

1 Answers1

0

I would recommend using CSV files, that can be loaded into excel. Python is really great at working with CSVs. Here is a link that might be useful.

[https://docs.python.org/3/library/csv.html][1]

AlexAlbu
  • 76
  • 3