2011-11-03 62 views
19

我正在使用POI api。现在我的问题是,我无法将单元格文本垂直对齐。我使用getCellStyle().setAlignment(HSSFCellStyle.VERTICAL_TOP)来设置对齐方式。使用poi的单元格垂直顶部对齐方式

然而,当我打开工作表时,它不受影响。

回答

-4
style = wb.createCellStyle(); 
style.setFillForegroundColor(IndexedColors.ORANGE.getIndex()); 
style.setFillPattern(CellStyle.SOLID_FOREGROUND); 
cell = row.createCell((short) 2); 
cell.setCellValue("X"); 
cell.setCellStyle(style); 
+3

它包含一无所知排列呢?它是关于背景颜色的... – efirat

18

有这个问题,以及,你会被supprised但设置垂直aligment到风格POI你应该使用setVerticalAlignment()功能不setAlignment()。例如:

XSSFCellStyle styleSubHeader = (XSSFCellStyle) wb.createCellStyle(); 
styleSubHeader.setVerticalAlignment(CellStyle.VERTICAL_CENTER); 
4
XSSFWorkbook wbOut = new XSSFWorkbook();  
CellStyle style = wbOut.createCellStyle(); 
style.setVerticalAlignment(HSSFCellStyle.VERTICAL_TOP); 
cell.setCellStyle(style); 
3

您可以使用此代码:

style.setVerticalAlignment(VerticalAlignment.TOP);