List of usage examples for org.apache.poi.ss.usermodel CellStyle setFillPattern
void setFillPattern(FillPatternType fp);
From source file:com.ostrichemulators.semtool.poi.main.XlsWriter.java
License:Open Source License
@Override public void write(ImportData data, OutputStream output) throws IOException { createWorkbook(data);/*w w w. ja v a 2 s . c o m*/ CellStyle errorstyle = currentwb.createCellStyle(); errorstyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); errorstyle.setFillForegroundColor(IndexedColors.PINK.getIndex()); for (LoadingSheetData nodes : data.getNodes()) { List<String> props = new ArrayList<>(nodes.getProperties()); createTab(nodes.getName(), makeHeaderRow(nodes, props)); // +2 -> 1 for the blank first col and 1 for the subject type String[] row = new String[2 + props.size()]; CellStyle[] fmts = new CellStyle[2 + props.size()]; Map<String, IRI> proplkp = nodes.getPropertiesAndDataTypes(); IRI[] datatypes = new IRI[2 + props.size()]; int dtcol = 2; for (String propname : props) { if (null != proplkp.get(propname)) { datatypes[dtcol] = proplkp.get(propname); } dtcol++; } DataIterator di = nodes.iterator(); while (di.hasNext()) { LoadingNodeAndPropertyValues nap = di.next(); row[1] = nap.getSubject(); fmts[1] = (nap.isSubjectError() ? errorstyle : null); int col = 2; for (String prop : props) { Value val = nap.get(prop); row[col++] = (null == val ? null : val.stringValue()); } addRow(row, fmts, datatypes); } } for (LoadingSheetData rels : data.getRels()) { List<String> props = new ArrayList<>(rels.getProperties()); createTab(rels.getName(), makeHeaderRow(rels, props)); // +3 -> 1 for the blank first col and 1 for the subject type, 1 for object type String[] row = new String[3 + props.size()]; CellStyle[] fmts = new CellStyle[3 + props.size()]; if (rels.isEmpty()) { // no rows to add, but still add the relationship name field row[0] = rels.getRelname(); } Map<String, IRI> proplkp = rels.getPropertiesAndDataTypes(); IRI[] datatypes = new IRI[3 + props.size()]; int dtcol = 3; for (String propname : props) { if (null != proplkp.get(propname)) { datatypes[dtcol] = proplkp.get(propname); } dtcol++; } DataIterator di = rels.iterator(); while (di.hasNext()) { LoadingNodeAndPropertyValues nap = di.next(); if (rels.hasErrors()) { log.warn("tab color not set (refactor, please)"); //currentsheet.setTabColor( IndexedColors.ROSE.getIndex() ); } // do we need the relation name in the first column? row[0] = (nextRowIsFirstRowOfTab() ? rels.getRelname() : null); row[1] = nap.getSubject(); fmts[1] = (nap.isSubjectError() ? errorstyle : null); row[2] = nap.getObject(); fmts[2] = (nap.isObjectError() ? errorstyle : null); int col = 3; for (String prop : props) { Value val = nap.get(prop); row[col++] = (null == val ? null : val.stringValue()); } addRow(row, fmts, datatypes); } } write(output); }
From source file:com.plugin.excel.util.ExcelFileHelper.java
License:Apache License
private static void formatCell(Workbook workbook, Cell cell, ExcelCell excell, Map<IndexedColors, CellStyle> s_cellStyle, Font font, Font invisibleFont) { if (excell.getFormat() != null) { ExcelFormat format = excell.getFormat(); CellStyle style = s_cellStyle.get(format.getBackgroundColor()); if (format.isDate()) { // for date create a new style style = getDateStyle("date", cell.getSheet(), font); XSSFCreationHelper createHelper = (XSSFCreationHelper) cell.getSheet().getWorkbook() .getCreationHelper(); style.setDataFormat(createHelper.createDataFormat().getFormat("MMMM dd, yyyy")); font.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL); font.setBold(false);/* w ww . j a va 2 s .c o m*/ font.setFontHeightInPoints((short) 12); style.setFont(font); cell.setCellValue(new Date()); } if (style == null) { style = workbook.createCellStyle(); s_cellStyle.put(format.getBackgroundColor(), style); } if (format.getAlignment() > 0) { style.setAlignment(format.getAlignment()); } if (format.getBackgroundColor() != null && !IndexedColors.WHITE.equals(format.getBackgroundColor())) { style.setFillForegroundColor(format.getBackgroundColor().getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); } if (format.getTextColor() != null) { font.setColor(format.getTextColor().getIndex()); style.setFont(font); } if (format.isBold()) { font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); } if (format.getFontHeight() > 0) { font.setFontHeightInPoints(format.getFontHeight()); } if (format.isWrapText()) { style.setWrapText(true); } style.setFont(font); if (format.isHideText()) { invisibleFont.setColor(IndexedColors.WHITE.getIndex()); style.setFont(invisibleFont); } cell.setCellStyle(style); } else { // Let's set default formatting for free text cell IndexedColors defaultStyle = IndexedColors.AUTOMATIC; // we are using this index CellStyle style = s_cellStyle.get(defaultStyle); if (style == null) { style = workbook.createCellStyle(); s_cellStyle.put(defaultStyle, style); } style.setWrapText(true); cell.setCellStyle(style); } }
From source file:com.primovision.lutransport.core.util.TollCompanyTagUploadUtil.java
private static void createColumnHeaders(LinkedList<String> expectedColumnList, Sheet sheet, CellStyle style) { Row headerRow = sheet.createRow(0);//from www. j a v a 2 s. c o m int columnHeaderIndex = 0; for (String columnHeader : expectedColumnList) { // TODO redundant, use actualColumnListMap.keys instead sheet.setColumnWidth(columnHeaderIndex, 256 * 20); Cell cell = headerRow.createCell(columnHeaderIndex++); cell.setCellValue(columnHeader); style.setAlignment(CellStyle.ALIGN_CENTER); style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); cell.setCellStyle(style); } }
From source file:com.rarediscovery.services.logic.WorkPad.java
protected CellStyle applySelectedStyle() { Font font = workbook.createFont(); if (bold) {/* w ww. j a va2 s .co m*/ font.setBold(true); } else { font.setBold(false); } CellStyle style = workbook.createCellStyle(); style.setFont(font); if (alignRight) { style.setAlignment(CellStyle.ALIGN_RIGHT); } else { style.setAlignment(CellStyle.ALIGN_LEFT); } if (backgroundColor) { style.setFillBackgroundColor(IndexedColors.ORANGE.getIndex()); style.setFillPattern(CellStyle.BIG_SPOTS); } else { style.setFillBackgroundColor(IndexedColors.WHITE.getIndex()); } return style; }
From source file:com.saba.CalendarDemo.java
License:Apache License
private static Map<String, CellStyle> createStyles(Workbook wb) { Map<String, CellStyle> styles = new HashMap<String, CellStyle>(); CellStyle style; Font titleFont = wb.createFont(); titleFont.setFontHeightInPoints((short) 14); titleFont.setFontName("Trebuchet MS"); titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD); style = createBorderedStyle(wb);//from ww w. ja v a 2 s .c om style.setFont(titleFont); style.setAlignment(CellStyle.ALIGN_CENTER); style.setFillForegroundColor(IndexedColors.GREEN.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); styles.put("title", style); Font itemFontLeft = wb.createFont(); itemFontLeft.setFontHeightInPoints((short) 11); itemFontLeft.setFontName("Trebuchet MS"); itemFontLeft.setBoldweight(Font.BOLDWEIGHT_BOLD); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_LEFT); style.setFont(itemFontLeft); styles.put("item_left", style); Font itemFontRight = wb.createFont(); itemFontRight.setFontHeightInPoints((short) 10); itemFontRight.setFontName("Trebuchet MS"); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_LEFT); style.setFont(itemFontRight); styles.put("item_right", style); return styles; }
From source file:com.saba.CalendarDemo.java
License:Apache License
/** * createHeaderStyle : // ww w.ja v a2 s . co m * Header row setting for sheet * @param wb * @return */ private static CellStyle createHeaderStyleForAward(Workbook wb) { CellStyle headerStyle; Font headerFont = wb.createFont(); headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD); headerStyle = createBorderedStyle(wb); headerStyle.setAlignment(CellStyle.ALIGN_LEFT); headerStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); headerStyle.setFillPattern(CellStyle.SOLID_FOREGROUND); headerStyle.setFont(headerFont); return headerStyle; }
From source file:com.tecnosur.util.Excel.java
private static void createCell(HSSFWorkbook wb, Row row, int column, short halign, short valign, String strContenido, boolean booBorde, boolean booCabecera) { CreationHelper ch = wb.getCreationHelper(); Cell cell = row.createCell(column);/*from w w w . j a va 2 s . c o m*/ HSSFFont cellFont = wb.createFont(); cellFont.setFontHeightInPoints((short) 8); cellFont.setFontName(HSSFFont.FONT_ARIAL); cellFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); cell.setCellValue(ch.createRichTextString(strContenido)); CellStyle cellStyle = wb.createCellStyle(); cellStyle.setAlignment(halign); cellStyle.setVerticalAlignment(valign); cellStyle.setFont(cellFont); if (booBorde) { cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); cellStyle.setBottomBorderColor((short) 8); cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); cellStyle.setLeftBorderColor((short) 8); cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN); cellStyle.setRightBorderColor((short) 8); cellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN); cellStyle.setTopBorderColor((short) 8); } if (booCabecera) { cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); cellStyle.setBottomBorderColor((short) 8); cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); cellStyle.setLeftBorderColor((short) 8); cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN); cellStyle.setRightBorderColor((short) 8); cellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN); cellStyle.setTopBorderColor((short) 8); cellStyle.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index); cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); } cell.setCellStyle(cellStyle); }
From source file:com.tm.hiber.service.util.DatabaseUtil.java
/** * * @param objFile/*from w ww .j a v a 2s . c o m*/ * @param objJTable * @return number of records exported */ public int exportData(File objFile, JTable objJTable) throws FileNotFoundException, IOException { int response = 0; if (objFile == null) { return response; } DefaultTableModel tm = (DefaultTableModel) objJTable.getModel(); Object[] rows = tm.getDataVector().toArray(); JTableHeader columnNames = objJTable.getTableHeader(); TableColumnModel columnModel = columnNames.getColumnModel(); int columnCount = columnModel.getColumnCount(); Vector<String> vecColumnNames = new Vector<String>(); for (int c = 0; c < columnCount; c++) { vecColumnNames.add(columnModel.getColumn(c).getHeaderValue().toString()); } HSSFWorkbook exportReadyWorkbook = new HSSFWorkbook(); HSSFSheet dataSheet = exportReadyWorkbook.createSheet(getExportSheetName()); if (vecColumnNames.size() > 0) { int columnCounter = 0; Row objHSSFColumnName = dataSheet.createRow(0); for (String strColumnName : vecColumnNames) { /* Set Header CSS */ Cell objHSSFCell = objHSSFColumnName.createCell(columnCounter); objHSSFCell.setCellValue(strColumnName); CellStyle csll = exportReadyWorkbook.createCellStyle(); Font objFont = exportReadyWorkbook.createFont(); objFont.setFontName("Calibri"); objFont.setColor(IndexedColors.BLACK.index); objFont.setBold(true); csll.setFont(objFont); csll.setFillBackgroundColor(HSSFColor.YELLOW.index); csll.setFillForegroundColor(HSSFColor.YELLOW.index); csll.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); csll.setAlignment(HSSFCellStyle.ALIGN_CENTER); //csll.setWrapText(true); objHSSFCell.setCellStyle(csll); columnCounter++; } } if (rows != null && rows.length > 0) { /* Set Data into Sheet */ for (int i = 0; i < rows.length; i++) { Vector objCellsData = (Vector) rows[i]; Row objHSSFRow = dataSheet.createRow(i + 1); if (objCellsData != null && objCellsData.size() > 0) { for (int j = 0; j < objCellsData.size(); j++) { /* Set Cell Data CSS */ Cell objHSSFCell = objHSSFRow.createCell(j); CellStyle csll = exportReadyWorkbook.createCellStyle(); Font objFont = exportReadyWorkbook.createFont(); objFont.setColor(IndexedColors.BLACK.index); objFont.setBold(false); objFont.setFontName("Calibri"); csll.setFont(objFont); csll.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); csll.setFillBackgroundColor(IndexedColors.WHITE.index); csll.setFillForegroundColor(IndexedColors.WHITE.index); csll.setAlignment(HSSFCellStyle.ALIGN_CENTER); //csll.setWrapText(true); csll.setBorderBottom(CellStyle.BORDER_THIN); csll.setBorderTop(CellStyle.BORDER_THIN); csll.setBottomBorderColor(HSSFColor.GREY_25_PERCENT.index); csll.setTopBorderColor(HSSFColor.GREY_50_PERCENT.index); objHSSFCell.setCellStyle(csll); Object cellData = objCellsData.get(j); objHSSFCell.setCellValue((String) cellData); } } } for (int i = 0; i < columnCount; i++) { if (i == 2) { dataSheet.setColumnWidth(i, 30 * 256); } else { dataSheet.autoSizeColumn(i); } } /* Write File */ FileOutputStream objFileOutputStream = new FileOutputStream(objFile); exportReadyWorkbook.write(objFileOutputStream); objFileOutputStream.flush(); objFileOutputStream.close(); response = rows.length; } return response; }
From source file:com.vincestyling.apkinfoextractor.core.export.ExportToExcel.java
License:Apache License
private Map<String, CellStyle> createStyles(Workbook wb) { Map<String, CellStyle> styles = new HashMap<>(); String fontName = getAvaliableTitleFont(); CellStyle style; Font font = wb.createFont();//w w w . j a va2s. c o m font.setFontName(fontName); font.setFontHeightInPoints((short) 14); font.setColor(IndexedColors.BROWN.getIndex()); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_LEFT); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setFont(font); styles.put("title", style); font = wb.createFont(); font.setFontName(fontName); font.setFontHeightInPoints((short) 14); font.setBoldweight(Font.BOLDWEIGHT_BOLD); font.setColor(IndexedColors.WHITE.getIndex()); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_CENTER); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); style.setFont(font); style.setWrapText(true); setBorder(style); styles.put("header", style); font = wb.createFont(); font.setFontName(fontName); font.setFontHeightInPoints((short) 12); font.setColor(IndexedColors.BLACK.getIndex()); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setWrapText(true); style.setFont(font); setBorder(style); styles.put("cell", style); return styles; }
From source file:com.wabacus.system.assistant.StandardExcelAssistant.java
License:Open Source License
public CellStyle getTitleCellStyleForStandardExcel(Workbook workbook) { CellStyle cs = workbook.createCellStyle(); cs.setBorderTop(CellStyle.BORDER_THIN); cs.setBorderLeft(CellStyle.BORDER_THIN); cs.setBorderBottom(CellStyle.BORDER_THIN); cs.setBorderRight(CellStyle.BORDER_THIN); cs.setWrapText(true);/*from w ww. j av a 2 s . c o m*/ cs.setVerticalAlignment(CellStyle.VERTICAL_CENTER); cs.setAlignment(CellStyle.ALIGN_CENTER); cs.setFillPattern(CellStyle.SOLID_FOREGROUND); cs.setFillForegroundColor(HSSFColor.LIGHT_CORNFLOWER_BLUE.index); Font font = workbook.createFont(); font.setBoldweight(Font.BOLDWEIGHT_NORMAL); font.setFontHeightInPoints((short) 10); cs.setFont(font); //cs.setUserStyleName("wabacus_title_rowstyle");// return cs; }