Saving Excel Files as .xls with Office 2007

CIMStu

Member
Joined
Mar 9, 2010
Messages
13
Programming Experience
Beginner
Hi All

I am now on to writing my second application! lol, and am a bit stuck on this one...

I have written an application that uses a 2d array to write to an excel spreadsheet. I then use the SaveAs method of the Excel.Application namespace to Save the file, i have set the filename to end with a .xls

I have Office 2007 on my machine and therefore have used the COM reference for Excel Library 12(or something like that)

The code i have created works fine, the file gets created. However when i goto open the spreadsheet from within excel 2007 it comes up saying the file is not formatted as expected.

If i change the filename i save to .xlsx and then open within Excel, it opens fine.

I want my application to work for people if they have office 2007 or office 2003...

Is there a way i can set the file format to an office 2003 from within the code? or do i need to use a different com reference?

As explained this is only my 2nd application, so am still finding my feet big time!

Thanks
 
I use Word all the time with 2007, but I use 97-2003 documents/templates when I am using automation with the 12.0 object library. It opens, edits and saves them fine. So it must be the fact that you are starting with 2007 and then telling it to convert it.
 
Thanks for the reply

I am actually creating the document within the code, rather than opening or editing.

So in theory if i create a spreadsheet in 2003, open it within the code and edit then save i should be able to get around the problem?
 
How about making a blank .xls file from a StreamWriter then open it.
VB.NET:
Using sw As New StreamWriter("somefile.xls")
End Using
 
I will give that a go in the morning (its 9:30 at night here) so don't really feel like doing it now! lol

Thanks for the suggestions, i'll let you know how i get on!
 
SaveAs method has many optional parameters you can use, one of them is FileFormat, the value you specify here is defined in the XlFileFormat enumeration, for example the value XlFileFormat.xlExcel9795.
 
Back
Top