Solved

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

Posted on 2003-11-14
6
734 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
 

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

705 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