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
Solved

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

Posted on 2003-11-14
6
716 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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…

792 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