Board index » cppbuilder » Office Components

Office Components

Does't anyone use the Office Components ??
Where can we find some help on them ??

Please help .....


Re:Office Components

"Ken Stoole" <> wrote:
> Does't anyone use the Office Components ??

See thread 'TAccessForm'.


Re:Office Components

I read samples in "BCB5 Unleashed" as I remember this samples
avalaible from Internet but I have no reference.
Another way it is not using C++ Builder components for this.
Office applications support the work with OLE Automation.
This info available on MS site.
It is later binding. For this exist special type of data Variant and it
can be called VB style.
Sample for Excel:

Variant covFalse((short)false);
Variant vExcel;

Function WorkbooksP("Workbooks");
Function OpenF("Open");
Variant WorkBooks;
Variant WorkBook;

PropertyGet WS("ActiveSheet");

Function SaveAsF("SaveAs");
Function CloseF("Close");
Function QuitF("Quit");
Function NewWorkBook("Add");
PropertyGet GetActiveSheet("ActiveSheet");
bool FieldCanBeString[10]={1,1,1,1,0,0,0,0,0,0};

//Creating Excel Instance:
//Do it visible:
  vExcel.Exec(PropertySet("Visible") << Variant((short)true));

//get interface to Workbooks

//Add new workbook
//get active sheet prop.:
  Variant WorkSheet=WorkBook.Exec(GetActiveSheet);

//sending data from database to excel:
int RC=Table1->RecordCount;
for(int i=1; i <= RC; ++i)
   for(int j=0; j < Table1->Fields->Count; ++j)
        PropertySet Cells("Cells");
        WorkSheet.Exec(Cells << i << j+1 <<


//save excel data
  WorkBook.Exec(SaveAsF << "c:\\1.xls");
//close and quit:
  WorkBook.Exec(CloseF << covFalse);


Re:Office Components

Vladimir Afanasyev D???:

> I read samples in "BCB5 Unleashed" as I remember this samples
> avalaible from Internet but I have no reference.


Re:Office Components

Hi Ken,

I wrote a application that uses the TExcelApplication component in BCB v6 sp 2.  They aren't too bad if you have access to the Excel (2000 or 97) VBA book by WROX.  I also find that the online Microsoft Excel help at to be helpful too.  The biggest hurtle is to know what you want to do in Excel and then how to translate it into the component calls.  The next issue is how to connect the different types so you can call the component methods without needing to load them into individual variables all the time.  Here is a snipit of code I just posted for someone that copies the active spreadsheet to the end of the workbook:

_WorksheetPtr       ws;
Excel_2k::SheetsPtr sheets;

sheets = ExcelApplication1->get_Sheets();
ws = ExcelApplication1->ActiveSheet;
ws->Copy( TNoParam(),
          (TVariant)sheets->get_Item( (TVariant)sheets->Count ),

The copy command in basic would have been

Active.Copy After=sheets.Item( sheets.Count )
{ or something like this }

BCB doesn't let you use named parameters (i.e., After=), so you need to fill in the unused parameters with TNoParam(), in this case the first parameter, Before.  The other issue is that the VBA model lets you use the short names of the objects, so it is often difficult to know where the object fits into the component objects that TExcelApplications provides.  However, you can use the Excel VB Editor's Object Browser to look at the different objects to figure out how they fit together.

It sort of like using three dictionaries, each in different all in a laguage you don't understand to decypher a message in yet another language.  Not easy at first, but once you begin to understand the different languages you can do it.

Good luck,
Mr Phelps, er, Stoole

Oh, and yes documentation from Borland on these niffty new components might make them more useful.

"Ken Stoole" <> wrote:
>Does't anyone use the Office Components ??
>Where can we find some help on them ??

>Please help .....

Other Threads