We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Error while opening .xls file

Hi,

While opening '.xls' file,I'm getting an error:"Cannot recognize current file type".
The code which I'm using is;
ExcelEngine excelEngine1 = new ExcelEngine();
IApplication applicationExcel1;
applicationExcel1 = excelEngine1.Excel;
IWorkbook workbook1;
if (Path.GetExtension(FileName) == ".xls")
workbook1 = applicationExcel1.Workbooks.Open(f1);

Can any one tell me a solution.

Regards,
Ramana.


3 Replies

BP Bhuvaneswari P Syncfusion Team May 14, 2008 05:07 PM UTC

Hi Ramana,

Thank you for your interest in Syncfusion products.

Your code:

if (Path.GetExtension(FileName) == ".xls")
workbook1 = applicationExcel1.Workbooks.Open(f1);

In your code you are checking the file extension using the FileName, but while opening the workbook you are passing f1. Make sure that f1 contains the xls file. Normally this error occurs if we open the unknown file not xls file. Please try with the below code:


OpenFileDialog op = new OpenFileDialog();
ExcelEngine excelEngine1 = new ExcelEngine();
IApplication applicationExcel1;
applicationExcel1 = excelEngine1.Excel;
IWorkbook workbook1;

if (op.ShowDialog() == DialogResult.OK)
{
if (Path.GetExtension(op.FileName) == ".xls")
{


workbook1 = applicationExcel1.Workbooks.Open(op.FileName);
workbook1.SaveAs("sample.xls");
System.Diagnostics.Process.Start("sample.xls");

//No exception will be thrown if there are unsaved workbooks.
excelEngine1.ThrowNotSavedOnDestroy = false;
excelEngine1.Dispose();
}




Herewith I have attached the working sample:
http://www.syncfusion.com/development/uploads/XlsFileOpen_cd6bf1b.zip

In the sample click the button to browse the xls file to open the file through xls. If still you are getting the same error, please provide the xls file you are trying to open, so that we can reproduce and analysis more on this issue.

Best Regards,
Bhuvana




RA Ramana May 20, 2008 04:24 AM UTC

Hi,

In my code f1 contains the file extension also,but Still I'm getting the same error ,I'm sending the xls file which I'm trying to open.

Thanks & Regards,
Ramana.



excelAddresslist1.zip


BP Bhuvaneswari P Syncfusion Team May 22, 2008 11:51 AM UTC


Hi Ramana,

Thanks for the file.

I am afraid that I am not able to reproduce the issue. I am able to open the file without any issues.

I have tested this sample in the following environment:
Windows XP with Service pack2, Excel 2003, VisualStudio 2005, .Net Framework 2.0 and Essential Studio version 6.2.0.40.

Here is the tested sample:

http://www.syncfusion.com/development/uploads/OpenXlsFile_109baf0f.zip


Try this sample, if still reproduce the issue could you pleas provide the below details to reproduce the issue in our end.

1. System details
2. Office version

This will helps us to reproduce the issue in our end and provide you an solution.

Best Regards,
Bhuvana



Loader.
Live Chat Icon For mobile
Up arrow icon