Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

best way to programmatically modify excel spreadsheets

Tags:

c++

excel

I'm looking for a library that will allow me to programatically modify Excel files to add data to certain cells. My current idea is to use named ranges to determine where to insert the new data (essentially a range of 1x1), then update the named ranges to point at the data. The existing application this is going to integrate with is written entirely in C++, so I'm ideally looking for a C++ solution (hence why this thread is of limited usefulness). If all else fails, I'll go with a .NET solution if there is some way of linking it against our C++ app.

An ideal solution would be open source, but none of the ones I've seen so far (MyXls and XLSSTREAM) seem up to the challenge. I like the looks of Aspose.Cells, but it's for .NET or Java, not C++ (and costs money). I need to support all Excel formats from 97 through the present, including the XLSX and XLSB formats. Ideally, it would also support formats such as OpenOffice, and (for output) PDF and HTML.

Some use-cases I need to support:

  • reading and modifying any cell in the spreadsheet, including formulas
  • creating, reading, modifying named ranges (the ranges themselves, not just the cells)
  • copying formatting from a cell to a bunch of others (including conditional formatting) -- we'll use one cell as a template for all the others we fill in with data.

Any help you can give me finding an appropriate library would be great. I'd also like to hear some testimonials about the various suggestions (including the ones in my post) so I can make more informed decisions -- what's easy to use, bug-free, cheap, etc?

like image 474
rmeador Avatar asked Jan 13 '09 16:01

rmeador


1 Answers

The safest suggestion is to just use OLE. It uses the COM, which does not require .NET at all.

http://en.wikipedia.org/wiki/OLE_Automation <--about halfway down is a C++ example.

You may have to wrap a few functionalities into functions for usability, but it's really not ugly to work with.

EDIT: Just be aware that you need a copy of Excel for it to work. Also, there's some first-party .h files that you can find specific to excel. (it's all explained in the Wikipedia article)

like image 75
user54650 Avatar answered Oct 20 '22 19:10

user54650