LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

how can I save more than one worksheet with ActiveX?

Hello,
I want to use ActiveX and Excel to analyze some data recorded in a txt file.
I'm not familiar with ActiveX, so I'm copying from NI examples (I use excelreport.fp).
 
I was able to:
- open the *.txt file with ActiveX: my data are in the first worksheet
- add a new worksheet
- add some formula in the 2nd sheet, the formula use data from 1st sheet
 
Everything work fine (I see the result on the Excel sheet), but I'm not able to correctly save and close (programmatically)  the document.
 
I want to save the document with another extension (*.xls), but when I use the ExcelRpt_WorkbookSave function, only the second worksheet is saved.
I verified the number of sheets present in the workbook
(ExcelRpt_GetWorkbookAttribute (wbHandle,ER_WB_ATTR_NUM_WORKSHEETS, &number)) and the outcome is positive (number = 2).
 
I also tried to save and rename the workbook immediately after the ExcelRpt_WorkbookOpen function, add the new worksheet with functions and save again but didn't work.
 
Can someone have an idea?
I'm using CVI8.01, Windows XP and Excel 2000
 
Thanks
0 Kudos
Message 1 of 3
(3,668 Views)

I wonder if it has to do with opening a .txt file. If I manually try to save a workbook that was opened as a .txt file, I get the message "The selected file type does not support workbooks that contain multiple sheets ...To save only the active sheet click OK... "  I would try the same code, but start by opening a simple one-worksheet .xls workbook file.

Your check of the number of worksheets leads me to think that you have the right parent-child relationship between application, workbook and worksheets. But double check that you create the instances of each object in the right order. i.e do they follow the relationship shown in the code below?.:

ExcelRpt_ApplicationNew (VTRUE, &Excelxp_handle);
ExcelRpt_WorkbookNew (Excelxp_handle, &wb_handle); 
ExcelRpt_WorksheetNew (wb_handle, 1, &ws_handle);
 

I assume that you have the version of Excel installed that matches the object model your instrument (.fp). 

More on object model versions here: http://forums.ni.com/ni/board/message?board.id=180&message.id=18825&requireLogin=False

More on object models here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_wrcore/html/wrconexcelobjectmode...

Hope this helps. Please let us know what you find.

--Ian 

Message 2 of 3
(3,642 Views)

Hello Ian,

you give me the right suggestion!

I just called the "ExcelRpt_WorkbookSave" function with a different File Format (ExRConst_Excel9795 instead of ExRConst_DefaultFileFormat) and now everythink works as I want.

Thank you for your help!

baloss

0 Kudos
Message 3 of 3
(3,618 Views)