06-19-2009 11:33 AM
Hi
I'm trying to open an existing excell file but the function Excel_WorkbooksOpen() returns error.
The code is as below :
err=Excel_NewApp(NULL,1,LOCALE_NEUTRAL,0,&applicationHandle);
err=Excel_GetProperty(applicationHandle, NULL, Excel_AppWorkbooks,
CAVT_OBJHANDLE,&workbooksHandle);
err=Excel_WorkbooksOpen(workbooksHandle,NULL,"MyFile.xls",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, &workbookHandle);
A second question is :
How can I deterime how many rows the excell sheet has ?
Regards Per
06-19-2009 01:42 PM
It looks like you are playing with the example givin by NI? \CVI\samples\activex\excel\excel2000dem.cws ? What do you mean by returns an error? Does it not compile? or does it compile but crash and return an error when you run it? Are you sure that the file you are trying to open exists and you are pointing to the proper location that the file is kept in? If it is in your main project folder and you are running the program in debug mode than the program will be running in a different folder than the xls is kept in. With a little more detail I'm sure we can get it working for ya.
Cheers
06-19-2009 01:58 PM
06-20-2009 05:06 AM
You are right, I'v copied lines from the excell2000 example into my app. The xls file is present in the same
directory as the source code.
My app compiles and do not crash, but the function Excel_WorkbooksOpen() returns the error code -2147352567
and the variable "workbookHandle" remains 0.
I do run the app in the debuger.
excelreport.fp is included in the project.
Regards Per
07-14-2009 01:44 PM
Hi! Per,
You need to add two backslashes to your file name like this "\\MyFile.xls"
07-15-2009 02:19 AM
If I'm not wrong you must pass a complete filename to Excel_WorkbooksOpen. Try this:
char file[MAX_PATHNAME_LEN];
GetProjectDir (file);
MakePathname (file, "MyFile.xls", file);
error = Excel_WorkbooksOpen (ExcelWorkbooksHandle, NULL, file, 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, &ExcelWorkbookHandle);
07-15-2009 07:18 AM