Board index » cppbuilder » word - excel

word - excel


2006-11-16 04:11:42 AM
cppbuilder63
hello
there are some tools in builder 6.0 that allow to insert word,excel
documents. I would like to ask
if its possible and how to create a form that will include a "shell" from
word. I have seen that in other
programming tools like visual fox pro,where you could open a word istance in
the visual fox pro form
and also change fonts,save etc. Is this possible in builder and how plz?
thank you very much for your time
Kind Regards
Vasilis
 
 

Re:word - excel

Yes, this can be done.
1. Drop a TOleContainer on your form.
2. In code:
OleContainer1->CreateObjectFromFile("MySpreadsheet.xls",false);
OleContainer1->AutoActivate=aaGetFocus;
3. In order to manipulate worksheets, cells etc.:
Variant WB = OleContainer1->OleObject; //this retrieves the workbook
PropertyGet GetActiveSheet("ActiveSheet");
Variant WS=WB.Exec(GetActiveSheet); //this retrieves the active
worksheet
PropertySet GR("Range");
Variant range=WS.Exec(GR << Variant("B12")<< Variant("999.99")); //this
sets the cell B-12 to the value 999.99
PropertyGet SV("Range");
Variant valueInCell=WS.Exec(SV << Variant("B12")); //reads the value in
cell B-12
4. To save any changes:
OleContainer1->SaveAsDocument("ChangedSpreadsheet.xls");
This should get you started. Using "Variant" allows us to put anything
into that variable such as a list of worksheet objects or an integer.
Microsoft has more documentation of the object models for this as well
as Word on their site:
msdn2.microsoft.com/en-us/office/aa905497.aspx
Good Luck.
~fakepoo
 

Re:word - excel

hello,
i wrote the first 2 line but i get an exception when it runs the:
OleContainer1->CreateObjectFromFile("a.xls",false);
ive put an olecontainer and i have the xls file in the project folder
is there an example of how to open excel (generaly office automation) files
through builder?
there are some components in the palete for excel office but theres nothing
in the help for them
thks
< XXXX@XXXXX.COM >wrote in message
Quote
Yes, this can be done.
1. Drop a TOleContainer on your form.
2. In code:

OleContainer1->CreateObjectFromFile("MySpreadsheet.xls",false);
OleContainer1->AutoActivate=aaGetFocus;

3. In order to manipulate worksheets, cells etc.:

Variant WB = OleContainer1->OleObject; //this retrieves the workbook

PropertyGet GetActiveSheet("ActiveSheet");
Variant WS=WB.Exec(GetActiveSheet); //this retrieves the active
worksheet

PropertySet GR("Range");
Variant range=WS.Exec(GR << Variant("B12")<< Variant("999.99")); //this
sets the cell B-12 to the value 999.99

PropertyGet SV("Range");
Variant valueInCell=WS.Exec(SV << Variant("B12")); //reads the value in
cell B-12


4. To save any changes:
OleContainer1->SaveAsDocument("ChangedSpreadsheet.xls");


This should get you started. Using "Variant" allows us to put anything
into that variable such as a list of worksheet objects or an integer.
Microsoft has more documentation of the object models for this as well
as Word on their site:
msdn2.microsoft.com/en-us/office/aa905497.aspx

Good Luck.
~fakepoo

 

{smallsort}