Wrong sheet name (XLS/XML file)

Hello,

We regularly receive XLS files from our customers which are XML. This file contains the addition “XMLDATA” in the first line.

Excel can handle it and only notices that not all Feautures are usable.

In version 19.1.0 (.NET) we could not read the file because Cells threw an InvalidOperationException.

In version 19.5.0 (.NET) the file goes suddenly. Everything is correct except that the sheet name is not read correctly. Cells says that the sheet name is equal to the file name.

Please look at the sample file:
XMLDataSheet.zip (544 Bytes)

@mservdev,
I have analyzed your file which is actually XML as mentioned by you. In your scenario as you cannot rely on the file extension and if load it into Workbook as it is, it behaves unexpectedly like it parses wrong file name from the available data. To avoid loading such file you may please use FileFormatUtil.DetectFileFormat to check i if this file contains proper format or not. If it does not return proper format, you may not load it into Workbook object.

Workbook wb = new Workbook(path + "XMLDataSheet.xls");
Aspose.Cells.FileFormatInfo fmtType = Aspose.Cells.FileFormatUtil.DetectFileFormat(path + "XMLDataSheet.xls");
Console.WriteLine(fmtType.FileFormatType);

If you run this code, you will observe that it returns Unknown, hence this file shall not be loaded into Workbook object.

Okay, thanks, that’ll help us.

@mservdev,
You are welcome.

I have another question about that.

Shouldn’t Workbook.FileFormat (Workbook.FileFormat | Aspose.Cells for .NET API Reference) also output “Unkown” like
Aspose.Cells.FileFormatUtil.DetectFileFormat(path + “XMLDataSheet.xls”);?

Because in my example (see above) FileFormat is CSV and DetectFileFormat return Unkown.:thinking:

@mservdev,
Actually, this function works by checking some specific header or identifier etc. in a file to decide the file format. As CSV does not contain any such identification and can be created without following any hard and fast rules, therefore it is not possible to declare a CSV file to be an Excel file always. That is why it returns Unknown.

Hope it clarifies the query.