C++ Reading data from excel file and treating them as variables - c++

I am using C++ & CLR to create a GUI in Visual studio. The whole app is like a calculator for the price of transport and the costs associated with it for my work. At work, we are using Helios and we are able to export certain data to Excel. Specifically, the prices of transport, packaging materials, etc. And what I need is for my program to be able to read certain cells in Excel where prices and other variables are recorded and calculate with it so that I don't have to rewrite all the values manually in the source code.
I spent a lot of time looking for a solution but couldn't find anything that referred to my problem. Is it even possible to build such a program? I don't want anyone to solve it for me. Maybe I just missed some banality and just need some direction. And as far as I understand, the CSV format is irrelevant for me, because I need to work with a few specific cells that Helios pre-fills for me in the Excel sheet.

Related

How to write to, edit, and retrieve specific cells from an Excel doc with C++?

Basically, I want to be to be able to pass data between Excel cells and
my C++ program. I don't have any experience in Excel/C++ interactions and I haven't been able to find a coherent explanation or documentation on any websites. If someone could link me some references or provide one themselves it would be much appreciated. Thanks.
If this is for a Windows system, you could always use one of the available managed Excel libraries, such as OfficeWriter or Aspose.
There also might be similar libraries specifically for c++, I know we (OfficeWriter) used to make one.
Edit: Looks like there are a few out there, like LibXL and BasicExcel.
If the application will run on an end user machine with Excel installed, you can easily use the Excel interop and keep Excel hidden.
In addition to LibXL and BasicExcel mentioned by smoore, there is:
ExcelFormat Library is an improved version of the BasicExcel library and will allow you to read and write simple values. It is free.
xlslib will also read and write simple values, I have not tried it tho. It is also free.
Number Duck, is a commercial library that I have written, It supports reading and writing values, formulas and pictures. The website has examples of how to use the features.

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++.

C++/MFC - How to export window contents to Excel? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Excel files and C++
I am using an API called UltimateGrid which allows me to easily create Excel-like grids using C++/MFC. I need a way to export all of the contents of these grids to an actual Excel document. I could not find anything about this in the documentation for this API. Then I got to thinking ... exporting contents to an Excel document is a common requirement in applications. I was thinking about creating a right-click menu option for exporting a grid to Excel. I feel like I am reinventing the wheel as I start to code this. I googled around and saw a lot of common ways of dealing with this when database tables are involved. But that is not the case here. My underlying "datasource" is not a database table, but rather just some business objects internal to the application. Am I going to have to just write my own custom handler that iterates through the business objects corresponding to the rows and output them to a CSV file to be used by Excel?
I'm not sure how automated you want this to be. I did this a while back (as in years ago), so forgive me if this info is out of date. Here's what I remember:
CSV is fine, as long as you don't want to export formats, graphs, etc...
You should be able to access the Excel object from your C++ code, and Microsoft should have documentation on how to do this.
It may be easier to have your C++ generate a VBScript to access the component, since last I checked, there was much less red tape to doing it that way, but you could run into permissions/security issues with this method.
Also, have you checked to see if UltimateGrid supports other export formats that are compatible with Excel?
If there are no other options, I think you might want to look into DDE (Dynamic Data Exchange).
There could be a limitation on that OS should be Microsoft Windows, however you might be able to find some open source/runtime that supports other OSs as well.
One that I used long ago was NDde.

alternative for jasperreport in c++

from a c++ program i need to print a simple label. the label contains a text, an image and a barcode.(in my project the label is more complex, this is just for example)
my customer need a way to customize che label layout.
in the past in java I solve this problem using a report created with jasperreport. my customer customize the report with ireport and then i fill the data with an hashtable datasource (i never connect to an sql database)
anybody know a way to obtain something like this in java
really sorry for my scholastic english
Offhand, it's a bit hard to say -- most report generators assume some sort of database (SQL or at least accessible via ODBC) as the data source. I'd probably look into some that are free and include source code so you can change the data source (though I've no idea how difficult a modification that will be).
The other problem is that printing anything but plain text is somewhat non-portable; you'll need different code for Linux, Mac/OS or Windows. For Windows, one possibility would be Report Generator from CodeProject.com. If you want something more portable, you could use something like Xport to create XHTML output to be viewed in/printed from a browser (or any number of other programs that understand [X]HTML (there's also a commercial version). Of course, you could generate output in any number of other formats that support graphics, such as Postscript/PDF, LaTex, etc. This lets you use portable code to generate the report, but usually requires some non-portable code to invoke a viewer.

How do I plot the output from a C++ Win32 console app?

I have a small Win32 console application which is essentially a test harness. I read data in, do some processing on it and currently just output some of the numbers to the console. This isn't a huge problem - I can get an idea of what the data looks like, but it would be much easier to analyse if there was a way of getting that information into a graph for each run of the software.
I've been getting to grips with GNUPlot recently, but can't work out a simple way to get the data sent to it. Has anyone tried this? ..or is there another graphing application I should try?
Excel and OO Calc are great tools and I've loaded .csv data into them for graphing data plenty of times myself. I was, however, hoping for a way to dynamically pipe data into a graphing application to avoid having to close/reopen excel and plot a graph each time I want to look at some data.
I think you can pipe data into GNUPlot (which is why I mentioned it) but the details of how to do so are rather scant.
A simple approach is to wtite the data out as CSV and then import it into a spreadsheet like Excel or OpenOffice to do the graph drawing.
Edit: Following your question, I got interested in GNUPlot myself - this is the simplest description of using it from the command line that I found: http://www.goldb.org/goldblog/CommentView,guid,f378e279-eaa5-4d85-b7d2-0339a7c72864.aspx
Never underestimate the power of Excel and a .csv data dump.
Writing data to a .csv file form C++ is not very difficult and there's lots of articles out there regarding the subject, for example: here, or just google.
Excel can easily load .csv's and then you can just use that to plot whatever graphs you require. THis is particularly useful if you just want a quick visual sanity check of results etc.
You don't really need to touch VBA to do this
In Excel you can set up a Data Connection to a file, it supports many files type but CSV does work fine.
Go to List item
Data Tab
Click Connections
Click Add
select the file
go to the connection properties - un-tick prompt for file name
set the required period.
close the connections dialog
select the start cell for importing the data - cell 1a on worksheet 2
click existing connections
select you data connection
flip to worksheet1 add your chart and hookup the data.
the chart will now update automatically
this is Excel 2007 - but think older version had this and I think OO can do it to.
You might also want to look into XMGrace which allows you to launch it and drive it dircetly from C/Fortran programs as shown here
Excel is completely script-able. Use the macro recorder to figure out the steps. Create the chart in its own sheet. Then save the chart using the GIF filter.
The actual import is something like:
ActiveChart.Export FileName:=something_dot_gif, FilterName:="GIF"
I just found an example of piping data into gnuplot on Cardiff University's website. Not tried it yet, but it looks promising!
[edit] ..and another which includes some notes for windows.
You can use MathGL - it can create a window (FLTK, GLUT or Qt) and display plot inside. Also it have large set of plot types and can work in console.