LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

problems with saving excel

Hi,
There are few questions about ExcelReport.fp
1. I am trying to save current workbook with by ExcelRpt_WorkbookSave with  ExRConst_DefaultFileFormat flag, and i recieve windows exception. Why?
When I use ExRConst_TextWindows flag - saving done successfuly. I just need to save my workbook
as is in xls file. Wich parameter need to be used?
2. When I save my workbook, only active worksheet saved. How can i save whole workbook?
 
Thanks
0 Kudos
Message 1 of 5
(3,928 Views)

I try to clarify: there is a code example:

            //create excel

            GetObjHandleFromActiveXCtrl( PanelHandle,ExcelId, &workbookHandle);

            GUI_p_ExcelChangeExcelWorksheet(1);

            //add values from the table

            ExcelRpt_WriteDataFromTableControl(worksheetHandle, "B2:E6",

                                                                                                PanelHandle, TableId);

            //save excel in file

        ExcelRpt_WorkbookSave( workbookHandle,"file",ExRConst_DefaultFileFormat);

 

Program create excel file, but when I open it I can’t see anything. Additionally, when I open it in notepad I can see the data. I guess that problem is in the file format constant.

 

Some body can help me pls

 

Thank you


 

0 Kudos
Message 2 of 5
(3,931 Views)
Try to use  Create ActiveX Controller Wizzard Then :
 
// Active X Excel Variable
char      excelFileName[260];
int                  appVisible = 1;
VARIANT MyVariant;
VARIANT MyCellRangeV;
 
      sprintf (excelFileName, "C:\\Report\\%s.xls",Excel file name); 
      Excel_NewApp (NULL,&ExcelAppHandle);    
     // Make Excel visible
      Excel_SetProperty (ExcelAppHandle, NULL, Excel_AppVisible, CAVT_BOOL,VTRUE);

     Excel_GetProperty (ExcelAppHandle, NULL, Excel_AppWorkbooks, CAVT_OBJHANDLE,&ExcelWorkbooksHandle);
     Excel_WorkbooksOpen (ExcelWorkbooksHandle, NULL, excelFileName,
                                            CA_DEFAULT_VAL, CA_DEFAULT_VAL, CA_DEFAULT_VAL,
                                            CA_DEFAULT_VAL, CA_DEFAULT_VAL, CA_DEFAULT_VAL,
                                           CA_DEFAULT_VAL, CA_DEFAULT_VAL, CA_DEFAULT_VAL,
                                           CA_DEFAULT_VAL, CA_DEFAULT_VAL, CA_DEFAULT_VAL,
                                           &ExcelWorksheetHandle); 
       Excel_GetProperty (ExcelAppHandle, NULL, Excel_AppSheets, CAVT_OBJHANDLE, &ExcelSheetsHandle);
       Excel_SheetsItem (ExcelSheetsHandle, NULL, CA_VariantInt(1), &ExcelWorksheetHandle);
 
Put your statement here  .. .. . . . . . . . . . . . . . .
     
       Excel_WorksheetSaveAs (ExcelWorksheetHandle, NULL, excelFileName, CA_DEFAULT_VAL, CA_DEFAULT_VAL,
                                                  CA_DEFAULT_VAL, CA_DEFAULT_VAL, CA_DEFAULT_VAL,
                                                  CA_DEFAULT_VAL, CA_DEFAULT_VAL, CA_DEFAULT_VAL);
        Excel_SetProperty (ExcelAppHandle, NULL, Excel_AppDisplayAlerts,CAVT_BOOL, VFALSE);
       CA_VariantSetCString (&MyVariant, excelFileName);
       Excel_WorkbookClose (ExcelWorkbooksHandle, NULL, CA_DEFAULT_VAL, MyVariant, CA_DEFAULT_VAL);  
      //Discard unwanted handle
}
 
0 Kudos
Message 3 of 5
(3,897 Views)

Thank you, it works excellent. I saw it in cvi examples, before. I need to use excel document from cvi panel and not as separate document, and I need to save this document after using. So i can do it by duplicating data (once in cvi panel excel and one else in new excel application) but it looks urgly.

is it impossible to save excel, created from uir component?? Dose it mean, that cvi activex control driver has serious bug/problem??

 

0 Kudos
Message 4 of 5
(3,869 Views)

Yes you can. Create Excel Template. Save all data from UIR to temp file. Using Excell macro or VBA to open temp file then insert those data into your Excel Template then tell VBA program save as Excel file name.

Let me know if it work

0 Kudos
Message 5 of 5
(3,863 Views)