List of usage examples for org.apache.poi.ss.usermodel CellStyle setWrapText
void setWrapText(boolean wrapped);
From source file:org.projectforge.excel.XlsContentProvider.java
License:Open Source License
@Override public XlsContentProvider updateCellStyle(final ExportCell cell) { final CellFormat format = cell.ensureAndGetCellFormat(); CellStyle cellStyle = reusableCellFormats.get(format); if (cellStyle == null) { cellStyle = workbook.createCellStyle(); reusableCellFormats.put(format, cellStyle); format.copyToCellStyle(cellStyle); if (format.getFillForegroundColor() != null) { cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); }// ww w .ja va 2 s.c o m cellStyle.setBorderBottom((short) 1); cellStyle.setBorderLeft((short) 1); cellStyle.setBorderRight((short) 1); cellStyle.setBorderTop((short) 1); cellStyle.setWrapText(true); final String dataFormat = format.getDataFormat(); if (dataFormat != null) { final short df = workbook.getDataFormat(format.getDataFormat()); cellStyle.setDataFormat(df); } } cell.setCellStyle(cellStyle); return this; }
From source file:org.projectforge.export.XlsContentProvider.java
License:Open Source License
public void updateCellStyle(final ExportCell cell) { final CellFormat format = cell.ensureAndGetCellFormat(); CellStyle cellStyle = reusableCellFormats.get(format); if (cellStyle == null) { cellStyle = workbook.createCellStyle(); reusableCellFormats.put(format, cellStyle); format.copyToCellStyle(cellStyle); if (format.getFillForegroundColor() != null) { cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); }//ww w. jav a 2s. c o m cellStyle.setBorderBottom((short) 1); cellStyle.setBorderLeft((short) 1); cellStyle.setBorderRight((short) 1); cellStyle.setBorderTop((short) 1); cellStyle.setWrapText(true); final String dataFormat = format.getDataFormat(); if (dataFormat != null) { final short df = workbook.getDataFormat(format.getDataFormat()); cellStyle.setDataFormat(df); } } cell.setCellStyle(cellStyle); }
From source file:org.sakaiproject.signup.tool.downloadEvents.WorksheetStyleClass.java
License:Educational Community License
public static Map<String, CellStyle> createStyles(Workbook wb) { Map<String, CellStyle> styles = new HashMap<String, CellStyle>(); CellStyle style; Font titleFont = wb.createFont(); titleFont.setFontHeightInPoints((short) 18); titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD); titleFont.setColor(IndexedColors.DARK_BLUE.getIndex()); style = wb.createCellStyle();/*from w w w .j a v a2s. c o m*/ style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setFont(titleFont); styles.put("title", style); Font commentTitleFont = wb.createFont(); commentTitleFont.setFontHeightInPoints((short) 12); commentTitleFont.setBoldweight(Font.BOLDWEIGHT_BOLD); commentTitleFont.setColor(IndexedColors.DARK_BLUE.getIndex()); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_LEFT); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setFont(commentTitleFont); styles.put("commentTitle", style); Font itemFont = wb.createFont(); itemFont.setFontHeightInPoints((short) 10); itemFont.setFontName("Trebuchet MS"); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_LEFT); style.setFont(itemFont); styles.put("item_left", style); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_LEFT); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setFont(itemFont); style.setWrapText(true); styles.put("item_left_wrap", style); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_LEFT); style.setVerticalAlignment(CellStyle.VERTICAL_TOP); style.setFont(itemFont); style.setWrapText(true); styles.put("item_left_wrap_top", style); itemFont.setFontHeightInPoints((short) 10); itemFont.setFontName("Trebuchet MS"); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setFont(itemFont); styles.put("tabItem_fields", style); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_RIGHT); style.setFont(itemFont); styles.put("item_right", style); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setFont(itemFont); style.setWrapText(true); styles.put("attendee_layout", style); Font itemBoldFont = wb.createFont(); itemBoldFont.setFontHeightInPoints((short) 10); itemBoldFont.setFontName("Trebuchet MS"); itemBoldFont.setColor(IndexedColors.DARK_BLUE.getIndex()); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_LEFT); style.setVerticalAlignment(CellStyle.VERTICAL_TOP); itemBoldFont.setBoldweight(Font.BOLDWEIGHT_BOLD); style.setFont(itemBoldFont); styles.put("item_leftBold", style); Font tableFont = wb.createFont(); tableFont.setFontHeightInPoints((short) 12); tableFont.setColor(IndexedColors.WHITE.getIndex()); tableFont.setBoldweight(Font.BOLDWEIGHT_BOLD); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setFillForegroundColor(IndexedColors.DARK_BLUE.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setFont(tableFont); styles.put("tabColNames", style); tableFont.setFontHeightInPoints((short) 10); tableFont.setColor(IndexedColors.WHITE.getIndex()); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setFont(tableFont); style.setWrapText(true); styles.put("header", style); Font linkFont = wb.createFont(); linkFont.setFontHeightInPoints((short) 10); linkFont.setColor(IndexedColors.BLUE.getIndex()); linkFont.setUnderline(Font.U_SINGLE); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_LEFT); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setFont(linkFont); styles.put("hyperLink", style); style = wb.createCellStyle(); style.setBorderTop(CellStyle.BORDER_THICK); style.setTopBorderColor(IndexedColors.DARK_BLUE.getIndex()); styles.put("tab_endline", style); return styles; }
From source file:org.sigmah.server.endpoint.export.sigmah.spreadsheet.ExcelUtils.java
License:Open Source License
public CellStyle getGlobalExportHeaderStyle(HSSFWorkbook wb) { CellStyle style = createBorderedStyle(wb); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); HSSFPalette palette = wb.getCustomPalette(); palette.setColorAtIndex(HSSFColor.GREY_25_PERCENT.index, ExportConstants.GRAY_5_RGB[0], ExportConstants.GRAY_5_RGB[1], ExportConstants.GRAY_5_RGB[2]); style.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setFont(getItalicFont(wb, (short) 10)); style.setWrapText(true); style.setIndention((short) 1); return style; }
From source file:org.sigmah.server.endpoint.export.sigmah.spreadsheet.ExcelUtils.java
License:Open Source License
public CellStyle getHeaderStyle(HSSFWorkbook wb) { CellStyle style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); HSSFPalette palette = wb.getCustomPalette(); palette.setColorAtIndex(HSSFColor.GREY_25_PERCENT.index, ExportConstants.GRAY_10_RGB[0], ExportConstants.GRAY_10_RGB[1], ExportConstants.GRAY_10_RGB[2]); style.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setFont(getBoldFont(wb, (short) 10)); style.setWrapText(true); return style; }
From source file:org.sigmah.server.endpoint.export.sigmah.spreadsheet.ExcelUtils.java
License:Open Source License
public CellStyle getGroupStyle(HSSFWorkbook wb) { CellStyle style = createBorderedStyle(wb); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); HSSFPalette palette = wb.getCustomPalette(); palette.setColorAtIndex(HSSFColor.BROWN.index, ExportConstants.LIGHTORANGE_RGB[0], ExportConstants.LIGHTORANGE_RGB[1], ExportConstants.LIGHTORANGE_RGB[2]); style.setFillForegroundColor(HSSFColor.BROWN.index); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setFont(getItalicFont(wb, (short) 10)); style.setWrapText(true); return style; }
From source file:org.sigmah.server.endpoint.export.sigmah.spreadsheet.ExcelUtils.java
License:Open Source License
public CellStyle getInfoStyle(Workbook wb, boolean bold) { Font font = getBoldFont(wb, (short) 11); if (!bold)// www . j av a2 s . c o m font.setBoldweight(Font.BOLDWEIGHT_NORMAL); CellStyle style = wb.createCellStyle(); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setFont(font); style.setIndention((short) 1); style.setWrapText(true); return style; }
From source file:org.sigmah.server.endpoint.export.sigmah.spreadsheet.ExcelUtils.java
License:Open Source License
public CellStyle getBoderedBasicStyle(Workbook wb) { CellStyle style = createBorderedStyle(wb); style.setIndention((short) 1); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setWrapText(true); return style; }
From source file:org.sigmah.server.endpoint.export.sigmah.spreadsheet.ExcelUtils.java
License:Open Source License
public void createLinkCell(HSSFCell cell, String value, String target, boolean bordered) { cell.setCellValue(value);/* w ww . ja va 2s . c o m*/ CellStyle style = wb.createCellStyle(); if (bordered) style = createBorderedStyle(wb); Font hlink_font = wb.createFont(); hlink_font.setUnderline(Font.U_SINGLE); hlink_font.setColor(IndexedColors.BLUE.getIndex()); style.setFont(hlink_font); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setIndention((short) 1); style.setWrapText(true); HSSFHyperlink link = new HSSFHyperlink(HSSFHyperlink.LINK_DOCUMENT); link.setAddress("'" + normalizeAsLink(target) + "'!A1"); cell.setHyperlink(link); cell.setCellStyle(style); }
From source file:org.sigmah.server.report.renderer.excel.ExcelPivotTableRenderer.java
License:Open Source License
@Override public void render(Workbook book, PivotTableElement element) { /* Generate the actual pivot table data */ final PivotTableData table = element.getContent().getData(); /* Generate the excel sheet */ new BaseExcelTableRenderer<PivotTableElement, PivotTableData.Axis>(book, element) { @Override/*from w ww . j av a2s . c o m*/ public List<FilterDescription> generateFilterDescriptions() { return element.getContent().getFilterDescriptions(); } protected CellStyle[] rowHeaderStyles; @Override public void generate() { /* Initialize Cell Styles */ initColHeaderStyles(table.getRootColumn()); initRowHeaderStyles(); /* Generate the column headers */ generateColumnHeaders(1, table.getRootColumn()); int headerHeight = rowIndex; /* Create the rows */ // row headers are in column 1 sheet.setColumnWidth(0, 40 * 256); generateRows(table.getRootRow().getChildList(), 0); /* Finalize the sheet */ sheet.setRowSumsBelow(false); sheet.createFreezePane(1, headerHeight); } protected void initRowHeaderStyles() { int depth = table.getRootRow().getDepth(); rowHeaderStyles = new CellStyle[depth]; for (int i = 0; i != depth; ++i) { CellStyle style = book.createCellStyle(); style.setIndention((short) i); style.setWrapText(true); Font font = createBaseFont(); if (i + 1 != depth) { /* Has sub headers */ font.setBoldweight(Font.BOLDWEIGHT_BOLD); } else { font.setBoldweight(Font.BOLDWEIGHT_NORMAL); } style.setFont(font); rowHeaderStyles[i] = style; } } protected void generateRows(List<PivotTableData.Axis> rows, int indent) { for (PivotTableData.Axis pivotRow : rows) { Row row = sheet.createRow(rowIndex++); Cell headerCell = row.createCell(0); headerCell.setCellValue(factory.createRichTextString(pivotRow.getLabel())); headerCell.setCellStyle(rowHeaderStyles[indent]); if (pivotRow.isLeaf()) { for (Entry<PivotTableData.Axis, Integer> entry : colIndexMap.entrySet()) { PivotTableData.Cell pivotCell = pivotRow.getCell(entry.getKey()); if (pivotCell != null) { Cell cell = row.createCell(entry.getValue()); cell.setCellValue(pivotCell.getValue()); } } } else { int groupStart = rowIndex; generateRows(pivotRow.getChildList(), indent + 1); int groupEnd = rowIndex; sheet.groupRow(groupStart, groupEnd); } } } }; }