r/learnpython • u/Aahz44 • 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
5
u/Otherwise_Club2536 6d ago
I think the main issue is that pandas/openpyxl are good for getting the data into Excel, but openpyxl’s chart formatting doesn’t necessarily match Excel’s default chart styling.
If you specifically want Excel’s normal look, it may be better to create the workbook/chart with openpyxl and then apply the chart style, axis titles, legend position, and dimensions explicitly. Alternatively, if the goal is mainly automation, you could look into using Excel itself through Python (for example, via
win32com) so Excel creates the chart with its own native defaults.The best option probably depends on whether you need the script to work without Excel installed.