Java Code Examples for org.apache.poi.ss.usermodel.CellStyle#getWrapText()
The following examples show how to use
org.apache.poi.ss.usermodel.CellStyle#getWrapText() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HSSFCellStyleProducer.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 6 votes |
protected HSSFCellStyleKey( final CellStyle style ) { this.color = style.getFillForegroundColor(); this.colorTop = style.getTopBorderColor(); this.colorLeft = style.getLeftBorderColor(); this.colorBottom = style.getBottomBorderColor(); this.colorRight = style.getRightBorderColor(); this.borderStrokeTop = style.getBorderTopEnum(); this.borderStrokeLeft = style.getBorderLeftEnum(); this.borderStrokeBottom = style.getBorderBottomEnum(); this.borderStrokeRight = style.getBorderRightEnum(); this.dataStyle = style.getDataFormat(); this.font = style.getFontIndex(); this.horizontalAlignment = style.getAlignmentEnum(); this.verticalAlignment = style.getVerticalAlignmentEnum(); this.wrapText = style.getWrapText(); this.textRotation = TextRotation.getInstance( style.getRotation() ); }
Example 2
Source File: AbstractSheet.java From tools with Apache License 2.0 | 5 votes |
/** * @param cell * @return */ @SuppressWarnings("deprecation") private int getNumWrappedLines(Cell cell) { if (cell.getCellTypeEnum() == CellType.STRING) { String val = cell.getStringCellValue(); if (val == null || val.isEmpty()) { return 1; } CellStyle style = cell.getCellStyle(); if (style == null || !style.getWrapText()) { return 1; } Font font = sheet.getWorkbook().getFontAt(style.getFontIndex()); AttributedString astr = new AttributedString(val); java.awt.Font awtFont = new java.awt.Font(font.getFontName(), 0, font.getFontHeightInPoints()); float cellWidth = sheet.getColumnWidth(cell.getColumnIndex())/ 256F * 5.5F; astr.addAttribute(TextAttribute.FONT, awtFont); FontRenderContext context = new FontRenderContext(null, true, true); java.awt.font.LineBreakMeasurer measurer = new java.awt.font.LineBreakMeasurer(astr.getIterator(), context); int pos = 0; int numLines = 0; while (measurer.getPosition() < val.length()) { pos = measurer.nextOffset(cellWidth); numLines++; measurer.setPosition(pos); } return numLines; } else { // Not a string type return 1; } }