Solved

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

Posted on 2003-11-14
6
727 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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 additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

733 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