문제

I have the following lines of code:

Dim ms As New MemoryStream(my_memory_stream)
workbook As New Workbook(ms)
workbook.Save("C:\book1.xlsx")

My purpose is to save the stream contained in my_memory_stream into an xlsx file named "book1": the problem is that when I run this code an exception occurr (Invalid Excel2007Xlsx file format). Does anyone know what I'm doing wrong?

Thanks so much!

도움이 되었습니까?

해결책

Most probably, the problem is the base64 format. It is in the form of ASCII characters. You need to convert the Base64 data to binary. And then load the binary data in Workbook class.

' Decode base64
Dim binaryBytes As Byte() = Convert.FromBase64CharArray(base64Data, 0, base64Data.Length)

' Load in MemoryStream
Dim binaryStream As New MemoryStream(binaryBytes)

' Pass memory stream to Workbook
Dim workbook As New Aspose.Cells.Workbook(my_memory_stream)
workbook.Save(dataDir + "workbook-out.xlsx")

Also note that, if your decoding is correct, you can directly save the binary byte or stream to disk and verify that the Excel is saved correctly.

PS. I am a Developer Evangelist at Aspose.

다른 팁

It seems that you are trying to save a stream directly to a Excel file. Excel files have a fixed format, and the stream will not be adhering to the standard file protocol of excel.

I think you would like to use Workbook object of Microsoft.office.Interop.Excel namespace.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top