More LoadFormats (453)

Hi,

In LoadFormat API reference I see there is one common format (XLSX) for multiple excel formats like Open XML spreadsheetML workbook or template, with or without macros.
I’d like to request (or join to an already existing request) to have different LoadFormats for following formats:

  • Open XML spreadsheetML workbook
  • Open XML macro-enabled spreadsheetML
  • Open XML spreadsheetML template
  • Open XML macro-enabled spreadsheetML template
  • Excel template (binary)

Please share with me your thoughts on this request. If there is a plan to have this in a specific version of aspose cells already, please let me know.

Regards, Zeljko

@Zeljko

Thanks for using Aspose APIs.

Please provide us your sample documents and sample code. We will look into this issue at our end after executing your code and log it in our database so that this feature could be improved in future releases.

Hi,

here is the sample code and sample-files.zip (29.6 KB).

    @Test
    public void test() throws Exception {
	int loadFormat = com.aspose.cells.FileFormatUtil.detectFileFormat("Book5.xlsx").getLoadFormat();
	assertTrue(loadFormat == com.aspose.cells.LoadFormat.XLSX);

	loadFormat = com.aspose.cells.FileFormatUtil.detectFileFormat("Book4.xlt").getLoadFormat();
	assertFalse(loadFormat == com.aspose.cells.LoadFormat.EXCEL_97_TO_2003);
//	assertTrue(loadFormat == com.aspose.cells.LoadFormat.XLT);

	loadFormat = com.aspose.cells.FileFormatUtil.detectFileFormat("Book3.xltm").getLoadFormat();
	assertFalse(loadFormat == com.aspose.cells.LoadFormat.XLSX);
//	assertTrue(loadFormat == com.aspose.cells.LoadFormat.XLTM);

	loadFormat = com.aspose.cells.FileFormatUtil.detectFileFormat("Book2.xltx").getLoadFormat();
	assertFalse(loadFormat == com.aspose.cells.LoadFormat.XLSX);
//	assertTrue(loadFormat == com.aspose.cells.LoadFormat.XLTX);

	loadFormat = com.aspose.cells.FileFormatUtil.detectFileFormat("Book1.xlsm").getLoadFormat();
	assertFalse(loadFormat == com.aspose.cells.LoadFormat.XLSX);
//	assertTrue(loadFormat == com.aspose.cells.LoadFormat.XLSM);
    }

Best, Zeljko

@Zeljko,

Thanks for the sample code and template files.

We will evaluate your issue using your template files and get back to you soon.

@Zeljko

Thanks for considering Aspose APIs.

We could not find record that specifies whether the workbook is a template in the file, so we only can detect the type as xls.

Please open and save as the file in your MS Excel and check the default save type.


Please try the following code and it should help you recognize the type truly. The code uses the FileFormatInfo.getFileFormatType() method.

Java

FileFormatInfo o = FileFormatUtil.detectFileFormat(yourFile);

System.out.println("LF: " + o.getLoadFormat());
System.out.println("FMT: " + o.getFileFormatType());

Thanks, suggested alternative method works fine.

Zeljko