Solved

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

Posted on 2003-11-14
6
689 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

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…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
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 viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

744 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

11 Experts available now in Live!

Get 1:1 Help Now