Hi,
Thanks for your posting and using Aspose.Cells.
1. when i know the file format, how can i open the workbook from filename and file format?
Workbook constructor takes a parameter
LoadOptions, you can create LoadOptions from the
FileFormatInfo using the following code.
LoadOptions opts = new LoadOptions(finfo.getLoadFormat());
The following sample code detects the file format of file, then creates loadoptions object and finally creates workbook object.
JavaString[] filenames = { “HuongExcelAddIn97-2004_NOK.xla”, “HuongExcelMacro_NOK.xlsm”, “HuongExcelAddIn_NOK.xlam”, “Test95.xls” };
for(int i=0; i<filenames.length; i++)
{
System.out.println(filenames[i]);
FileFormatInfo finfo = FileFormatUtil.detectFileFormat(filenames[i]);
LoadOptions opts = new LoadOptions(finfo.getLoadFormat());
Workbook wb = new Workbook(filenames[i], opts);
}
2. why did aspose-cell not implement the function which can open the excel file with automatically file format detection?
Aspose.Cells is able to detect file formats via file extensions. The following code loads your files into workbook object by names and it works fine except it throws exception for Excel 95 file.
JavaString[] filenames = { “HuongExcelAddIn97-2004_NOK.xla”, “HuongExcelMacro_NOK.xlsm”, “HuongExcelAddIn_NOK.xlam”, “Test95.xls” };
for(int i=0; i<filenames.length; i++)
{
System.out.println(filenames[i]);
Workbook wb = new Workbook(filenames[i]);
}