[英]Compatibility mode in excel file when created by Apache POI
I am using POI to create excel file (using HSSFWorkbook) and save with xls file. 我正在使用POI创建excel文件(使用HSSFWorkbook)并保存为xls文件。 But when i used higher office (2007+), i got a warning in title bar : Filename.xls [Compatibility Mode]. 但是,当我使用高级办公室(2007+)时,标题栏中出现了警告:Filename.xls [兼容模式]。
Workbook wb = new HSSFWorkbook();
Sheet sheet = wb.createSheet("new sheet");
Row row = sheet.createRow((short) 0);
Cell cell = row.createCell(0);
cell.setCellValue(1);
FileOutputStream fileOut = new FileOutputStream("D:/testExcel/workbook.xls");
wb.write(fileOut);
fileOut.close();
How can i configure in in POI to not open file in this mode? 如何在POI中配置为在此模式下不打开文件?
Try, 尝试,
Workbook wb = WorkbookFactory.create(myExcelFile);
if (wb instanceof HSSFWorkbook) {
// do whatever
} else if (wb instanceof SXSSFWorkbook) {
// do whatever
} else if (wb instanceof XSSFWorkbook) {
// do whatever
}
Your myExcelFile
can be an InputStream
, File
, etc. Check reference. 您的myExcelFile
可以是InputStream
, File
等。请检查引用。
This will allow you to handle .xls and .xlsx extention files. 这将允许您处理.xls和.xlsx扩展文件。 Perhaps your issue can also be handled. 也许您的问题也可以得到解决。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.