Free Support Forum - aspose.com

Saving to TabDelimited CSV causes Unicode issues in .NET

I'm losing Unicode information in the content when saving the workbook using the following code:

MemoryStream stream = new MemoryStream();

Workbook.Save(stream, SaveFormat.TabDelimited);

byte[] byteArray = stream.ToArray();

stream.Flush();

stream.Close();

Encoding encoding = Encoding.Unicode;

string s = encoding.GetString(byteArray);

Could you confirm that the Save method of WorkBook that writes to the MemoryStream does preserve unicode. Alternatively, is there another mechanism to extract the unicode text from the content.

Thanks.

Hi,

Yes, it does preserve unicode text.

I have tested it a bit with the following code:

Workbook workbook = new Workbook();
workbook.Worksheets[0].Cells[“A1”].PutValue(“HelloWorld!”);
MemoryStream stream = new MemoryStream();
workbook.Save(stream, ‘;’, System.Text.Encoding.Unicode);

byte[] byteArray = stream.ToArray();
stream.Flush();
stream.Close();
Encoding encoding = Encoding.Unicode;
string s = encoding.GetString(byteArray);

MessageBox.Show(s);



And, please try our latest version v5.1.3.x.

Thank you.

Hi,

If you are using the latest version v5.1.3, you may use the following code:

Workbook workbook = new Workbook();
workbook.Worksheets[0].Cells[“A1”].PutValue(“HelloWorld!”);
MemoryStream stream = new MemoryStream();
workbook.Settings.Encoding = Encoding.Unicode;

workbook.Save(stream, SaveFormat.CSV);


Thank you.