List of usage examples for org.apache.poi.ss.usermodel Row getHeightInPoints
float getHeightInPoints();
From source file:org.unitime.timetable.export.XLSPrinter.java
License:Apache License
public void printLine(A... fields) { int cellIdx = 0; Row row = iSheet.createRow(iRowNum++); int nrLines = 1; for (int idx = 0; idx < fields.length; idx++) { if (iHiddenColumns.contains(idx)) continue; Cell cell = row.createCell(cellIdx++); A f = fields[idx];/* w w w .jav a2s. com*/ if (f == null || f.isEmpty() || (iCheckLast && f.equals(iLastLine == null || idx >= iLastLine.length ? null : iLastLine[idx]))) { f = new A(); if (fields[idx] != null && fields[idx].has(F.NOSEPARATOR)) f.set(F.NOSEPARATOR); } cell.setCellStyle(getStyle(f, iLastLine == null && !f.has(F.NOSEPARATOR), f.getPattern())); if (f.hasBufferedImage()) { try { addImageToSheet(cellIdx - 1, iRowNum - 1, (HSSFSheet) iSheet, f.getBufferedImage(), EXPAND_ROW_AND_COLUMN); } catch (IOException e) { e.printStackTrace(); } } if (f.isNumber()) { cell.setCellValue(f.getNumber()); } else if (f.isDate()) { cell.setCellValue(f.getDate()); } else if (f.hasText()) { boolean number = sNumber.matcher(f.getText()).matches(); if (number && f.has(F.RIGHT)) { try { cell.setCellValue(Double.valueOf(f.getText())); } catch (NumberFormatException e) { cell.setCellValue(f.getText()); } } else { cell.setCellValue(f.getText()); nrLines = Math.max(nrLines, f.getText().split("\n").length); } } else if (f.hasChunks()) { StringBuffer text = new StringBuffer(); List<Object[]> font = new ArrayList<Object[]>(); for (A g : f.getChunks()) { if (g.hasText()) { if (text.length() > 0) text.append(f.has(F.INLINE) ? " " : "\n"); font.add(new Object[] { text.length(), getFont(g.has(F.BOLD), g.has(F.ITALIC), g.has(F.UNDERLINE), g.getColor()) .getIndex() }); text.append(g.getText()); } if (g.hasChunks()) { for (A h : g.getChunks()) { if (h.hasText()) { if (text.length() > 0) text.append(" "); font.add(new Object[] { text.length(), getFont(h.has(F.BOLD), h.has(F.ITALIC), h.has(F.UNDERLINE), h.getColor()) .getIndex() }); text.append(h.getText()); } } } } nrLines = Math.max(nrLines, text.toString().split("\n").length); font.add(new Object[] { text.length(), (short) 0 }); HSSFRichTextString value = new HSSFRichTextString(text.toString()); for (int i = 0; i < font.size() - 1; i++) value.applyFont((Integer) font.get(i)[0], (Integer) font.get(1 + i)[0], (Short) font.get(i)[1]); cell.setCellValue(value); } } if (nrLines > 1) row.setHeightInPoints( Math.max(nrLines * iSheet.getDefaultRowHeightInPoints() + 1f, row.getHeightInPoints())); iLastLine = fields; }