Here's what I need to do: I'm going to use C++ to produce data that I
then would like to enter into an Excel worksheet and make a graph from
it, and then display that graph. All from the user simply opening the
program.
I havn't got a clue as to how to import excel into C++ and make them
share graphs and so forth.
All you have to do is to create an ActiveX excel object:
enslavedExcel = CreateObject ("Excel.Application",...)
(or something like that)
Then you can do something like:
enslavedExcel->NewWorksheet();
You can do anything with it.
How to do this in c++ can be easily found in the msdn.
And if you need some convenient help on what you can do with
your Excel object, check the vba for excel (macro) documentation,
because if I remember correctly code completion will not help you much.
Best regards,
Andreas
2006/1/15, Misha <msha...@gmail.com>:
fprintf(fp, "%f\n", number);
fclose(fp);
}
void clearExcelSheet(char *fileName)
{
fclose(fopen(fileName, "w"));
}
I'm not exactly clear on what exactly it is that you're trying to do,
but these functions should be of some help. Here's how they work.
clearExcelSheet(fileName) is used to create a new Excel worksheet or to
delete the contents of one that already exists. For example, the
following C++ program will create a new Excel sheet called
'MySheet.xls'
#include <stdio.h>
void clearExcelSheet(char *fileName)
{
fclose(fopen(fileName, "w"));
}
int main()
{
clearExcelSheet("MySheet.xls");
return 0;
}
Run this program, then open the folder where the program is running
from. There should be an empty Excel worksheet there. But how do you
fill it with numbers? Just use the addNumberToExcelSheet function,
like this:
#include <stdio.h>
void addNumberToExcelSheet(char *fileName, double number)
{
FILE *fp = fopen(fileName, "a");
fprintf(fp, "%f\n", number);
fclose(fp);
}
void clearExcelSheet(char *fileName)
{
fclose(fopen(fileName, "w"));
}
int main()
{
int i;
clearExcelSheet("MySheet.xls");
addNumberToExcelSheet("MySheet.xls", 3.14);
for (i = 0 ; i < 5 ; i++)
addNumberToExcelSheet("MySheet.xls", (double) i);
addNumberToExcelSheet("MySheet.xls", 1337);
return 0;
}
Compile and run the above C++ program, then look in the folder where
the program file is. There should be an Excel sheet by the name of
MySheet.xls. Inside that Excel sheet, there will be the following
contents:
3.14
0
1
2
3
4
1337
All you have to do now is make a chart. I hope this answers your
question. If you were hoping to do somethign a bit more complex, like
makign a full two-dimensional table of numbers, just let me know and I
can help you out with some code. A clearer description of your problem
always helps get better replies to your posts.
Jeff Cameron
Especially Jeff, that was exactly what I was looking for. Nice and
simple too! So is the program just basically making a file called
MySheet.xls and since it ends with xls windows decides to make it
Excel? Wonderful.
As a side note, I was wondering if there is anything more Excel
specific that I can do with just a C++ program, such as:
1) Forcing this excel file to open after my code executes.
2) Forcing Excel to create a graph for me and have it ready when the
file opens(assuming (1) is possible.
Again, thank you very very much for your reply.
Sincerely,
Mikhail (Misha) Shashkov Jr.