How to check whether an Excel document is supported by XlsIO?
This article explains how to check whether an Excel document is supported by XlsIO.
XlsIO supports Excel files generated from Excel97 (*.xls) onwards. We can check whether the file is supported by XlsIO using IsSupported() method in IApplication. This method accepts either a file path or a stream object of an Excel document and returns true if the file is supported by XlsIO, otherwise false.
Sample code to check whether the Excel file is supported
//Check whether the file is supported by XlsIO if (application.IsSupported(fileStream))
When we try to open an Excel document generated prior Excel97 using XlsIO then “File does not contain workbook stream” exception occurs.
To know more about this, please refer the documentation
The following C#/VB complete code snippet explains how to check whether an Excel document is supported by XlsIO.
C#
using Syncfusion.XlsIO; using System; using System.IO; using System.Reflection; namespace SupportedFormat { class Program { static void Main(string[] args) { using (ExcelEngine excelEngine = new ExcelEngine()) { //Instantiate the excel application object. IApplication application = excelEngine.Excel; //The workbook is opened. IWorkbook workbook; //Open existing workbook with data entered Assembly assembly = typeof(Program).GetTypeInfo().Assembly; Stream fileStream = assembly.GetManifestResourceStream("SupportedFormat.Test.xls"); //Check whether the file is supported by XlsIO if (application.IsSupported(fileStream)) { workbook = application.Workbooks.Open(fileStream, ExcelOpenType.Automatic); //Saving and closing the workbook Stream stream = File.Create("Output.xlsx"); workbook.SaveAs(stream); } else { Console.WriteLine("File is not supported by XlsIO"); Console.Read(); } } } } }
VB
Imports Syncfusion.XlsIO Imports System Imports System.IO Imports System.Reflection Namespace SupportedFormat Class Program Private Shared Sub Main(ByVal args() As String) Dim excelEngine As ExcelEngine = New ExcelEngine 'Instantiate the excel application object. Dim application As IApplication = excelEngine.Excel 'The workbook is opened. Dim workbook As IWorkbook 'Open existing workbook with data entered Dim assembly As Assembly = GetType(Program).GetTypeInfo.Assembly Dim fileStream As Stream = assembly.GetManifestResourceStream("SupportedFormat.Sample.xls") 'Check whether the file is supported by XlsIO If application.IsSupported(fileStream) Then workbook = application.Workbooks.Open(fileStream, ExcelOpenType.Automatic) 'Saving and closing the workbook Dim stream As Stream = File.Create("Output.xlsx") workbook.SaveAs(stream) Else Console.WriteLine("File is not supported by XlsIO") Console.Read() End If End Sub End Class End Namespace