Free Support Forum -

Garbage returned when saving workbook to stream


I have a problem when saving a workbook to a stream in this case using, fileformattype.csv)

When converting the memory stream to bytes and writing this to file I get a single line file which can not be read by Excel or even in notepad. I am using version In my case I am doing the conversion on server sending the bytes back over webservice and then converting the bytes to file. Even if I remove the webservice as in the example bellow I get the same problem.

Here is a simple example of what I am doing.

Dim mstream As New

With mstream

workbooktemp.Save(mstream, FileFormatType.CSV)

Dim oBytes(CInt(mstream.Length)) As Byte

mstream.Read(oBytes, 0, oBytes.Length)

Dim fs As New System.IO.FileStream("c:\testcsv", IO.FileMode.CreateNew)

fs.Write(oBytes, 0, oBytes.Length)



End With


Since you are using some older version of Aspose.Cells. Could you try the latest version Aspose.Cells for .NET (Latest Version)

If you still find the problem, kindly post your template .csv file here, we will check it soon.

Thank you.

HI, I have tried the latest versions with the same result.

I am populating the worksheet from a data table.

The data table has around 35000 rows in it and 100 columns.

If I do, fileformatType.csv) it saves the file ok, but in this case I do not want to have to save the file first, before converting it into bytes to send to the client.

I have also tried doing this for 1 record of data and it appears as though the memory stream does not contain the correct encoding characters for ASCII, perhaps this is the problem.

I have mamaged to solve the problem, When I wrote the memory stream to bytes, it was getting converted somehow,

So have changed the write to file as fs.write(mstream.toarry(), 0, to mstream.length).

And it works.


Could you try the following version of the overloaded method "Save":

workbook.Save(System.IO.Stream stream, chart separator, System.Text.Encoding encoding)

and for your info, the default encoding type is unicode.

Thank you.