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 = newWorkbook(@“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 = newWorkbook(@“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)”
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.
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”);
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 .