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;