C++ library to read a document, created within "Open Office Calc" - openoffice-calc

I have the file created within "Open Office Calc" which I need to load into my C++ program to generate some game-specific code for which this design file was written. All I need is spreadsheets names, fields data and formulas results.
Is there a way to do so?
Thank you.

All OpenOffice files are zip-archives, with the contents in publicly specified XML files. Might be some work but would not be impossible to get the data you need with the help of most available XML-parsers.

Related

How to read Excel data from C++ project

I my c++ project I want to open an excel file and query data and identify the rows that matches the specific column values(more than one column). What is the best methodology to connect to excel and query the worksheets?
The excel might contain several thousands of records and hence it is very important to complete the search and show the results in quick time and optimum performance.
Request you to let me know more than one option and suggest the best out of it.
See here for a library (under an open CPOL) license another Stackoverflow user recommends:
https://stackoverflow.com/a/2879322/444255

Beginner - data storage through XML or text files

I am a beginner in visual studio and has only code C and C++ in command line settings.
Currently, I am taking a module(software development) which requires me to come up with an expense tracker - a program which helps user tracks his/her daily expenses. Therefore, at the end of each individual day, or after a user uses finishes the program, we would have to perform data storage to store all the info in one place which we would export it during the next usage.
My constraint include not using any relational database(although i have no idea what it is :( ). Data storage must be done using XML or text files. Following this, I have several questions regarding data storage:
1) If data is stored successfully, do we export it everytime we start the program? And everytime after the user closes the program, we overwrite the existing data file and then store it accordingly?
2) I have heard from some people that using text file may be easier. Searching on the internet and library only provides me with information regarding XML and not text. Would anyone be able to help me with it? Like tutorials link and stuff?
Thank you very much!
File writing/handling works similar to every other buffer in c++.
you can enable file handling using the fstream header. You can create a file, write to it and over-write every time the program is run, or can even create a file the first time the program is run and then append to it every subsequent time the program runs.
Ive only ever done text files, never tried XML, but Im guessing they're similar.
http://www.cplusplus.com/doc/tutorial/files/ should give you everything you need to know.
Your choice of XML vs plain text depends on the kind of data that you'll be storing.
The reason why you'll only find XML libraries on the internet is because XML is a lot more complicated than plain text. If you don't know what XML is or if the data that you're storing isn't very complex, then I would suggest going with plain text.
For example, to track expenses, you might store a file like this:
sandwich 5.00
coffee 2.30
soft drink 1.50
...
It's very easy to read/write lines like this to/from a file in C++.

Programmatically creating Excel file in C++

I have seen programs exporting to Excel in two different ways.
Opening Excel and entering data cell by cell (while it is running it looks like a macro at work)
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++.
Do I need different SDKs for .xls and .xlsx?
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).
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?
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.
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.
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.

Read all files in a folder then place each file and its match in new excel document. Is it possible with C++?

I have a folder that contains 300 different files. There are 150 .cft files and 150 .s01 files. Each .cft file has a corresponding .s01 file of the same name. I would like to create a program that can read the files from the folder and place each .cft file and its corresponding .s01 file into an excel document. I would like the .cft file to be on the first worksheet in the document and the .s01 file to be on the second sheet. Then I would like the program to save the file and name it (---------).xls. The (---------) would be the name of the .cft and .s01 file since they are both the same.
So!!! I wrote a program that is able to take the .cft file and the .s01 file, append them and place them in a user defined .xls document. However...I don't want to manually get the names of the 150 files and have to type each one into the program. I also don't want the files to be placed on the same worksheet.
So!!!! I don't want to waste time trying to code something impossible, so before I spend anymore time on this I have a few questions:
Is it possible to read all of the files in a folder and match files of the same name but with different types?
If this is possible, is it then possible to place the corresponding .cft file and .s01 file in the same excel document but on different worksheets?
Then, is it possible to create and save this worksheet as (---------).xls, (-------) being the name of the matching .cft and .s01 file?
So basically...I want to write this code because I am lazy and I don't want to do anything manually ><;;; lol
Example:
The main folder contains 8 files:
dog.cft dog.s01 cat.cft cat.s01 tree.cft tree.s01 bird.cft bird.s01
The program reads all of the files in the folder and recognizes that dog.cft and dog.s01 go together.
The program then creates an excel document and on worksheet 1 places dog.cft and on worksheet 2 places dog.s01.
The program then saves the excel document as dog.xls
Then the program loops through the main folder repeating this process for each of the .cft and .s01 pairs until all 150 pairs have been separated and saved in their own excel document.
I don't know if I'm dreaming a little too big with this but any advice is much appreciated!
personally I would do this with a macro in excel rather than in c++ because doing excel related functions is much easier that way. All of the requirements are possible using VBA within excel.
Yes, it's possible.
For the listing of files in a folder, you can use the Windows API functions FindFirstFile and FindNextFile. When you finish iterating the folder, you'll need to call FindClose.
For creating the Excel spreadsheet and working with the workbook's sheets, you can use COM automation. Here's a link to an article on doing so from C++ (MFC); the article explains where to find one that isn't MFC based.
If you get started and have specific questions about either of the tasks, please post them as separate questions. This should have been two individual questions, in fact - one about iterating the content of a folder and a different one about working with Excel files from C++.

Prgrammably making excel spreadsheets (97 - 2003 format)

I was wondering how difficult it would be to make an application like this. Basically, I have some old html files that use tables. I want to put these tables into excel for easier reading and manipulation. I only have text, I have no numbers of formulas or anything.
Are there any tutorials on how to do this sort of thing?
The application would produce .xls
Thanks
You have three options:
Output a CSV file. While not an XLS file, Excel is more than capable of opening such a file, and it's extremely easy to create. You need nothing more than standard C++ to implement this solution. This is by far the easiest and quickest way to output to Excel (or any spreadsheet program, for that matter).
Use OLE automation. Microsoft even has a Knowledge Base article that provides an example of how to invoke Excel from your native C++ application and fill in some values. If you absolutely need to output XLS files, this is the easiest way to go. Note that users must have Excel installed on their computers for this to work.
Create your own XLS writer. Don't even bother with this option unless you really want to generate XLS files without requiring Excel to be installed on end-user computers. Options 1 and 2 are more than good enough for just about any application.
You don't need to reverse-engineer the XLS format; Microsoft documents the excel file format here. Due to the evolution of Excel over the years, it's not exactly a clean specification.
If you don't mind installing a copy of Excel along with your program, using OLE Automation would be much easier.
The simplest thing to do is simply create a CSV file. If you have column headers, put them in the first row. CSV files can be opened natively in Excel as if they were Excel spreadsheets.
There is a trick here: save .html tables with the .xls extension and Excel can read them (ie Excel can read the output of the DataGrid control).
But, if you want to create 'real' Excel files, then you can either use Excel Interop (which could be messy, requires Excel and the PIA's to be installed on the machine, and needs careful memory management (since its COM)). You could also opt for a 3rd-party library like FlexCel - which will avoid many of the InterOp problems but will not give you 'complete' Excel functionality (addins, custom vba macros etc.). For most uses, however, a 3rd party library should do the trick.
Looks like there's another alternative called ExcelFormat. I didn't try it, though.