Convert XLS to byte array via C#
Native and high performance Microsoft Excel XLS to byte array conversion or vice versa for spreadsheets data processing using server side .NET APIs.
Byte Array is helpful for data processing or storing. You can convert XLS file to Byte Array as well as a Byte Array to XLS document using C# language. In order to convert XLS to byte array, we’ll use
API that offers different features for document manipulation and conversion using .NET platform.
How to Convert XLS to Byte Array via C#
It is easy for the developers to load & convert XLS files to byte array for further manipulation tasks in just a few lines of code.
- Include the namespace in your class file
- Load input XLS File using Workbook
- Initialize MemoryStream object
- Convert stream data to byte array
- Process data as of your requirement
System Requirements
Just make sure that system have Microsoft Windows or a compatible OS with .NET Framework, .NET Core, Windows Azure, Mono or Xamarin Platforms as well as development environment like Microsoft Visual Studio.
- Install from command line as
nuget install Aspose.Cells
or via Package Manager Console of Visual Studio withInstall-Package Aspose.Cells
. - Alternatively, get the offline MSI installer or all DLLs in a ZIP file from downloads
This sample code shows XLS to byte array C# Conversion
Workbook workbook = new Workbook("sourceFile.xls");
//Save the workbook in memory stream
MemoryStream ms = new MemoryStream();
workbook.Save(ms, SaveFormat.Xls);
//Read bytes from memory stream
byte[] byte_array = new byte[ms.Length];
ms.Read(byte_array, 0, byte_array.Length);
// Process the memory stream byte array data as of your requirement
XLS What is XLS File Format?
Files with XLS extension represent Excel Binary File Format. Such files can be created by Microsoft Excel as well as other similar spreadsheet programs such as OpenOffice Calc or Apple Numbers. File saved by Excel is known as Workbook where each workbook can have one or more worksheets. Data is stored and displayed to users in table format in worksheet and can span numeric values, text data, formulas, external data connections, images, and charts. Applications like Microsoft Excel lets you export workbook data to several different formats including PDF, CSV, XLSX, TXT, HTML, XPS, and several others. The XLS file format was replaced with a more open and structured format, XLSX, with the release of Microsoft Excel 2007. The latest versions still provide support for creating and reading XLS files, though XLSX is the first choice of use now.
Read MoreOther Supported Conversions
You can also convert other file formats into byte array or vice versa including few listed below.