Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Thu Apr 02, 2020 9:18 pm

Hello

I've been looking around the web for a solution that can convert a byte array into an Excel file, since my application already creates a PDF version. I've been looking into Spire.XLS and haven't found a way to do it, although this library has an InsertArray function that seems to accept it (one overload accepts an object array). Is is possible?

ftquadros
 
Posts: 2
Joined: Thu Apr 02, 2020 9:10 pm

Fri Apr 03, 2020 2:17 am

Hi,

Thanks for your inquiry.
Kindly note the InsertArray function is designed to insert an array of data into a range in Excel Worksheet. For your situation, if your byte array data is an Excel file, you could use the following method to convert the byte array to workbook.
Code: Select all
//Your byte array
byte[] bytes = File.ReadAllBytes("test.xlsx");
//Load from byte array
Workbook workbook = new Workbook();
workbook.LoadFromStream(new MemoryStream(bytes));
//Save to Excel file
workbook.SaveToFile("result.xlsx", ExcelVersion.Version2013);
If you just want to insert some data in the form of byte array in a worksheet, please refer to the following sample code. If there is any question, please freel free to write back.
Code: Select all
//Create a workbook
Workbook workbook = new Workbook();
//Get the first worksheet
Worksheet sheet = workbook.Worksheets[0];
//Byte array
byte[] myByteArray = new byte[] { 0x01, 0x02, 0x03 };
//Insert the data in worksheet
sheet.InsertArray<byte>(myByteArray, 1, 1, true);
//Save to Excel file
workbook.SaveToFile("result.xlsx", ExcelVersion.Version2013);
Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1187
Joined: Tue Sep 27, 2016 1:06 am

Fri Apr 03, 2020 11:08 am

Thank you, Nina. My case resembles most your second example, so I'll try it out.

Cheers

ftquadros
 
Posts: 2
Joined: Thu Apr 02, 2020 9:10 pm

Mon Apr 06, 2020 1:27 am

Hi,

Did your try the second example, did it meet your need well?
Thanks in advance for your valuable feedback and time.

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1187
Joined: Tue Sep 27, 2016 1:06 am

Return to Spire.XLS

cron