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 Excel 97 (*.xls) onwards. We can check whether the file is supported by XlsIO using the `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 to Excel 97 using XlsIO, a “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 the 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
Take a moment to peruse the documentation where you can find basic Excel document processing options along with the features like import and export data, chart, formulas, conditional formatting, data validation, tables, pivot tables and, protect the Excel documents, and most importantly, the PDF, CSV and Image conversions with code examples.
Conclusion
I hope you enjoyed learning about How to check whether an Excel document is supported by XlsIO.
You can refer to our XIsIO’s feature tour page to learn about its other groundbreaking features. Explore our UG documentation and online demos to understand how to manipulate data in Excel documents.
If you are an existing user, you can access our latest components from the License and Downloads page. For new users, you can try our 30-day free trial to check out XlsIO and other Syncfusion® components.
If you have any queries or require clarification, please let us know in the comments below or contact us through our support forums, Support Tickets, or feedback portal. We are always happy to assist you!