We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Settings.Encoding always returns default encoding

Hi,

I’m trying to get the encoding of an CSV or Excel document.
But if run the following code the settings.encoding property always returns the default encoding type.
Workbook wb = new Workbook(@“C:\Users\user\Desktop\Book2.CSV”);	//Loading the Woorkbook
MessageBox.Show(wb.Settings.Encoding.EncodingName); //Says “Western European (Windows)” like expected
wb.Settings.Encoding = Encoding.BigEndianUnicode; //Changing the encoding to BigEndianUnicode
wb.Save(@“C:\Users\user\Desktop\Book2-BEUnicode.CSV”, FileFormatType.CSV); //Save the File //Edit: The new CSV File has the Big Endian encoding now (Tested with notepad++)
Workbook wb2 = new Workbook(@“C:\Users\user\Desktop\Book2-BEUnicode.CSV”); //Loading the Woorkbook again
MessageBox.Show(wb2.Settings.Encoding.EncodingName);//Still returns “Western European (Windows)”. Expected: “Unicode (Big-Endian)”
Best regards. Manuel

Hi,


Could you attach your template “Book2.csv” file here, we will check your issue soon.

Thank you.

Book2.CSV is the original, Book2-BEUnicode.CSV the one with the changed encoding.

Hi Manuel,


Thank you for providing the sample files.

We are able to observe the same issue as mentioned in your original post while using your sample CSV and the latest version of Aspose.Cells for .NET 8.0.0.3. In order to further investigate the matter, and provide a fix we have logged this issue in our bug tracking system under ticket Id CELLSNET-42560. Please spare us little time for proper analysis. In the meanwhile, we will keep you posted with updates in this regard.

We are sorry for the inconvenience caused.

Hi,


As we have logged a ticket “CELLSNET-42560” for your issue, so we will look into it to figure it out soon.

In the mean while if you need your CSV/ Excel file should be loaded with specific encoding type by Aspose.Cells APIs, you may always specify your desired encoding type using LoadOptions for your needs.
e.g
Sample code:

Workbook wb = new Workbook(@“e:\test2\Book2.CSV”);
MessageBox.Show(wb.Settings.Encoding.EncodingName);
wb.Settings.Encoding = Encoding.BigEndianUnicode;
MessageBox.Show(wb.Settings.Encoding.EncodingName);
wb.Save(@“e:\test2\outBook2-BEUnicode.CSV”, SaveFormat.CSV);

TxtLoadOptions options = new TxtLoadOptions(LoadFormat.CSV);
options.Encoding = Encoding.BigEndianUnicode;
Workbook wb2 = new Workbook(@“e:\test2\outBook2-BEUnicode.CSV”, options);
MessageBox.Show(wb2.Settings.Encoding.EncodingName);


Thank you.

Hi Manuel,


Thank you for using Aspose.Cells.

This property is used to open and save the csv file, we do not update it when open the file.
If it’s not set, Aspose.Cells just simply open the file with new StreamReader(string file) and if .NET Framework could not detect the correct encoding of the csv file, Aspose.Cells will return the wrong data too.

We have no plan to support it and we have obsoleted it .

If you want to get the encoding of the csv file, please parse it by yourself .

There is the following temporary solution:

Console.WriteLine ((new StreamReader(“C:\test.csv”)).CurrentEncoding);