Excel – a simple and reliable C library for working with Excel files?

c++excel

Well… that's it.

I need something simple and reliable (doesn't have to have fancy features – I need to write and read text and numbers from Excel cells)

And yes, I would like a sample "Hello Cell" code

What do you recommend?

Best Solution

Strongly discouraged. I'd recommend using a C-friendly format (e.g. CSVs) instead of XLS, or using the new XML formats (take your pick on XML and ZIP libraries).

Still, for a quick fix, you could export to quoted CSV and then import using VBScript. Something like this, although I'd try to get it to work in VBA first.

Note that this will require a copy of Office, and will not scale well (but you can hide the Excel window).


I've just found xlsLib, so if you really need to write directly in C, give it a go! Be careful though, because it's very hard to get right, especially if you're writing to already-existing files.

There also exists LibExcel, but that's C++, so you'd need to compile a wrapper around, or rewrite for C.


One final caveat: the reason I didn't search for these at the start is that it's extremely difficult to get right. I have not used the libraries above, but I suspect they'll break in strange and unusual ways. I trust you've read Joel's take on the Office formats.