Setting the vertical alignment of the style of the first cell in a row to CellStyle.VERTICAL_TOP, then subsequently attempting to set a later cell to CelLStyle.VERTICAL_BOTTOM results in both cells having TOP alignment (essentially, the second alignment is ignored). I've opened the result of executing the below demo snippet in both LibreOffice and OpenOffice (but not actual MS Excel, not sure if it would behave properly), and the problem appears in both, so I suspect it's a POI problem and not a bug common to both, though that is possible. public class POITest { public static void main(String[] args) { //HSSFWorkbook exhibits correct behavior: Workbook workbook = new XSSFWorkbook(); CellStyle vertTop = workbook.createCellStyle(); vertTop.setVerticalAlignment(CellStyle.VERTICAL_TOP); CellStyle vertBottom = workbook.createCellStyle(); vertBottom.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM); Sheet sheet = workbook.createSheet("Sheet 1"); Row row = sheet.createRow(0); Cell top = row.createCell(0); Cell bottom = row.createCell(1); top.setCellValue("Top"); top.setCellStyle(vertTop); //comment this out to get all bottom-aligned cells bottom.setCellValue("Bottom"); bottom.setCellStyle(vertBottom); row.setHeightInPoints(85.75f); //make it obvious try { FileOutputStream out = new FileOutputStream("test.xlsx"); workbook.write(out); out.flush(); out.close(); } catch (IOException e) { e.printStackTrace(System.err); } } }
Created attachment 32019 [details] demo snippet
Created attachment 32703 [details] Result of running the code and opening the file in MS Excel
See the attached picture, it seems to work when opening the file with MS Excel, so I think this is rather a problem in LibreOffice/OpenOffice (which both share a common code-base so can easily have the same bug).