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


Quote
"Ken Stoole" <k...@kentric.com> wrote:
> Does't anyone use the Office Components ??

See thread 'TAccessForm'.

Micha.

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:

//variables
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:
  vExcel=Variant::CreateObject("Excel.Application");
//Do it visible:
  vExcel.Exec(PropertySet("Visible") << Variant((short)true));

//get interface to Workbooks
  WorkBooks=vExcel.Exec(WorkbooksP);

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

//sending data from database to excel:
Table1->Active=true;
int RC=Table1->RecordCount;
Table1->First();
for(int i=1; i <= RC; ++i)
{
   for(int j=0; j < Table1->Fields->Count; ++j)
    {
        PropertySet Cells("Cells");
        if(!FieldCanBeString[j])continue;
        WorkSheet.Exec(Cells << i << j+1 <<
Table1->Fields->Fields[j]->AsString);
    }
Table1->Next();

Quote
}

Table1->Active=false;
//save excel data
  WorkBook.Exec(SaveAsF << "c:\\1.xls");
//close and quit:
  WorkBook.Exec(CloseF << covFalse);
  vExcel.Exec(QuitF);

Vladimir.

Re:Office Components


Vladimir Afanasyev D???:

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

http://materials.diasoft.kiev.ua/bcb5/index.html

Vladimir.

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 www.microsoft.com 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 ),
          LOCALE_USER_DEFAULT );

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.

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

>Please help .....

Other Threads