links77
links77

Reputation: 1454

Programmatically creating Excel file in C++

I have seen programs exporting to Excel in two different ways.

  1. Opening Excel and entering data cell by cell (while it is running it looks like a macro at work)
  2. Creating an Excel file on disk and writing the data to the file (like the Export feature in MS Access)

Number 1 is terribly slow and to me it is just plain aweful.

Number 2 is what I need to do. I'm guessing I need some sort of SDK so that I can create Excel files in C++.

  1. Do I need different SDKs for .xls and .xlsx?
  2. Where do I obtain these? (I've tried Googling it but the SDKs I've found looks like they do other things than providing an interface to create Excel files).
  3. When it comes to the runtime, is MS Office a requirement on the PC that needs to create Excel files or do you get a redistributable DLL that you can deploy with your executable?

Upvotes: 10

Views: 28297

Answers (3)

matiu
matiu

Reputation: 7725

I'm doing this via Wt library's WTemplate

In short, I created the excel document I wanted in open office, and save-as excel 2003 (.xml) format.

I then loaded that in google-chrome to make it look pretty and copied it to the clipboard.

Now I'm painstakingly breaking it out into templates so that Wt can render a new file each time.

Upvotes: 0

Emir Akaydın
Emir Akaydın

Reputation: 5823

You can also try working with XLS/XLSX files over ODBC or ADO drivers just like databases with a limited usage. You can use some templates if you need formatting or create the files from stratch. Of course you are limited by playing with the field values that way. For styling etc. you will need to use an Excel API like Microsoft's.

Upvotes: 0

Baltasarq
Baltasarq

Reputation: 12212

You can easily do that by means of the XML Excel format. Check the wikipedia about that:

http://en.wikipedia.org/wiki/Microsoft_Excel#XML_Spreadsheet

This format was introduced in Excel 2002, and it is an easy way to generate a XLS file.

Upvotes: 12

Related Questions