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. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Error while opening .xls file

Thread ID:

Created:

Updated:

Platform:

Replies:

73544 May 9,2008 12:51 PM UTC May 22,2008 11:51 AM UTC WinForms 3
loading
Tags: XlsIO
Ramana
Asked On May 9, 2008 12:51 PM UTC

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.


Bhuvaneswari P [Syncfusion]
Replied On 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



Ramana
Replied On 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

Bhuvaneswari P [Syncfusion]
Replied On 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



CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;