We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Open File Error: This file's format is not supported or you don't specify a correct format

Hi,

I am getting this error very often when try to open an excel file:

This file's format is not supported or you don't specify a correct format.

My code:

System.IO.FileStream fstream = null;

Workbook workbook = new Workbook();

fstream = new System.IO.FileStream(docFile, FileMode.Open);

workbook.Open(fstream, fileFormat);

I have tried to use fileFormat = Excel97, XP, 2000, 2003, none of them work. However, I can open it with Excel 2003

I have attached one excel file for you to take a look.

Thanks

Chang

Please try FileFormatType.TabDelimited option.

yes, it works. Why I can't open it with any other formats?

Or my question is how do I know to use which right format to open the files?

Hi,

Well, the file is basically a text file, if you could open the file into notepad, you may see it's a text file. For text files, you may use FileFormatType.TabDelimited format type.

For other formats, you should choose a valid FileFormatType, e.g..,

xls/xlt -> Excel97/Excel2000/ExcelXP/Excel2003/Default etc.

csv -> CSV

xlsx -> Excel2007Xlsx

txt(tab delimited) -> TabDelimited

.xml (Spreadml) -> SpreadsheetML

For your further reference, kindly check the following doc links:

http://www.aspose.com/documentation/file-format-components/aspose.cells-for-.net-and-java/opening-files.html

http://www.aspose.com/documentation/file-format-components/aspose.cells-for-.net-and-java/saving-files.html

Thank you.

hi,

thanks for info. I am doing a batch process, all the files are saved as xls, I can not tell the format when openning. If I open them with excel, I don't need to specify exactly format to use, I think aspose.cells should be able to handle it the same way?

Hi,

I think you may use your own code to manually check the file's extension of the file with ease which you are opening using Workbook.Open() method.

e.g..,

.
.
.
string path = myFilePath;
string ext = path.Substring(path.LastIndexOf(".")+1, path.Length);

switch(ext)
{

case ".xls":
workbook.Open(myfilePath,FileFormatType.Default);
break;

case ".xlsx":
workbook.Open(myfilePath,FileFormatType.Excel2007Xlsx);
break;

case ".xml":
workbook.Open(myfilePath,FileFormatType.SpreadsheetML);
break;

case ".txt":
workbook.Open(myfilePath,FileFormatType.TabDelimited);
break;

case ".csv":
workbook.Open(myfilePath,FileFormatType.CSV);
break;


}
Thank you.

hi,

Aggree..if I can tell from file extension. The problem is we got files from clients, all of which have extension of 'xls' -- and there is not such a problem to open these files with excel interop, without knowing what internal file format is.

Hi,

Well, I 'm afraid we do not have any good solution for it, we can only know whether it is a txt file or other file from its content. We cannot simply get which separator the file uses.

Thank you.