List of usage examples for org.apache.poi.ss.usermodel CellStyle setBorderBottom
void setBorderBottom(BorderStyle border);
From source file:org.eclipse.sw360.exporter.ExcelExporter.java
License:Open Source License
/** * Create style for data cells/*w w w . j ava 2s . c o m*/ */ private static CellStyle createCellStyle(Workbook workbook) { CellStyle cellStyle = workbook.createCellStyle(); cellStyle.setBorderBottom(XSSFCellStyle.BORDER_THIN); cellStyle.setBorderTop(XSSFCellStyle.BORDER_THIN); cellStyle.setBorderRight(XSSFCellStyle.BORDER_THIN); cellStyle.setBorderLeft(XSSFCellStyle.BORDER_THIN); return cellStyle; }
From source file:org.forzaframework.util.ExcelUtils.java
License:Apache License
public static CellStyle getDefaultHeaderCellStyle(Workbook wb, Boolean defaultFormat) { CellStyle headerCellStyle = null; if (defaultFormat != null && defaultFormat) { //Le damos formato a los encabezados headerCellStyle = wb.createCellStyle(); headerCellStyle.setBorderBottom(BorderStyle.DOTTED); headerCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); // headerCellStyle.setFillBackgroundColor(HSSFColor.GREY_25_PERCENT.index); headerCellStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); //Creamos el tipo de fuente Font headerFont = wb.createFont(); // headerFont.setFontName(HSSFFont.FONT_ARIAL); headerFont.setBold(Boolean.TRUE); headerFont.setColor(Font.COLOR_NORMAL); headerFont.setFontHeightInPoints((short) 8); headerCellStyle.setFont(headerFont); }/* w w w.j a v a 2s . c om*/ return headerCellStyle; }
From source file:org.haplo.jsinterface.generate.KGenerateXLS.java
License:Mozilla Public License
@Override protected void writeRow(int rowNumber, ArrayList<Object> row, ArrayList<Object> rowOptions, boolean isHeaderRow, boolean pageBreakBefore) { Row r = this.sheet.createRow(rowNumber); if (pageBreakBefore && rowNumber > 0) { this.sheet.setRowBreak(rowNumber - 1); }/* w ww .j a v a 2s .c o m*/ int rowSize = row.size(); for (int i = 0; i < rowSize; ++i) { Object value = row.get(i); // ConsString is checked if (value != null) { Cell c = r.createCell(i); if (value instanceof Number) { c.setCellValue(((Number) value).doubleValue()); } else if (value instanceof CharSequence) { c.setCellValue(((CharSequence) value).toString()); } else if (value instanceof Date) { c.setCellValue((Date) value); // Check to see if option is for dates only boolean dateAndTimeStyle = true; String options = (String) getOptionsFromArrayList(rowOptions, i, String.class); // ConsString is checked by getOptionsFromArrayList() if (options != null && options.equals("date")) { dateAndTimeStyle = false; } if (dateCellStyle == null) { // Only create one each of the date cell styles per workbook to save space. dateCellStyle = workbook.createCellStyle(); dateCellStyle.setDataFormat(workbook.createDataFormat().getFormat("yyyy-mm-dd hh:mm")); dateOnlyCellStyle = workbook.createCellStyle(); dateOnlyCellStyle.setDataFormat(workbook.createDataFormat().getFormat("yyyy-mm-dd")); } c.setCellStyle(dateAndTimeStyle ? dateCellStyle : dateOnlyCellStyle); // Set column width so the dates don't come out as ########## on causal viewing setMinimumWidth(i, dateAndTimeStyle ? DATE_AND_TIME_COLUMN_WIDTH : DATE_COLUMN_WIDTH); } } } if (isHeaderRow) { // Make sure the row is always on screen this.sheet.createFreezePane(0, 1, 0, 1); // Style the row CellStyle style = this.workbook.createCellStyle(); style.setBorderBottom(BorderStyle.THIN); Font font = this.workbook.createFont(); font.setBold(true); style.setFont(font); r.setRowStyle(style); // Style the cells for (int s = 0; s < rowSize; ++s) { Cell c = r.getCell(s); if (c == null) { c = r.createCell(s); } c.setCellStyle(style); } } }
From source file:org.hellojavaer.poi.excel.utils.ExcelUtils.java
License:Apache License
@SuppressWarnings("rawtypes") private static void writeHead(boolean useTemplate, Sheet sheet, ExcelWriteSheetProcessor sheetProcessor) { Integer headRowIndex = sheetProcessor.getHeadRowIndex(); if (headRowIndex == null) { return;/* w w w . j a v a 2 s. c om*/ } Workbook wookbook = sheet.getWorkbook(); // use theme CellStyle style = null; if (!useTemplate && sheetProcessor.getTheme() != null) { int theme = sheetProcessor.getTheme(); if (theme == ExcelWriteTheme.BASE) { style = wookbook.createCellStyle(); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setFillForegroundColor((short) 44); style.setBorderBottom(CellStyle.BORDER_THIN); style.setBorderLeft(CellStyle.BORDER_THIN); style.setBorderRight(CellStyle.BORDER_THIN); style.setBorderTop(CellStyle.BORDER_THIN); // style.setBottomBorderColor((short) 44); style.setAlignment(CellStyle.ALIGN_CENTER); } // freeze Pane if (sheetProcessor.getHeadRowIndex() != null && sheetProcessor.getHeadRowIndex() == 0) { sheet.createFreezePane(0, 1, 0, 1); } } Row row = sheet.getRow(headRowIndex); if (row == null) { row = sheet.createRow(headRowIndex); } for (Map.Entry<String, Map<Integer, ExcelWriteFieldMappingAttribute>> entry : sheetProcessor .getFieldMapping().export().entrySet()) { Map<Integer, ExcelWriteFieldMappingAttribute> map = entry.getValue(); if (map != null) { for (Map.Entry<Integer, ExcelWriteFieldMappingAttribute> entry2 : map.entrySet()) { String head = entry2.getValue().getHead(); Integer colIndex = entry2.getKey(); Cell cell = row.getCell(colIndex); if (cell == null) { cell = row.createCell(colIndex); } // use theme if (!useTemplate && sheetProcessor.getTheme() != null) { cell.setCellStyle(style); } cell.setCellValue(head); } } } }
From source file:org.jaffa.qm.finder.apis.ExcelExportService.java
License:Open Source License
public static Workbook generateExcel(QueryServiceConfig master, QueryServiceConfig child, String sheetName) throws ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { Workbook wb = null;/*from w w w .j a va 2s . co m*/ String legacyExport = (String) ContextManagerFactory.instance() .getProperty("jaffa.widgets.exportToExcel.legacy"); if (legacyExport != null && legacyExport.equals("T")) { wb = new HSSFWorkbook(); } else { wb = new SXSSFWorkbook(100); } try { // Creating worksheet Sheet sheet = null; if (sheetName != null) sheet = wb.createSheet(sheetName); else sheet = wb.createSheet(); // creating a custom palette for the workbook CellStyle style = wb.createCellStyle(); style = wb.createCellStyle(); // setting the foreground color to gray style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); // Setting the border for the cells style.setBorderBottom(CellStyle.BORDER_THIN); style.setBottomBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderLeft(CellStyle.BORDER_THIN); style.setLeftBorderColor(IndexedColors.GREEN.getIndex()); style.setBorderRight(CellStyle.BORDER_THIN); style.setRightBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderTop(CellStyle.BORDER_THIN); style.setTopBorderColor(IndexedColors.BLACK.getIndex()); style.setAlignment(CellStyle.ALIGN_CENTER); // setting font weight Font titleFont = wb.createFont(); titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD); style.setFont(titleFont); int rowNum = 0; Row headerRow = sheet.createRow(rowNum); int colIndex = 0; for (Object o : master.getColumnModel()) { String columnTitle = (String) ((DynaBean) o).get("header"); if (columnTitle == null || columnTitle.length() == 0) columnTitle = (String) ((DynaBean) o).get("mapping"); headerRow.createCell(colIndex).setCellValue(columnTitle); Cell cell = headerRow.getCell(colIndex); cell.setCellStyle(style); sheet.autoSizeColumn(colIndex); colIndex += 1; } // Generate the Excel output by creating a simple HTML table if (child != null) { for (Object o : child.getColumnModel()) { String columnTitle = (String) ((DynaBean) o).get("header"); if (columnTitle == null || columnTitle.length() == 0) columnTitle = (String) ((DynaBean) o).get("mapping"); headerRow.createCell(colIndex).setCellValue(columnTitle); Cell cell = headerRow.getCell(colIndex); cell.setCellStyle(style); sheet.autoSizeColumn(colIndex); colIndex += 1; } } // Invoke the query and obtain an array of Graph objects Object[] queryOutput = invokeQueryService(master.getCriteriaClassName(), master.getCriteriaObject(), master.getServiceClassName(), master.getServiceClassMethodName()); // Add the data rows if (queryOutput != null) { for (Object row : queryOutput) { Object[] detailQueryOutput = new Object[0]; if (child == null) { rowNum += 1; Row dataRow = sheet.createRow((short) rowNum); int colNum = 0; // extract the columns from master object for (Object o : master.getColumnModel()) { String mapping = (String) ((DynaBean) o).get("mapping"); Object value = null; if (mapping.startsWith("appFields.")) { mapping = mapping.substring(10); try { Object[] appFields = (Object[]) PropertyUtils.getProperty(row, "applicationFields"); for (Object field : appFields) { String name = (String) PropertyUtils.getProperty(field, "name"); if (name.equals(mapping)) { value = (String) PropertyUtils.getProperty(field, "value"); } } } catch (Exception e) { if (log.isDebugEnabled()) log.debug("Property not found: " + mapping, e); } } else { try { value = PropertyUtils.getProperty(row, mapping); } catch (Exception e) { if (log.isDebugEnabled()) log.debug("Property not found: " + mapping, e); } } dataRow.createCell(colNum).setCellValue(format(value, (DynaBean) o)); colNum += 1; } } else { //child is not null // load the child rows String detailCriteriaObject = child.getCriteriaObject(); for (int i = 0; i < child.getMasterKeyFieldNames().length; i++) { String kfn = child.getMasterKeyFieldNames()[i]; try { String keyValue = (String) PropertyUtils.getProperty(row, kfn); detailCriteriaObject = detailCriteriaObject.replace("{" + i + "}", keyValue); } catch (Exception e) { if (log.isDebugEnabled()) log.debug("Key property not found: " + kfn, e); } } detailQueryOutput = invokeQueryService(child.getCriteriaClassName(), detailCriteriaObject, child.getServiceClassName(), "query"); // add the child columns if (detailQueryOutput != null && detailQueryOutput.length > 0) { for (Object detailRow : detailQueryOutput) { rowNum += 1; Row dataRow = sheet.createRow((short) rowNum); int colNum = 0; // extract the columns from master object for (Object obj : master.getColumnModel()) { String masterMapping = (String) ((DynaBean) obj).get("mapping"); Object masterValue = null; try { masterValue = PropertyUtils.getProperty(row, masterMapping); } catch (Exception e) { if (log.isDebugEnabled()) log.debug("Property not found: " + masterMapping, e); } dataRow.createCell(colNum).setCellValue(format(masterValue, (DynaBean) obj)); colNum += 1; } for (Object o : child.getColumnModel()) { String mapping = (String) ((DynaBean) o).get("mapping"); Object value = null; try { value = PropertyUtils.getProperty(detailRow, mapping); } catch (Exception e) { if (log.isDebugEnabled()) log.debug("Property not found in child result: " + mapping, e); } dataRow.createCell(colNum).setCellValue(format(value, (DynaBean) o)); colNum += 1; } } } } } } } catch (Exception e) { e.printStackTrace(); } return wb; }
From source file:org.jaffa.ria.finder.apis.ExcelExportService.java
License:Open Source License
public static Workbook generateExcel(QueryServiceConfig master, QueryServiceConfig child, String sheetName) throws ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { Workbook wb = null;/*from ww w. j a v a2 s. c o m*/ String legacyExport = (String) ContextManagerFactory.instance() .getProperty("jaffa.widgets.exportToExcel.legacy"); if (legacyExport != null && legacyExport.equals("T")) { wb = new HSSFWorkbook(); } else { wb = new SXSSFWorkbook(100); } try { // Creating worksheet Sheet sheet = null; if (sheetName != null) { if (sheetName.length() > 31) sheetName = sheetName.substring(0, 31); char replaceChar = '_'; sheetName = sheetName.replace('\u0003', replaceChar).replace(':', replaceChar) .replace('/', replaceChar).replace("\\\\", Character.toString(replaceChar)) .replace('?', replaceChar).replace('*', replaceChar).replace(']', replaceChar) .replace('[', replaceChar); sheet = wb.createSheet(sheetName); } else sheet = wb.createSheet(); // creating a custom palette for the workbook CellStyle style = wb.createCellStyle(); style = wb.createCellStyle(); // setting the foreground color to gray style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); // Setting the border for the cells style.setBorderBottom(CellStyle.BORDER_THIN); style.setBottomBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderLeft(CellStyle.BORDER_THIN); style.setLeftBorderColor(IndexedColors.GREEN.getIndex()); style.setBorderRight(CellStyle.BORDER_THIN); style.setRightBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderTop(CellStyle.BORDER_THIN); style.setTopBorderColor(IndexedColors.BLACK.getIndex()); style.setAlignment(CellStyle.ALIGN_CENTER); // setting font weight Font titleFont = wb.createFont(); titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD); style.setFont(titleFont); int rowNum = 0; Row headerRow = sheet.createRow(rowNum); int colIndex = 0; for (Object o : master.getColumnModel()) { String columnTitle = (String) ((DynaBean) o).get("header"); if (columnTitle == null || columnTitle.length() == 0) columnTitle = (String) ((DynaBean) o).get("mapping"); headerRow.createCell(colIndex).setCellValue(columnTitle); Cell cell = headerRow.getCell(colIndex); cell.setCellStyle(style); sheet.autoSizeColumn(colIndex); colIndex += 1; } // Generate the Excel output by creating a simple HTML table if (child != null) { for (Object o : child.getColumnModel()) { String columnTitle = (String) ((DynaBean) o).get("header"); if (columnTitle == null || columnTitle.length() == 0) columnTitle = (String) ((DynaBean) o).get("mapping"); headerRow.createCell(colIndex).setCellValue(columnTitle); Cell cell = headerRow.getCell(colIndex); cell.setCellStyle(style); sheet.autoSizeColumn(colIndex); colIndex += 1; } } // Invoke the query and obtain an array of Graph objects Object[] queryOutput = invokeQueryService(master.getCriteriaClassName(), master.getCriteriaObject(), master.getServiceClassName(), master.getServiceClassMethodName()); // Add the data rows if (queryOutput != null) { for (Object row : queryOutput) { Object[] detailQueryOutput = new Object[0]; if (child == null) { rowNum += 1; Row dataRow = sheet.createRow((short) rowNum); int colNum = 0; // extract the columns from master object for (Object o : master.getColumnModel()) { String mapping = (String) ((DynaBean) o).get("mapping"); Object value = null; try { value = PropertyUtils.getProperty(row, mapping); } catch (Exception e) { if (log.isDebugEnabled()) log.debug("Property not found: " + mapping, e); } dataRow.createCell(colNum).setCellValue(format(value, (DynaBean) o)); colNum += 1; } } else { //child is not null // load the child rows String detailCriteriaObject = child.getCriteriaObject(); for (int i = 0; i < child.getMasterKeyFieldNames().length; i++) { String kfn = child.getMasterKeyFieldNames()[i]; try { String keyValue = (String) PropertyUtils.getProperty(row, kfn); detailCriteriaObject = detailCriteriaObject.replace("{" + i + "}", keyValue); } catch (Exception e) { if (log.isDebugEnabled()) log.debug("Key property not found: " + kfn, e); } } detailQueryOutput = invokeQueryService(child.getCriteriaClassName(), detailCriteriaObject, child.getServiceClassName(), "query"); // add the child columns if (detailQueryOutput != null && detailQueryOutput.length > 0) { for (Object detailRow : detailQueryOutput) { rowNum += 1; Row dataRow = sheet.createRow((short) rowNum); int colNum = 0; // extract the columns from master object for (Object obj : master.getColumnModel()) { String masterMapping = (String) ((DynaBean) obj).get("mapping"); Object masterValue = null; try { masterValue = PropertyUtils.getProperty(row, masterMapping); } catch (Exception e) { if (log.isDebugEnabled()) log.debug("Property not found: " + masterMapping, e); } dataRow.createCell(colNum).setCellValue(format(masterValue, (DynaBean) obj)); colNum += 1; } for (Object o : child.getColumnModel()) { String mapping = (String) ((DynaBean) o).get("mapping"); Object value = null; try { value = PropertyUtils.getProperty(detailRow, mapping); } catch (Exception e) { if (log.isDebugEnabled()) log.debug("Property not found in child result: " + mapping, e); } dataRow.createCell(colNum).setCellValue(format(value, (DynaBean) o)); colNum += 1; } } } } } } } catch (Exception e) { e.printStackTrace(); } return wb; }
From source file:org.jboss.dashboard.displayer.table.ExportTool.java
License:Apache License
private Map<String, CellStyle> createStyles(Workbook wb) { Map<String, CellStyle> styles = new HashMap<String, CellStyle>(); CellStyle style; Font titleFont = wb.createFont(); titleFont.setFontHeightInPoints((short) 12); titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD); style = wb.createCellStyle();/* ww w . j a va 2s. co m*/ style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setFont(titleFont); style.setWrapText(false); style.setBorderBottom(CellStyle.BORDER_THIN); style.setBottomBorderColor(IndexedColors.GREY_80_PERCENT.getIndex()); styles.put("header", style); Font cellFont = wb.createFont(); cellFont.setFontHeightInPoints((short) 10); cellFont.setBoldweight(Font.BOLDWEIGHT_NORMAL); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_RIGHT); style.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM); style.setFont(cellFont); style.setWrapText(false); style.setDataFormat(wb.createDataFormat().getFormat(BuiltinFormats.getBuiltinFormat(3))); styles.put("integer_number_cell", style); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_RIGHT); style.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM); style.setFont(cellFont); style.setWrapText(false); style.setDataFormat(wb.createDataFormat().getFormat(BuiltinFormats.getBuiltinFormat(4))); styles.put("decimal_number_cell", style); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_LEFT); style.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM); style.setFont(cellFont); style.setWrapText(false); style.setDataFormat((short) BuiltinFormats.getBuiltinFormat("text")); styles.put("text_cell", style); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM); style.setFont(cellFont); style.setWrapText(false); style.setDataFormat(wb.createDataFormat() .getFormat(DateFormatConverter.convert(LocaleManager.currentLocale(), dateFormatPattern))); styles.put("date_cell", style); return styles; }
From source file:org.netxilia.impexp.impl.PoiUtils.java
License:Open Source License
public static CellStyle netxiliaStyle2Poi(Styles nxStyle, Workbook workbook, CellStyle poiStyle) { if (nxStyle == null) { return poiStyle; }//w w w. ja v a 2 s . co m poiStyle.setWrapText(nxStyle.contains(DefaultStyle.nowrap.getStyle())); // font short bold = nxStyle.contains(DefaultStyle.bold.getStyle()) ? Font.BOLDWEIGHT_BOLD : Font.BOLDWEIGHT_NORMAL; byte underline = nxStyle.contains(DefaultStyle.underline.getStyle()) ? Font.U_SINGLE : Font.U_NONE; boolean italic = nxStyle.contains(DefaultStyle.italic.getStyle()); boolean strikeout = nxStyle.contains(DefaultStyle.strikeout.getStyle()); Font defaultFont = workbook.getFontAt(poiStyle.getFontIndex()); Font font = workbook.findFont(bold, defaultFont.getColor(), defaultFont.getFontHeight(), defaultFont.getFontName(), italic, strikeout, defaultFont.getTypeOffset(), underline); if (font == null) { font = workbook.createFont(); font.setBoldweight(bold); font.setItalic(italic); font.setUnderline(underline); font.setStrikeout(strikeout); } poiStyle.setFont(font); // borders if (nxStyle.contains(DefaultStyle.borderLeft.getStyle())) { poiStyle.setBorderLeft(CellStyle.BORDER_THIN); } if (nxStyle.contains(DefaultStyle.borderRight.getStyle())) { poiStyle.setBorderRight(CellStyle.BORDER_THIN); } if (nxStyle.contains(DefaultStyle.borderTop.getStyle())) { poiStyle.setBorderTop(CellStyle.BORDER_THIN); } if (nxStyle.contains(DefaultStyle.borderBottom.getStyle())) { poiStyle.setBorderBottom(CellStyle.BORDER_THIN); } // align if (nxStyle.contains(DefaultStyle.alignLeft.getStyle())) { poiStyle.setAlignment(CellStyle.ALIGN_LEFT); } else if (nxStyle.contains(DefaultStyle.alignRight.getStyle())) { poiStyle.setAlignment(CellStyle.ALIGN_RIGHT); } else if (nxStyle.contains(DefaultStyle.alignCenter.getStyle())) { poiStyle.setAlignment(CellStyle.ALIGN_CENTER); } else if (nxStyle.contains(DefaultStyle.alignJustify.getStyle())) { poiStyle.setAlignment(CellStyle.ALIGN_JUSTIFY); } return poiStyle; }
From source file:org.phenotips.export.internal.Styler.java
License:Open Source License
public void style(DataCell dataCell, Cell cell, Workbook wBook) { Set<StyleOption> styles = dataCell.getStyles(); CellStyle cellStyle = wBook.createCellStyle(); /* For \n to work properly set to true */ cellStyle.setWrapText(true);/*from ww w. ja v a2 s . c o m*/ if (this.defaultFont == null) { this.defaultFont = createDefaultFont(wBook); } cellStyle.setFont(this.defaultFont); if (styles == null) { if (this.styleCache.containsKey(Collections.<StyleOption>emptySet())) { cell.setCellStyle(this.styleCache.get(Collections.<StyleOption>emptySet())); return; } cell.setCellStyle(cellStyle); this.styleCache.put(Collections.<StyleOption>emptySet(), cellStyle); return; } if (this.styleCache.containsKey(styles)) { cell.setCellStyle(this.styleCache.get(styles)); return; } /* Priority can be coded in by placing the if statement lower, for higher priority */ /** Font styles */ Font headerFont = null; if (styles.contains(StyleOption.HEADER)) { headerFont = wBook.createFont(); headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD); cellStyle.setFont(headerFont); cellStyle.setAlignment(CellStyle.ALIGN_CENTER); cellStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER); cell.setCellStyle(cellStyle); } if (styles.contains(StyleOption.LARGE_HEADER)) { if (headerFont == null) { headerFont = wBook.createFont(); headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD); } headerFont.setFontHeightInPoints((short) 12); cellStyle.setFont(headerFont); cell.setCellStyle(cellStyle); } if (styles.contains(StyleOption.YES)) { Font font = createDefaultFont(wBook); font.setColor(HSSFColor.GREEN.index); cellStyle.setFont(font); cell.setCellStyle(cellStyle); } if (styles.contains(StyleOption.NO)) { Font font = createDefaultFont(wBook); font.setColor(HSSFColor.DARK_RED.index); font.setBoldweight(Font.BOLDWEIGHT_BOLD); cellStyle.setFont(font); cell.setCellStyle(cellStyle); } /** Border styles */ if (styles.contains(StyleOption.HEADER_BOTTOM)) { cellStyle.setBorderBottom(CellStyle.BORDER_MEDIUM); cell.setCellStyle(cellStyle); } if (styles.contains(StyleOption.SECTION_BORDER_LEFT)) { cellStyle.setBorderLeft(CellStyle.BORDER_MEDIUM); cell.setCellStyle(cellStyle); } if (styles.contains(StyleOption.SECTION_BORDER_RIGHT)) { cellStyle.setBorderRight(CellStyle.BORDER_MEDIUM); cell.setCellStyle(cellStyle); } if (styles.contains(StyleOption.PATIENT_BORDER)) { cellStyle.setBorderBottom(CellStyle.BORDER_THIN); cell.setCellStyle(cellStyle); } if (styles.contains(StyleOption.FEATURE_SEPARATOR)) { cellStyle.setBorderTop(CellStyle.BORDER_THIN); cellStyle.setTopBorderColor(IndexedColors.GREY_25_PERCENT.getIndex()); cell.setCellStyle(cellStyle); } if (styles.contains(StyleOption.YES_NO_SEPARATOR)) { cellStyle.setBorderTop(CellStyle.BORDER_DASHED); cellStyle.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); cell.setCellStyle(cellStyle); } /* Keep this as the last statement. */ this.styleCache.put(styles, cellStyle); }
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); }/* w w w .j a v a 2 s. com*/ 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; }