List of usage examples for org.apache.poi.ss.usermodel CellStyle setVerticalAlignment
void setVerticalAlignment(VerticalAlignment align);
From source file:com.lufs.java.apache.poi.example.CalendarDemo.java
License:Apache License
/** * cell styles used for formatting calendar sheets *///from ww w . j a va 2 s .c o m private static Map<String, CellStyle> createStyles(Workbook wb) { Map<String, CellStyle> styles = new HashMap<>(); short borderColor = IndexedColors.GREY_50_PERCENT.getIndex(); CellStyle style; Font titleFont = wb.createFont(); titleFont.setFontHeightInPoints((short) 48); titleFont.setColor(IndexedColors.DARK_BLUE.getIndex()); style = wb.createCellStyle(); style.setAlignment(HorizontalAlignment.CENTER); style.setVerticalAlignment(VerticalAlignment.CENTER); style.setFont(titleFont); styles.put("title", style); Font monthFont = wb.createFont(); monthFont.setFontHeightInPoints((short) 12); monthFont.setColor(IndexedColors.WHITE.getIndex()); monthFont.setBold(true); style = wb.createCellStyle(); style.setAlignment(HorizontalAlignment.CENTER); style.setVerticalAlignment(VerticalAlignment.CENTER); style.setFillForegroundColor(IndexedColors.DARK_BLUE.getIndex()); style.setFillPattern(FillPatternType.SOLID_FOREGROUND); style.setFont(monthFont); styles.put("month", style); Font dayFont = wb.createFont(); dayFont.setFontHeightInPoints((short) 14); dayFont.setBold(true); style = wb.createCellStyle(); style.setAlignment(HorizontalAlignment.LEFT); style.setVerticalAlignment(VerticalAlignment.TOP); style.setFillForegroundColor(IndexedColors.LIGHT_CORNFLOWER_BLUE.getIndex()); style.setFillPattern(FillPatternType.SOLID_FOREGROUND); style.setBorderLeft(BorderStyle.THIN); style.setLeftBorderColor(borderColor); style.setBorderBottom(BorderStyle.THIN); style.setBottomBorderColor(borderColor); style.setFont(dayFont); styles.put("weekend_left", style); style = wb.createCellStyle(); style.setAlignment(HorizontalAlignment.CENTER); style.setVerticalAlignment(VerticalAlignment.TOP); style.setFillForegroundColor(IndexedColors.LIGHT_CORNFLOWER_BLUE.getIndex()); style.setFillPattern(FillPatternType.SOLID_FOREGROUND); style.setBorderRight(BorderStyle.THIN); style.setRightBorderColor(borderColor); style.setBorderBottom(BorderStyle.THIN); style.setBottomBorderColor(borderColor); styles.put("weekend_right", style); style = wb.createCellStyle(); style.setAlignment(HorizontalAlignment.LEFT); style.setVerticalAlignment(VerticalAlignment.TOP); style.setBorderLeft(BorderStyle.THIN); style.setFillForegroundColor(IndexedColors.WHITE.getIndex()); style.setFillPattern(FillPatternType.SOLID_FOREGROUND); style.setLeftBorderColor(borderColor); style.setBorderBottom(BorderStyle.THIN); style.setBottomBorderColor(borderColor); style.setFont(dayFont); styles.put("workday_left", style); style = wb.createCellStyle(); style.setAlignment(HorizontalAlignment.CENTER); style.setVerticalAlignment(VerticalAlignment.TOP); style.setFillForegroundColor(IndexedColors.WHITE.getIndex()); style.setFillPattern(FillPatternType.SOLID_FOREGROUND); style.setBorderRight(BorderStyle.THIN); style.setRightBorderColor(borderColor); style.setBorderBottom(BorderStyle.THIN); style.setBottomBorderColor(borderColor); styles.put("workday_right", style); style = wb.createCellStyle(); style.setBorderLeft(BorderStyle.THIN); style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); style.setFillPattern(FillPatternType.SOLID_FOREGROUND); style.setBorderBottom(BorderStyle.THIN); style.setBottomBorderColor(borderColor); styles.put("grey_left", style); style = wb.createCellStyle(); style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); style.setFillPattern(FillPatternType.SOLID_FOREGROUND); style.setBorderRight(BorderStyle.THIN); style.setRightBorderColor(borderColor); style.setBorderBottom(BorderStyle.THIN); style.setBottomBorderColor(borderColor); styles.put("grey_right", style); return styles; }
From source file:com.nc.common.utils.ExcelUtil.java
License:Open Source License
/** * <pre>/* w w w . ja v a 2s.co m*/ * 1. : POI UTIL * 2. : POI WORKBOOK ? / String , List<Map<String, Object>> ? , List<Map<String, Object>> * </pre> * * @method Name : createWorkBook * @param workbook, sheetName, list, colNames * @return Workbook * @throws Exception * */ @SuppressWarnings("deprecation") public static Workbook createWorkBook(Workbook workbook, String sheetName, List<Map<String, Object>> list, List<Map<String, Object>> colNames) throws Exception { Row row; Cell cell; /* ? ? START */ /* Workbook workbook = new Workbook(); */ CellStyle titleStyle = workbook.createCellStyle(); CellStyle cellStyle = workbook.createCellStyle(); CellStyle contentStyle = workbook.createCellStyle(); CellStyle contentStyle_2 = workbook.createCellStyle(); /* ? */ /* ? ? */ Font titleFont = workbook.createFont(); titleFont.setFontHeightInPoints((short) 13); titleFont.setFontName("? "); /* ? */ Font colNameFont = workbook.createFont(); colNameFont.setFontHeightInPoints((short) 10); colNameFont.setFontName("? "); /* ? */ Font contentFont = workbook.createFont(); /* ? ? ? */ titleStyle.setFont(titleFont); /* ? / ? ? */ cellStyle.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index); /* ? */ cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);//? cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); cellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN); cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); cellStyle.setFont(colNameFont); /* ? / ? */ contentStyle.setBorderRight(HSSFCellStyle.BORDER_THIN); /* ? */ contentStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); contentStyle.setBorderTop(HSSFCellStyle.BORDER_THIN); contentStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); contentStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); contentStyle.setFont(contentFont); /* ? / ? */ contentStyle_2.setBorderRight(HSSFCellStyle.BORDER_THIN); /* ? */ contentStyle_2.setBorderLeft(HSSFCellStyle.BORDER_THIN); contentStyle_2.setBorderTop(HSSFCellStyle.BORDER_THIN); contentStyle_2.setBorderBottom(HSSFCellStyle.BORDER_THIN); contentStyle_2.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); contentStyle_2.setAlignment(HSSFCellStyle.ALIGN_LEFT); contentStyle_2.setFont(contentFont); /* ? */ Sheet sheet = workbook.createSheet(sheetName); /* ?? */ int sheet1_row = 0; List<Map<String, Object>> colList = colNames; /* ? START */ row = sheet.createRow(sheet1_row); for (int i = 0; i < colList.size(); i++) { cell = row.createCell(i); cell.setCellValue(String.valueOf(colList.get(i).get("item" + i))); cell.setCellStyle(cellStyle); } sheet1_row++; /* ? END */ for (Map<String, Object> map : list) { row = sheet.createRow(sheet1_row); for (int j = 0; j < colList.size(); j++) { cell = row.createCell(j); cell.setCellStyle(contentStyle); if (null != map.get(colList.get(j).get("item" + j))) { cell.setCellValue((double) map.get(String.valueOf(colList.get(j).get("item" + j)))); } else { cell.setCellValue(""); } /* ? ?? */ sheet.autoSizeColumn((short) j); sheet.setColumnWidth(j, (sheet.getColumnWidth(j)) + 312); } sheet1_row++; } return workbook; }
From source file:com.ncc.excel.test.ExcelUtil.java
License:Apache License
/** * ????? //from www. ja v a2 s.c o m * * @param fromStyle * @param toStyle */ public static void copyCellStyle(CellStyle fromStyle, CellStyle toStyle) { toStyle.setAlignment(fromStyle.getAlignment()); // toStyle.setBorderBottom(fromStyle.getBorderBottom()); toStyle.setBorderLeft(fromStyle.getBorderLeft()); toStyle.setBorderRight(fromStyle.getBorderRight()); toStyle.setBorderTop(fromStyle.getBorderTop()); toStyle.setTopBorderColor(fromStyle.getTopBorderColor()); toStyle.setBottomBorderColor(fromStyle.getBottomBorderColor()); toStyle.setRightBorderColor(fromStyle.getRightBorderColor()); toStyle.setLeftBorderColor(fromStyle.getLeftBorderColor()); // ? toStyle.setFillBackgroundColor(fromStyle.getFillBackgroundColor()); toStyle.setFillForegroundColor(fromStyle.getFillForegroundColor()); // ?? toStyle.setDataFormat(fromStyle.getDataFormat()); toStyle.setFillPattern(fromStyle.getFillPattern()); // toStyle.setFont(fromStyle.getFont(null)); toStyle.setHidden(fromStyle.getHidden()); toStyle.setIndention(fromStyle.getIndention());// toStyle.setLocked(fromStyle.getLocked()); toStyle.setRotation(fromStyle.getRotation());// toStyle.setVerticalAlignment(fromStyle.getVerticalAlignment()); toStyle.setWrapText(fromStyle.getWrapText()); }
From source file:com.netxforge.netxstudio.server.logic.reporting.RFSServiceDashboardReportingLogic.java
License:Open Source License
/** * Write each Node per NodeType column, starting *///from w w w . j av a 2 s. c o m @Override protected void writeContent(Sheet sheet, Service service, Node node, int row, int column) { // Write the NODE.ID box. int newRow = NODE_ROW + (row * NODE_HEIGHT); int nodeColumn = NODE_COLUMN + (column * NODE_WIDTH); sheet.setColumnWidth(nodeColumn, 10 * 256); CellStyle nodeStyle = this.getWorkBook().createCellStyle(); nodeStyle.setBorderTop(CellStyle.BORDER_MEDIUM); nodeStyle.setBorderBottom(CellStyle.BORDER_MEDIUM); nodeStyle.setBorderLeft(CellStyle.BORDER_MEDIUM); nodeStyle.setBorderRight(CellStyle.BORDER_MEDIUM); nodeStyle.setAlignment(CellStyle.ALIGN_CENTER); nodeStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER); { Row cellRow = sheet.getRow(newRow); if (cellRow == null) { cellRow = sheet.createRow(newRow); } Cell c1 = cellRow.createCell(nodeColumn); c1.setCellValue(node.getNodeID()); c1.setCellStyle(nodeStyle); } { Row cellRow = sheet.getRow(newRow + 1); if (cellRow == null) { cellRow = sheet.createRow(newRow + 1); } Cell c1 = cellRow.createCell(nodeColumn); c1.setCellStyle(nodeStyle); } { Row cellRow = sheet.getRow(newRow + 2); if (cellRow == null) { cellRow = sheet.createRow(newRow + 2); } Cell c1 = cellRow.createCell(nodeColumn); c1.setCellStyle(nodeStyle); } sheet.addMergedRegion(new CellRangeAddress(newRow, newRow + NODE_HEIGHT - 2, nodeColumn, nodeColumn)); // In between column. sheet.setColumnWidth(nodeColumn + 1, 2 * 256); // Write the RAG CellStyle ragStyle = this.getWorkBook().createCellStyle(); ragStyle.setBorderTop(CellStyle.BORDER_THIN); ragStyle.setBorderBottom(CellStyle.BORDER_THIN); ragStyle.setBorderLeft(CellStyle.BORDER_THIN); ragStyle.setBorderRight(CellStyle.BORDER_THIN); ragStyle.setAlignment(CellStyle.ALIGN_CENTER); ragStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER); ragStyle.setFillPattern(CellStyle.SOLID_FOREGROUND); int ragColumn = nodeColumn + 2; sheet.setColumnWidth(ragColumn, 2 * 256); IMonitoringSummary summary = monStateModel.summary(new NullProgressMonitor(), node, new IComputationContext[] { new ObjectContext<Service>(service), new ObjectContext<DateTimeRange>(getPeriod()) }); if (summary == null) { return; } int[] rag = summary.rag(); { Row cellRow = sheet.getRow(newRow); if (cellRow == null) { cellRow = sheet.createRow(newRow); } Cell c1 = cellRow.createCell(ragColumn); c1.setCellValue("R"); CellStyle rStyle = this.getWorkBook().createCellStyle(); rStyle.cloneStyleFrom(ragStyle); rStyle.setFillForegroundColor(IndexedColors.RED.getIndex()); c1.setCellStyle(rStyle); if (rag != null) { c1.setCellValue(rag[0]); } } { Row cellRow = sheet.getRow(newRow + 1); if (cellRow == null) { cellRow = sheet.createRow(newRow + 1); } Cell c1 = cellRow.createCell(ragColumn); c1.setCellValue("A"); CellStyle aStyle = this.getWorkBook().createCellStyle(); aStyle.cloneStyleFrom(ragStyle); aStyle.setFillForegroundColor(IndexedColors.ORANGE.getIndex()); c1.setCellStyle(aStyle); if (rag != null) { c1.setCellValue(rag[1]); } } { Row cellRow = sheet.getRow(newRow + 2); if (cellRow == null) { cellRow = sheet.createRow(newRow + 2); } Cell c1 = cellRow.createCell(ragColumn); c1.setCellValue("G"); CellStyle gStyle = this.getWorkBook().createCellStyle(); gStyle.cloneStyleFrom(ragStyle); gStyle.setFillForegroundColor(IndexedColors.GREEN.getIndex()); c1.setCellStyle(gStyle); if (rag != null) { c1.setCellValue(rag[2]); } } // Clean our adapted summary. node.eAdapters().remove(summary); }
From source file:com.netxforge.netxstudio.server.logic.reporting.RFSServiceSummaryReportingLogic.java
License:Open Source License
private void writeSummary(Sheet sheet) { // Title// w w w. j ava 2s . c o m Row summaryRow = sheet.createRow(CONTENT_ROW); Cell summaryCell = summaryRow.createCell(2); summaryCell.setCellValue("Executive Summary"); sheet.addMergedRegion(new CellRangeAddress(CONTENT_ROW, CONTENT_ROW, 2, 4)); // Table CellStyle borderStyle = this.getWorkBook().createCellStyle(); borderStyle.setBorderTop(CellStyle.BORDER_THIN); borderStyle.setBorderBottom(CellStyle.BORDER_THIN); borderStyle.setBorderLeft(CellStyle.BORDER_THIN); borderStyle.setBorderRight(CellStyle.BORDER_THIN); borderStyle.setAlignment(CellStyle.ALIGN_CENTER); borderStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER); Row headerRow = sheet.createRow(HEADER_ROW); { Cell c1 = headerRow.createCell(4); c1.setCellValue("Quantity"); c1.setCellStyle(borderStyle); } { Cell c1 = headerRow.createCell(5); c1.setCellValue("RED"); c1.setCellStyle(borderStyle); } { Cell c1 = headerRow.createCell(6); c1.setCellValue("AMBER"); c1.setCellStyle(borderStyle); } { Cell c1 = headerRow.createCell(7); c1.setCellValue("GREEN"); c1.setCellStyle(borderStyle); } writeServicesSummary(sheet, borderStyle); writeNodesSummary(sheet, borderStyle); writeResourcesSummary(sheet, borderStyle); }
From source file:com.sccl.attech.common.utils.excel.ExportExcel.java
License:Open Source License
/** * ?// w ww. j a v a 2 s . c o m * @param row * @param column ? * @param val * @param align ??1?23?? * @return ? */ public Cell addCellStyle(Row row, int column, Object val, int align, Class<?> fieldType) { Cell cell = row.createCell(column); CellStyle style = styles.get("data" + (align >= 1 && align <= 3 ? align : "")); style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); style.setAlignment(HSSFCellStyle.ALIGN_LEFT); style.setWrapText(true); try { if (val == null) { cell.setCellValue(""); } else if (val instanceof String) { cell.setCellValue((String) val); } else if (val instanceof Integer) { cell.setCellValue((Integer) val); } else if (val instanceof Long) { cell.setCellValue((Long) val); } else if (val instanceof Double) { cell.setCellValue((Double) val); } else if (val instanceof Float) { cell.setCellValue((Float) val); } else if (val instanceof Date) { DataFormat format = wb.createDataFormat(); style.setDataFormat(format.getFormat("yyyy-MM-dd")); cell.setCellValue((Date) val); } else { if (fieldType != Class.class) { cell.setCellValue((String) fieldType.getMethod("setValue", Object.class).invoke(null, val)); } else { cell.setCellValue((String) Class .forName(this.getClass().getName().replaceAll(this.getClass().getSimpleName(), "fieldtype." + val.getClass().getSimpleName() + "Type")) .getMethod("setValue", Object.class).invoke(null, val)); } } } catch (Exception ex) { log.info("Set cell value [" + row.getRowNum() + "," + column + "] error: " + ex.toString()); cell.setCellValue(val.toString()); } if (column == 8) { CellRangeAddressList regions = new CellRangeAddressList(25, 25, 8, 8); // ? DVConstraint constraint = DVConstraint .createExplicitListConstraint(new String[] { "2", "3", "" }); // HSSFDataValidation data_validation = new HSSFDataValidation(regions, constraint); // sheet data_validation.createErrorBox("Error", "Error"); data_validation.createPromptBox("", null); sheet.addValidationData(data_validation); } cell.setCellStyle(style); return cell; }
From source file:com.shiyq.poi.HSSFTest.java
public static boolean createExcel(String excelName) { boolean created = false; Workbook wb = new HSSFWorkbook(); Font font = wb.createFont();//from ww w .j a v a2s . c o m font.setBold(true); CellStyle headStyle = wb.createCellStyle(); headStyle.setFont(font); Sheet sheet = wb.createSheet("20165???"); String[] head = { "??", "?", "??", "???", "????", "????", "?", "??", "", "", "??" }; String[] code = { "card_no", "card_type", "spread_time", "spread_emp_no", "spread_emp_name", "owner_name", "plate", "blance", "start_time", "end_time", "month_money" }; List<Map<String, Object>> list = setList(); setSheet(sheet, list, head, headStyle, code); // int startRow = 4; int endRow = 8; int startColumn = head.length + 4; int endColumn = head.length + 8; String describe = "1?" + (new Date().toString()) + "\n"; describe += "2.\n"; describe += "3.?2016-4-42016-5-4"; CellStyle descStyle = wb.createCellStyle(); descStyle.setAlignment(CellStyle.ALIGN_LEFT); descStyle.setVerticalAlignment(CellStyle.VERTICAL_TOP); setSheet(sheet, startRow, endRow, startColumn, endColumn, describe, descStyle); Sheet sheet1 = wb.createSheet("20166???"); setSheet(sheet1, list, head, headStyle, code); setSheet(sheet1, startRow, endRow, startColumn, endColumn, describe, descStyle); try { try (FileOutputStream fileOut = new FileOutputStream(excelName)) { wb.write(fileOut); created = true; } } catch (FileNotFoundException ex) { Logger.getLogger(HSSFTest.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(HSSFTest.class.getName()).log(Level.SEVERE, null, ex); } return created; }
From source file:com.skt.adcas.lte.action.DownLinkByNMSAction.java
private static void createCell(Workbook wb, Row row, short column, String value, short halign) { Cell cell = row.createCell(column);//from w ww. j a v a 2 s.c o m cell.setCellValue(value); CellStyle cellStyle = wb.createCellStyle(); cellStyle.setAlignment(halign); cellStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER); cell.setCellStyle(cellStyle); }
From source file:com.skt.adcas.lte.action.DownLinkByNMSAction.java
private static void createCell(Workbook wb, Row row, short column, double value, short halign) { Cell cell = row.createCell(column);//from www . j a va 2 s . com cell.setCellValue(value); CellStyle cellStyle = wb.createCellStyle(); cellStyle.setAlignment(halign); cellStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER); cell.setCellStyle(cellStyle); }
From source file:com.skt.adcas.lte.action.DownLinkByNMSAction.java
private static void createCell(Workbook wb, Row row, short column, short halign, short valign, String text) { Cell cell = row.createCell(column);/* w w w .j av a2 s . com*/ cell.setCellValue(text); CellStyle cellStyle = wb.createCellStyle(); cellStyle.setAlignment(halign); cellStyle.setVerticalAlignment(valign); cell.setCellStyle(cellStyle); }