10-21-2005 04:59 AM
10-21-2005 08:21 AM
Rainer, here are some lines of code that should get you started, but since I just snipped them out, you may need to clean some details get it working:
#define ERR_BUF_SIZE 1000
#include "ExcelReport.h"
#include "excel2000.h"
void Exc_ErrRep(int err);
char cell[13];
char col='A';
int row=1;
CAObjHandle Excelxp_handle = 0;
CAObjHandle ws_handle = 0;
CAObjHandle wb_handle = 0;
// Open Excel & create wb and ws
Exc_ErrRep ( ExcelRpt_ApplicationNew (VTRUE, &Excelxp_handle) ) Exc_ErrRep ( ExcelRpt_WorkbookNew (Excelxp_handle, &wb_handle) );
Exc_ErrRep ( ExcelRpt_WorksheetNew (wb_handle, 1, &ws_handle) );
Exc_ErrRep ( ExcelRpt_SetWorksheetAttribute (ws_handle, ER_WS_ATTR_NAME, "MyNewSheet") ) ;
//Put in some data in cell A1
Fmt(cell, "%s<%c%d", col, row);
Exc_ErrRep ( ExcelRpt_SetCellValue (ws_handle, cell , ExRConst_dataDouble, (double)123.456 ) ) ;
col++;
row++;
Fmt(cell, "%s<%c%d", col, row);
Exc_ErrRep ( ExcelRpt_SetCellValue (ws_handle, cell , ExRConst_dataDouble, (double)789.012 ) ) ;
//Clean Up and Quit (important!)
Exc_ErrRep (CA_DiscardObjHandle (ws_handle) );
Exc_ErrRep (CA_DiscardObjHandle (wb_handle) );
Exc_ErrRep (CA_DiscardObjHandle (Excelxp_handle) );
void Exc_ErrRep(int err)
{
char errstring[ERR_BUF_SIZE];
if (err < 0) {
CA_GetAutomationErrorString (err, errstring, ERR_BUF_SIZE);
MessagePopup("ActiveX Error with Excel", errstring);
}
return;
}
Hope this help.
--Ian
10-21-2005 08:46 AM
Ian,
thanks for your answer. Meanwhile I could manage to add a workbook.
But, I'm really fighting with putting this new sheet to the end of the existing sheets. Using the "Excel_SheetsMove / Excel_WorksheetMove" I can't put it to the end. If you have any idea I would appreciate that :-))
Rainer.
10-21-2005 09:38 AM
Hi,
I agree with you that it is quite difficult to link excel and CVI. I had the same problem here.
You can use
error = Excel_GetProperty (ExcelAppHandle, NULL, Excel_AppSheets,
CAVT_OBJHANDLE, &ExcelSheetsHandle);
if (error<0)
goto Error;
error = Excel_SheetsAdd (ExcelSheetsHandle, NULL, CA_DEFAULT_VAL,
CA_DEFAULT_VAL, CA_DEFAULT_VAL, CA_DEFAULT_VAL,
&ExcelWorksheetHandle);
if (error<0)
goto Error;
Hope this will solve your problem.
Bye
Ashwin
10-24-2005 01:36 AM
@ashwincm:
It works, thanks.
But again, do you know a way to put a new sheet to the end of the active one by using the Move commands (simply appending)???
Rainer.
10-24-2005 06:24 AM