Echoing some of the above ...
If Excel is ultimately what you want to use to format your data, then you can (and should ...) use Excel to retrieve that data, too.
If that does not work out, then consider the hybrid approach of using Perl to generate an XML file. (Use any one of several XML-manipulation CPAN packages ...) Then, open a spreadsheet which specifies that file as an external data-source. Now, you can use Excel to specify all of the graphing, any secondary calculations, and so forth. You can change anything about the Excel spreadsheet within that product. You can also create any number of spreadsheets which draw from the same data-source. The only thing your program has to be able to do is to produce that data in the format that you have chosen.