LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to use Excel_WorksheetSaveAs to save as CSV

Solved!
Go to solution

I'm using LabWIndows/CVI 2010 and I'm trying to save an open Excel XLS file as a CSV but I cannot figure out how to specify the fileformat parameter. excel2000.h contains #defines for all the file formats but I cannot pass the define to Excel_WorksheetSaveAs. WHat do I need to cast the define to for it to work?

 

Thanks in advance.

0 Kudos
Message 1 of 7
(5,857 Views)

Thanks for the reply. My problem isn't opening the XLS file, it's saving it as a CSV. None of the sample code uses the SaveAs function.

0 Kudos
Message 3 of 7
(5,825 Views)

You could probably get what you want by calling Excel_WorkbookSaveAs with ExcelConst_xlCSV constant in "File Format" parameter.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 7
(5,810 Views)

I've tried casting ExcelConst_xlCSV to CA_VariantInt (you cant pass it directly, it wont compile) as the File Format and that gives me an 0x80004002 Interface Not Supported. Tried various other ExcelConst values as well and always get the same error. 

0 Kudos
Message 5 of 7
(5,732 Views)
Solution
Accepted by topic author trewm

Now, this is strange. I hadn't tested originally this option but I made it right now and it is working for me: this instruction effectively create a CSV file out of an Excel workbook I created programmatically exporting test data in an application of mine

	errChk (Excel_WorkbookSaveAs (ExcelWorkbookHandle, NULL, MyVariant,
				CA_VariantInt (ExcelConst_xlCSV), CA_DEFAULT_VAL, CA_DEFAULT_VAL,
				CA_DEFAULT_VAL, CA_DEFAULT_VAL, ExcelConst_xlNoChange, CA_DEFAULT_VAL,
				CA_DEFAULT_VAL, CA_DEFAULT_VAL, CA_DEFAULT_VAL));

(it happened to create a CSV file even if the filename had .xls extension!)

 

FYI, my environment is Win7Pro SP1 64bit, CVI 2012 FDS SP1, Office 2000 installed.

 



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 6 of 7
(5,722 Views)

I was using ExcelWorkSheetSaveAs not ExcelWorkBookSaveAs but switching to ExcelWorkBookSaveAs got rid of the error. Thanks for the help!

0 Kudos
Message 7 of 7
(5,714 Views)