.Net how to check .xlsx file encoding?

Hi,


I’m trying to get the encoding of an input .xlsx file using the following:

LoadOptions loadOptions = new LoadOptions(LoadFormat.Xlsx);
var inputWorkbook = ReportFactory.CreateSpreadsheetFromStream(UsersData, loadOptions);
var fileEncoding = inputWorkbook.Settings.Encoding;

However this always returns the Windows-1252 encoding. The example file attached has the encoding ‘Turkish (ISO)’.

I noticed that workbook.settings.encoding tips states “only applies for CSV”. Is there a different method for getting the file encoding that will work for all file formats?

Thanks

Hi Paul,


Thank you for contacting Aspose support.

Please note, the latest revisions of Aspose.Cells APIs have removed the Encoding property from the WorkbookSettings class and moved it to TxtLoadOptions & TxtSaveOptions classes. Reason being, the encoding is applicable for CSV (TXT) files only and has nothing to do with spreadsheet formats such as XLSX.

I am not sure why you need to get/set the encoding for XLSX file format. If you can explain the requirement, we may be able to provide an alternative solution or workaround for your needs.

Hi,


Thanks for your response.

The reason we want to check the xlsx encoding, is we only support windows-1252 characters. So we want to test that the xlsx encoding is Windows-1252 and reject any files that are not in this format.

Regards,
Paul

Hi Paul,


As per discussion with the concerned member of the product team, the Aspose.Cells APIs are not capable of detecting the encoding of XLSX file format nor we have plans to provide such support in near future. That said, I searched for alternative solutions using core .NET APIs but I am not able to refer you to any because such solutions are not 100% reliable.

We are sorry for the inconvenience.