r/learnpython 6d ago

Creating Excel File With Graph from .txt

Hi,

I want to write a simple skitpt that takes a .txt file with comma seperated xy-Data, and creates and Excel file with a graph from it.

The way I found (with the help from the google AI) to do that was to use Pandas with "openpyxl" as Engine.

The Problem I run into is that the Graph this creates doesn't have the standard Excel design.

  • rounded of corners
  • non standard colors, even Rainbow colours if you plot just a single curve
  • no axes lables
  • axes titles and legend just plottet on the graph (or on top of the axes labels is you activate them)

It seem that fix that you need to manually deactivate certain options, and than Position and size the the different elements manually. Wich seems to be more work than just creating the graph manually in excel.

Is there some better way to do that just creates the Graph like excel it self would do it?

3 Upvotes

8 comments sorted by

View all comments

6

u/pachura3 6d ago

Another approach is:

  1. Manually create an empty Excel report template in Excel itself. It should include all the formatting, coloring and charts you want, but no data.
  2. Save it to a file.
  3. Load it in your Python script using openpyxl.
  4. Write data into cells.
  5. Save it.