C++ Builder and Excel files

This is a discussion on C++ Builder and Excel files within the Windows Programming forums, part of the Platform Specific Boards category; I need to generate Excel files based on database queries. I accomplished what I wanted to some extent. I use ...

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    7

    C++ Builder and Excel files

    I need to generate Excel files based on database queries.
    I accomplished what I wanted to some extent.
    I use a TExcelApplication component to connect to Excel and fill the matrix with data gathered from a database query.
    But I'm having trouble generating more than one file within the same run of the program.
    The first file is ok , but when i try to load a second excel workbook it won't display anything but the header of the excel window.Besides if i try to fill a second workbook ,it causes Excel to raise an error when exiting.

    Here is quite how I do it,any help regarding what is wrong will be appreciated
    Second run of the below (trimmed)code does not work properly:
    BTW : Conenct Kind of the component is ckRunningOrNew and AutoConnect , AutoQuit are false

    Code:
    TExcelApplication *Excel;
    
    TExcelWorksheet *ExcelWS = new TExcelWorksheet(this);
    TExcelWorkbook  *ExcelWB = new TExcelWorkbook(this);  
    
    ExcelWS->ConnectKind = Excel->ConnectKind;
    ExcelWB->ConnectKind = Excel->ConnectKind;
    
    Excel->Connect();
    
    Excel->Workbooks->Add(EmptyParam,LOCALE_USER_DEFAULT);
    ExcelWB->ConnectTo(Excel->ActiveWorkbook);
    ExcelWS->ConnectTo(Excel->ActiveSheet);
    Excel->set_SheetsInNewWorkbook(LOCALE_USER_DEFAULT, 1);
    
    // .....
    // Fill the matrix ... this is ok ...
    // ....
    
    // save file...
    ExcelWB->SaveAs((OleVariant)wcTmp,(OleVariant)xlNormal, EmptyParam, EmptyParam, (OleVariant)false, (OleVariant)false,
                        xlNoChange,(OleVariant)xlUserResolution,(OleVariant)false,EmptyParam,EmptyParam,LOCALE_USER_DEFAULT);
    
    delete wcTmp;
    
    Excel->set_Visible(LOCALE_USER_DEFAULT,xlSheetVisible);
            
    ExcelWS->Disconnect();
    ExcelWB->Disconnect();
    
    delete ExcelWS;
    delete ExcelWB;
    Last edited by Salem; 09-23-2004 at 01:03 PM. Reason: [monty]tag tag tag tag tag tag tag tag tag tag tag tag tag tag[/monty]

  2. #2
    Code Monkey Davros's Avatar
    Join Date
    Jun 2002
    Posts
    812
    Can't you export the data as a comma (CSV) or tab separated text file? All spreadsheets can open these.
    OS: Windows XP
    Compilers: MinGW (Code::Blocks), BCB 5

    BigAngryDog.com

  3. #3
    Registered User
    Join Date
    Sep 2004
    Posts
    7
    No , I can't
    I need to format the data

    Thanks yet

  4. #4
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    I dont use Borland...I could help you in VC++ if you have access?

    You could give anonytmouse's DispHelper library a go. Not sure if it will work on Borland but it might work for you

    Feedback wanted - DispHelper

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. looking for Borland Builder hints
    By BrownB in forum Tech Board
    Replies: 3
    Last Post: 11-07-2006, 10:57 AM
  2. Accessesing Excel files from borland c++ builder 6
    By warturtle in forum Windows Programming
    Replies: 4
    Last Post: 09-22-2005, 12:50 AM
  3. TExcelApplication problem in Builder
    By mfdemi in forum C++ Programming
    Replies: 0
    Last Post: 12-23-2004, 01:42 AM
  4. C++ Builder DataGrid data to Excel files
    By fadraga in forum C++ Programming
    Replies: 3
    Last Post: 10-12-2004, 12:38 PM
  5. Borland Builder & Office
    By gustavosserra in forum C++ Programming
    Replies: 4
    Last Post: 05-29-2004, 10:38 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21