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.zipIn 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