Created attachment 34809 [details] example Hi: I have a question. Execute the following code, office2010 is no problem, but for office2013 AP after column style will be lost. I use poi version 3.12. Code: // for test public static void main(String[] args) { String[][] data = new String[][] { { "123", "456", "789", "012","123", "456", "789", "012","123", "456", "789", "012","123", "456", "789", "012","123", "456", "789", "012","123", "456", "789", "012","123", "456", "789", "012","123", "456", "789", "012","123", "456", "789", "012","123", "456", "789", "012","123", "456", "789", "012","123", "456", "789", "012","123", "456", "789", "012","123" }, { "123", "456", "789", "012","123", "456", "789", "012","123", "456", "789", "012","123", "456", "789", "012","123", "456", "789", "012","123", "456", "789", "012","123", "456", "789", "012","123", "456", "789", "012","123", "456", "789", "012","123", "456", "789", "012","123", "456", "789", "012","123", "456", "789", "012","123", "456", "789", "012","123" }, { "123", "456", "789", "012","123", "456", "789", "012","123", "456", "789", "012","123", "456", "789", "012","123", "456", "789", "012","123", "456", "789", "012","123", "456", "789", "012","123", "456", "789", "012","123", "456", "789", "012","123", "456", "789", "012","123", "456", "789", "012","123", "456", "789", "012","123", "456", "789", "012","123"} }; exportExcel(data, "E:\\excelutil-write.xls"); } public static boolean exportExcel(String[][] data, String filePath) { if (data == null || data.length == 0) { return false; } boolean flag = true; HSSFWorkbook workbook = new HSSFWorkbook(); try { File file = new File(filePath); if (file.exists()) { file.delete(); } FileOutputStream outputStream = new FileOutputStream(file); Sheet sheet = workbook.createSheet(); workbook.setSheetName(0, "sheet1"); Row row = null; Cell cell = null; int rowCount = data.length; int colCount = data[0].length; CellStyle style = workbook.createCellStyle(); style.setBorderBottom(CellStyle.BORDER_THIN); style.setBorderLeft(CellStyle.BORDER_THIN); style.setBorderRight(CellStyle.BORDER_THIN); style.setBorderTop(CellStyle.BORDER_THIN); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setAlignment(CellStyle.ALIGN_CENTER); List<CellStyle> dList = new ArrayList<CellStyle>(); for (int i = 0; i < colCount; i++) { CellStyle dstyle = workbook.createCellStyle(); dstyle.cloneStyleFrom(style); dstyle.setAlignment(CellStyle.ALIGN_CENTER); dList.add(dstyle); } for (int i = 0; i < rowCount; i++) { row = sheet.createRow(i); for (int j = 0; j < colCount; j++) { cell = row.createCell(j); cell.setCellType(XSSFCell.CELL_TYPE_STRING); cell.setCellValue(data[i][j]); CellStyle cStyle = dList.get(j); //cStyle.cloneStyleFrom(dList.get(j)); cell.setCellStyle(cStyle); } } workbook.write(outputStream); outputStream.close(); } catch (IOException ex) { flag = false; loger.error(ex); } finally { try { workbook.close(); } catch (IOException e) { } } return flag; }
There were many fixes in newer versions, maybe this one is already solved. Can you verify with the latest, preferably 3.16-beta2 to check if it still happens in the latest version?