Articles in this section
Category / Section

Why XlsIO throws "cannot recognize current file type" exception?

4 mins read

This article explains why WinForms XlsIO throws “cannot recognize current file type” exception in C#/VB.NET

When the Excel file is created using older version of MS Excel (i.e, below Excel97), the “cannot recognize current file type exception” is thrown. The API IApplication.IsSupported(string filePath) or IApplication.IsSupported(Stream Stream) helps to check whether the file is supported in XlsIO. To work with unsupported files, we recommend copying the template document into a local machine where MS Excel is installed then resave Excel documents.

 

To know more about avoiding other errors in XlsIO, please refer the documentation.

Download input file

Download complete sample

The following C#/VB.NET code illustrates how to check if the file is supported in XlsIO.

using Syncfusion.XlsIO;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
 
namespace XlsIO_Sample
{
    class Program
    {
        public static void Main(string[] args)
        {
            //Instantiate the spreadsheet creation engine
            using (ExcelEngine excelEngine = new ExcelEngine())
            {
                IApplication application = excelEngine.Excel;
 
                Assembly assembly = typeof(Program).GetTypeInfo().Assembly;
                Stream fileStream = assembly.GetManifestResourceStream("XlsIO_Sample.Data.xls");
 
                if (application.IsSupported(fileStream))
                {
                   //Open the existing workbook
                    IWorkbook workbook = application.Workbooks.Open(fileStream);
                    IWorksheet worksheet = workbook.Worksheets[0];
 
                    //Save and close the workbook
                    Stream stream = File.Create("Output.xlsx");
                    worksheet.UsedRange.AutofitColumns();
                    workbook.SaveAs(stream);
                }
            }
        }
    }
}
 

 

Imports Syncfusion.XlsIO
Imports System.Collections.Generic
Imports System.IO
Imports System.Reflection
 
Namespace XlsIO_Sample
 
    Class Program
        Public Shared Sub Main(ByVal args As String())
            'Instantiate the spreadsheet engine
            Using excelEngine As ExcelEngine = New ExcelEngine()
 
                Dim application As IApplication = excelEngine.Excel
                Dim assembly As Assembly = GetType(Program).GetTypeInfo().Assembly
                Dim fileStream As Stream = assembly.GetManifestResourceStream("XlsIO_Sample.Data.xls")
 
                If application.IsSupported(fileStream) Then
                    'Open the existing workbook
                    Dim workbook As IWorkbook = application.Workbooks.Open(fileStream)
                    Dim worksheet As IWorksheet = workbook.Worksheets(0)
 
                    'Save and close the workbook
                    Dim stream As Stream = File.Create("Output.xlsx")
                    worksheet.UsedRange.AutofitColumns()
                    workbook.SaveAs(stream)
                End If
 
            End Using
        End Sub
    End Class
End Namespace
 

 

Note:

This method is available only from 12.4 version

 

Conclusion

I hope you enjoyed learning about why XlsIO throws "cannot recognize current file type" exception.

You can refer to our WinForms XIsIO’s feature tour page to know about its other groundbreaking feature representations. You can also explore our WinForms XIsIO documentation to understand how to present and manipulate data.

For current customers, you can check out our WinForms components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our WinForms XIsIO and other WinForms components.

If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied