List of usage examples for org.apache.poi.xssf.usermodel XSSFCellStyle setAlignment
@Override public void setAlignment(HorizontalAlignment align)
From source file:com.philips.his.pixiu.cdr.poi.BigGridDemo.java
License:Apache License
/** * Create a library of cell styles.//from w w w. j ava 2 s. c om */ private static Map<String, XSSFCellStyle> createStyles(XSSFWorkbook wb) { Map<String, XSSFCellStyle> styles = new HashMap<String, XSSFCellStyle>(); XSSFDataFormat fmt = wb.createDataFormat(); XSSFCellStyle style1 = wb.createCellStyle(); style1.setAlignment(HorizontalAlignment.RIGHT); style1.setDataFormat(fmt.getFormat("0.0%")); styles.put("percent", style1); XSSFCellStyle style2 = wb.createCellStyle(); style2.setAlignment(HorizontalAlignment.CENTER); style2.setDataFormat(fmt.getFormat("0.0X")); styles.put("coeff", style2); XSSFCellStyle style3 = wb.createCellStyle(); style3.setAlignment(HorizontalAlignment.RIGHT); style3.setDataFormat(fmt.getFormat("$#,##0.00")); styles.put("currency", style3); XSSFCellStyle style4 = wb.createCellStyle(); style4.setAlignment(HorizontalAlignment.RIGHT); style4.setDataFormat(fmt.getFormat("mmm dd")); styles.put("date", style4); XSSFCellStyle style5 = wb.createCellStyle(); XSSFFont headerFont = wb.createFont(); headerFont.setBold(true); style5.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); style5.setFillPattern(FillPatternType.SOLID_FOREGROUND); style5.setFont(headerFont); styles.put("header", style5); return styles; }
From source file:com.rdg.export.util.ExportXLS.java
License:Apache License
/** * create cell style for header names// w w w . ja v a2 s. co m * * @return */ private static XSSFCellStyle getCellStyleHeader() { XSSFCellStyle cellStyle = workbook.createCellStyle(); CreationHelper createHelper = workbook.getCreationHelper(); Font headerFont = workbook.createFont(); headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD); cellStyle.setDataFormat(createHelper.createDataFormat().getFormat(DateUtil.sDateFormat_1)); cellStyle.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM); cellStyle.setBorderTop(HSSFCellStyle.BORDER_MEDIUM); cellStyle.setBorderRight(HSSFCellStyle.BORDER_MEDIUM); cellStyle.setBorderLeft(HSSFCellStyle.BORDER_MEDIUM); cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); cellStyle.setFont(headerFont); return cellStyle; }
From source file:com.sec.ose.osi.report.standard.CoverSheetTemplate.java
License:Open Source License
protected void createTitle() { short lineThickness = (short) (6 * BASE_HEIGHT); // Top Line// w w w . ja v a 2 s .co m Row row = sheet.createRow(ROW_4); row.setHeight(lineThickness); XSSFCellStyle style = wb.createCellStyle(); style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); setDummyTitleStyle(row, style); // Title row = sheet.createRow(ROW_5); row.setHeightInPoints(100); sheet.addMergedRegion(CellRangeAddress.valueOf("B5:G5")); Font font = wb.createFont(); font.setFontHeightInPoints((short) 28); font.setFontName("Trebuchet MS"); font.setBoldweight(Font.BOLDWEIGHT_BOLD); style = wb.createCellStyle(); style.setFont(font); style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); setDummyTitleStyle(row, style); row.getCell(COL_B).setCellValue("Open Source License Verification Report"); // Bottom Line row = sheet.createRow(ROW_6); row.setHeight(lineThickness); style = wb.createCellStyle(); style.setFillForegroundColor(DARK_BLUE); style.setFillPattern(CellStyle.SOLID_FOREGROUND); setDummyTitleStyle(row, style); }
From source file:com.sec.ose.osi.report.standard.CoverSheetTemplate.java
License:Open Source License
protected XSSFCellStyle getCellStyle(int border, Font font) { XSSFCellStyle style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setWrapText(true); // new line style.setBottomBorderColor(IndexedColors.BLACK.getIndex()); style.setLeftBorderColor(IndexedColors.BLACK.getIndex()); style.setRightBorderColor(IndexedColors.BLACK.getIndex()); style.setTopBorderColor(IndexedColors.BLACK.getIndex()); if ((border & BORDER_BOTTOM) > 0) style.setBorderBottom(CellStyle.BORDER_DOUBLE); else//from w ww . j a v a2s. c om style.setBorderBottom(CellStyle.BORDER_THIN); if ((border & BORDER_LEFT) > 0) style.setBorderLeft(CellStyle.BORDER_DOUBLE); else style.setBorderLeft(CellStyle.BORDER_THIN); if ((border & BORDER_RIGHT) > 0) style.setBorderRight(CellStyle.BORDER_DOUBLE); else style.setBorderRight(CellStyle.BORDER_THIN); if ((border & BORDER_TOP) > 0) style.setBorderTop(CellStyle.BORDER_DOUBLE); else style.setBorderTop(CellStyle.BORDER_THIN); if (font != null) style.setFont(font); return style; }
From source file:com.sec.ose.osi.report.standard.ISheetTemplate.java
License:Open Source License
/** * @param color//from ww w. j a v a 2s. c o m * @param font * @return CellStyle */ protected XSSFCellStyle getCellStyle(XSSFColor color, Font font) { XSSFCellStyle style = wb.createCellStyle(); style.setFillForegroundColor(color); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setWrapText(true); // new line style.setBorderBottom(CellStyle.BORDER_THIN); style.setBottomBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderLeft(CellStyle.BORDER_THIN); style.setLeftBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderRight(CellStyle.BORDER_THIN); style.setRightBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderTop(CellStyle.BORDER_THIN); style.setTopBorderColor(IndexedColors.BLACK.getIndex()); if (font != null) style.setFont(font); return style; }
From source file:com.tikal.tallerWeb.servicio.reporte.cliente.AbstractSeccionXLS.java
License:Apache License
public void addHeaderStyle(XSSFCellStyle cellStyle, XSSFWorkbook wb) { cellStyle.setAlignment(CellStyle.ALIGN_CENTER); // cellStyle.setFillForegroundColor(new XSSFColor(new Color(85, 142, 213))); cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND); XSSFFont font = wb.createFont();//from w w w. ja v a 2 s .co m font.setColor(IndexedColors.WHITE.getIndex()); font.setBold(true); cellStyle.setFont(font); }
From source file:com.yyl.common.utils.excel.ExcelTools.java
/** * ?xlsxExcel//from w w w. ja v a 2 s . co m * @param heads * @param data ? * @param sheetName Excel? * @param out ? * @return ByteArrayOutputStream * @throws IOException */ public static void writeToXLSX(ExcelRow heads, ExcelData data, String sheetName, ByteArrayOutputStream out) throws IOException { XSSFWorkbook wb = new XSSFWorkbook(); XSSFSheet sheet1 = wb.createSheet(sheetName); XSSFRow row = sheet1.createRow(0); XSSFCellStyle style = wb.createCellStyle(); style.setAlignment(HSSFCellStyle.ALIGN_CENTER); XSSFCell cell; for (int i = 0; i < heads.size(); i++) { cell = row.createCell(i); cell.setCellValue(heads.get(i)); cell.setCellStyle(style); } if (data != null && data.size() != 0) { for (int n = 0; n < data.size(); n++) { row = sheet1.createRow(n + 1); ExcelRow datarow = data.get(n); for (int m = 0; m < datarow.size(); m++) { cell = row.createCell(m); cell.setCellValue(datarow.get(m)); cell.setCellStyle(style); } } } wb.write(out); }
From source file:das.pf.io.IOExcel.java
License:Open Source License
private XSSFCellStyle getXSSFCellStyleValues(Workbook worbook, TypeValues typeValue, TypeUnits typeUnit) { XSSFCellStyle style = (XSSFCellStyle) worbook.createCellStyle(); XSSFFont font = (XSSFFont) worbook.createFont(); font.setBold(true);/* ww w . j ava 2 s . co m*/ font.setColor(new XSSFColor(Color.WHITE)); style.setAlignment(HorizontalAlignment.CENTER); switch (typeValue) { case VALUES: switch (typeUnit) { case MTH: style.setFillForegroundColor(new XSSFColor(Color.BLUE.darker())); break; case QRT: style.setFillForegroundColor(new XSSFColor(Color.BLUE.darker().darker())); break; case YTD: style.setFillForegroundColor(new XSSFColor(Color.BLUE)); break; case MAT: style.setFillForegroundColor(new XSSFColor(Color.CYAN)); break; } break; case UNITS: switch (typeUnit) { case MTH: style.setFillForegroundColor(new XSSFColor(Color.RED.darker())); break; case QRT: style.setFillForegroundColor(new XSSFColor(Color.RED.darker().darker())); break; case YTD: style.setFillForegroundColor(new XSSFColor(Color.ORANGE)); break; case MAT: style.setFillForegroundColor(new XSSFColor(Color.YELLOW)); break; } break; case U_E: switch (typeUnit) { case MTH: style.setFillForegroundColor(new XSSFColor(Color.GRAY.darker())); break; case QRT: style.setFillForegroundColor(new XSSFColor(Color.GREEN.darker().darker())); break; case YTD: style.setFillForegroundColor(new XSSFColor(Color.GRAY)); break; case MAT: style.setFillForegroundColor(new XSSFColor(Color.LIGHT_GRAY)); break; } break; } style.setFillPattern(FillPatternType.SOLID_FOREGROUND); style.setFont(font); return style; }
From source file:das.pf.io.IOExcel.java
License:Open Source License
private XSSFCellStyle getXSSFCellStyleHeaderData(Workbook workbook) { XSSFCellStyle style = (XSSFCellStyle) workbook.createCellStyle(); XSSFFont font = (XSSFFont) workbook.createFont(); font.setBold(true);/* w w w .j a va 2 s . co m*/ font.setColor(new XSSFColor(Color.WHITE)); style.setAlignment(HorizontalAlignment.CENTER); style.setFillForegroundColor(new XSSFColor(Color.GRAY)); style.setFillPattern(FillPatternType.SOLID_FOREGROUND); style.setFont(font); return style; }
From source file:document.ExcelDocumentStyles.java
private void styleAligment(XSSFCellStyle style, short s) { style.setAlignment(s); }