Comment puis-je faire pivoter le texte dans une classe HSSFCell de POI Apache? P>
3 Réponses :
Utilisez HSSFCellstyle, cette classe a une méthode appelée setrotation (rotation courte) qui fera pivoter le texte. Tout ce que vous faites est d'appliquer le style de cellule à une cellule:
HSSFCellStyle myStyle = workbook.createCellStyle(); myStyle.setRotation((short)90); HSSFCell c = row.createCell(columnNumber); c.setCellStyle(myStyle);
Le paramètre INT en setrotation doit être jeté à court.
CellStyle cssVertical = wb.createCellStyle(); cssVertical.setFont(f); cssVertical.setRotation((short)90);
XSSFWorkbook workbook = new XSSFWorkbook(); XSSFSheet sheet = workbook.createSheet(); XSSFRow row = sheet.createRow(1); XSSFCell cell = row.createCell(1); XSSFCellStyle cs = workbook.createCellStyle(); cs.setRotation((short) 90); // set text rotation cs.getStyleXf().setApplyAlignment(true); // <<< Important cell.setCellValue("Vertical Text"); cell.setCellStyle(cs); workbook.write(new FileOutputStream("out.xlsx")); Apache POI 3.17, need to manually add alignment="true" attribute in cellXfs section.