jxl – MS Excel兼容性错误

我正在尝试使用jxl API生成Excel报告 – 但是我一直面对MS Excel的兼容性问题。 生成的报告包含一些样式,如粗体字体,自动resize的单元格等,就像LibreOffice Calc的魅力一样。 但是,如果我试图用MS Excel打开相同的.xls文件,我面临一个像这样的警告:

截图

当我确认MS Excel提示继续恢复文件时,我能够看到没有路线和样式的工作表内容。

编辑:只是想通了; 合并细胞是这个问题的原因 。 如果我不合并单元格,一切都按预期工作。 那么如何合并使用jxl与MS Excel兼容的单元呢?

以下是生成报告的服务的代码片段:

 WritableFont boldArial11Font = new WritableFont(WritableFont.ARIAL, 11, WritableFont.BOLD); WritableFont arial11Font = new WritableFont(WritableFont.ARIAL, 11); CellView sbtSizeCellView = new CellView(); sbtSizeCellView.setSize(4000); sbtSizeCellView.setAutosize(false); CellView autoSizeCellView = new CellView(); autoSizeCellView.setAutosize(true); WritableCellFormat boldArial10Format = new WritableCellFormat(boldArial11Font); boldArial10Format.setBorder(Border.ALL, BorderLineStyle.THIN, Colour.BLACK); WritableCellFormat boldArial10CenterFormat = new WritableCellFormat(boldArial11Font); boldArial10CenterFormat.setBorder(Border.ALL, BorderLineStyle.THIN, Colour.BLACK); boldArial10CenterFormat.setAlignment(Alignment.CENTRE); WritableCellFormat arial10Format = new WritableCellFormat(arial11Font); arial10Format.setBorder(Border.ALL, BorderLineStyle.THIN, Colour.BLACK); WorkbookSettings wbSettings = new WorkbookSettings(); wbSettings.setLocale(new Locale("tr", "TR")); WritableWorkbook workbook = Workbook.createWorkbook(baos, wbSettings); WritableSheet sheet = workbook.createSheet(documentName, 0); sheet.setPageSetup(PageOrientation.PORTRAIT, PaperSize.A4, 0, 0); String upTitle = Constants.REPORT_UP_TITLE; String title = "Report"; sheet.mergeCells(0, 0, 2, 0); // REASON OF THIS ISSUE!! Label header = new Label(0, 0, upTitle, boldArial10CenterFormat); sheet.addCell(header); sheet.mergeCells(0, 1, 2, 0); // REASON OF THIS ISSUE!! header = new Label(0, 1, title, boldArial10CenterFormat); sheet.addCell(header); // HEADERS int i = 0; int satir = 2; Label label = new Label(i, satir, "#", boldArial10Format); sheet.addCell(label); sheet.setColumnView(i, sbtSizeCellView); i++; label = new Label(i, satir, "Column 1", boldArial10Format); sheet.addCell(label); sheet.setColumnView(i, autoSizeCellView); i++; label = new Label(i, satir, "Column 2", boldArial10Format); sheet.addCell(label); sheet.setColumnView(i, autoSizeCellView); for (int j = 0; j < list.size(); j++) { int sutun = 0; Label dataLabel = new Label(sutun, j + 3, (j + 1) + "", arial10Format); sheet.addCell(dataLabel); sutun++; dataLabel = new Label(sutun, j + 3, "Row 1", arial10Format); sheet.addCell(dataLabel); sutun++; dataLabel = new Label(sutun, j + 3, "Row 1", arial10Format); sheet.addCell(dataLabel); } workbook.write(); workbook.close(); 

对不起,我不是一个专业的jxl api。 但是我确实希望为您的Windows Office修改需求build议使用差异API。

http://poi.apache.org/据我所知,Apache POI更稳定,支持官方API。