Solved

How to use TExcel.. VCL to retrieve an existing excel files & modify them

Posted on 2003-11-14
6
700 Views
Last Modified: 2012-05-04
Hello! I use BCB5 TExcelApplication & other VCLs to retrieveing the existing excel files. I could connect and open an existing excel file. But I don't know how to code for locating an specificed Cells and modify these data. There are not any  examples for Excel from Borland. Anybody could give me some examples or tell me how to code to connect an Excelworkbook & Excelsheet and modify at a specific cells.
0
Comment
Question by:abdate
  • 3
  • 3
6 Comments
 
LVL 6

Expert Comment

by:GloomyFriar
ID: 9750022
0
 

Author Comment

by:abdate
ID: 9751867
Thanks,GloomyFriar!
Yes, I know these two URL, because you tell me on Delphi topics.
My problem is:I use Borland C++ and  I am not familiar BCB OLEfunction to tranlate from Delphi to BCB. There are no on line help and only one example for Word by Borland. I write down the following to open an existing Excel file and I don't how to translate the following Delphi codes

 Drag 3 VCL as xlsApp, xlsWB & xlsWS
 WideString _filename="..\test.xls";
 xlsApp->Workbooks->Open(_filename);
 xlsWB->ConnectTo(XLApp->Workbooks->get_Item(1));
 xlsWS->ConnectTo(xlsWB->Worksheets->get_item(1)); //compiler error here
 xlsWS->Activate;                                                        //compile error here
 xlsWS->Cells->SpecialCells(Excel_2k::Range)->Activate;//Compiler error here
then how to modify them ?
.....................................

Regards
abdate


 
0
 

Author Comment

by:abdate
ID: 9753518
Drag 3 VCL as xlsApp, xlsWB & xlsWS
Then the following is the BCB code I made
 WideString _filename="..\test.xls";
 xlsApp->Workbooks->Open(_filename);
 xlsWB->ConnectTo(XLApp->Workbooks->get_Item(1));
 xlsWS->ConnectTo(xlsWB->Worksheets->get_Item(1));
 xlsWS->Activate();
There are no compiling error for the above codes,
then I try to modify xlsWS Cells data,font and colorindex like Delphi Codeing
xlsWS.Range['A1','A1'].Value := 'Hello World';
vMSExcel.Selection.Interior.ColorIndex := 6;
But I cannot, That's my problem



 
then how to modify them ?
.....................................
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 6

Expert Comment

by:GloomyFriar
ID: 9753850
Ok, I'll try to compile that.
0
 
LVL 6

Accepted Solution

by:
GloomyFriar earned 50 total points
ID: 9758386
The working code is below. It do not use vcl components, but it really works ;-)

Variant XL,v0,v1,v2;

XL=CreateOleObject("Excel.Application.8");
XL.OlePropertySet("Visible",true);
v0=XL.OlePropertyGet("Workbooks");
v0.OleProcedure("Add");
v1=v0.OlePropertyGet("Item",1);
v0=v1.OlePropertyGet("Worksheets") ;
v0.OlePropertyGet("Item",1).OlePropertySet("Name","yellow");
v0.OlePropertyGet("Item",2).OlePropertySet("Name","red");
for (int j=1;j<3;j++)
{
v1=v0.OlePropertyGet("Item",j);
for (int i=1;i<11;i++)
{
v1.OlePropertyGet("Cells").OlePropertyGet("Item",i,1).OlePropertySet("Value",i);
v1.OlePropertyGet("Cells").OlePropertyGet("Item",i,2).OlePropertySet("Value",i*5);
v2=v1.OlePropertyGet("Cells").OlePropertyGet("Item",i,2);
v2.OlePropertyGet("Font").OlePropertySet("Color",clBlue);
v2.OlePropertyGet("Font").OlePropertySet("Bold",true);
v2.OlePropertyGet("Interior").OlePropertySet("ColorIndex",9-3*j);
}
v1.OlePropertyGet("Cells").OlePropertyGet("Item",11,1).OlePropertySet("Value","=SUM(A1:A10)");
v1.OlePropertyGet("Cells").OlePropertyGet("Item",11,2).OlePropertySet("Value","=SUM(B1:B10)");
}
XL.OlePropertySet("DisplayAlerts",false);
XL.OlePropertyGet("Workbooks").OlePropertyGet("Item",1).OleProcedure("SaveAs","test.xls");
XL.OleProcedure("Quit");
0
 

Author Comment

by:abdate
ID: 9758526
Thank you very much!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now