List of usage examples for org.apache.poi.xssf.usermodel XSSFCellStyle setAlignment
@Override public void setAlignment(HorizontalAlignment align)
From source file:br.ufpa.psi.comportamente.labgame.relatorios.RelatorioJogadasExperimento.java
License:Open Source License
public static CellStyle retornaEstilo(String cor, Workbook wb, XSSFFont fb, XSSFFont fn) { XSSFCellStyle estilo = (XSSFCellStyle) wb.createCellStyle(); estilo.setVerticalAlignment(VerticalAlignment.CENTER); estilo.setAlignment(CellStyle.ALIGN_CENTER); estilo.setFillPattern(CellStyle.SOLID_FOREGROUND); estilo.setBorderBottom(BorderStyle.MEDIUM); estilo.setBorderTop(BorderStyle.MEDIUM); estilo.setFont(fb);//from w ww .j a v a2 s .co m estilo.getFont().setBold(true); switch (cor) { case "verde": estilo.setFillForegroundColor(new XSSFColor(new java.awt.Color(31, 131, 101))); return estilo; case "azul": estilo.setFillForegroundColor(new XSSFColor(Color.BLUE)); return estilo; case "vermelho": estilo.setFillForegroundColor(new XSSFColor(Color.RED)); return estilo; case "amarelo": estilo.setFillForegroundColor(new XSSFColor(Color.YELLOW)); estilo.setFont(fn); return estilo; case "roxo": estilo.setFillForegroundColor(new XSSFColor(new java.awt.Color(128, 0, 128))); return estilo; default: return estilo; } }
From source file:com.accounting.accountMBean.DifferentAccReports.java
public void simplePostProcessXLSX(Object document) { String startDateString = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap() .get("nepaliDate4"); String endDateString = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap() .get("nepaliDate5"); XSSFWorkbook wb = (XSSFWorkbook) document; XSSFCellStyle headerCellStyle = wb.createCellStyle(); XSSFCellStyle headerCellStyle1 = wb.createCellStyle(); XSSFCellStyle headerCellStyle2 = wb.createCellStyle(); Font headerFont = wb.createFont(); headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD); headerFont.setFontName(HSSFFont.FONT_ARIAL); headerCellStyle.setFont(headerFont); headerCellStyle.setAlignment(CellStyle.ALIGN_CENTER); Font headerFont1 = wb.createFont(); headerFont1.setBoldweight(Font.U_SINGLE_ACCOUNTING); headerFont1.setFontName(HSSFFont.FONT_ARIAL); headerCellStyle1.setFont(headerFont); headerCellStyle1.setAlignment(CellStyle.ALIGN_RIGHT); Font headerFont3 = wb.createFont(); headerFont3.setBoldweight(Font.U_SINGLE); headerFont3.setFontName(HSSFFont.FONT_ARIAL); headerCellStyle2.setFont(headerFont1); headerCellStyle2.setAlignment(CellStyle.ALIGN_RIGHT); XSSFSheet sheet = wb.getSheetAt(0);/*from ww w. j av a 2 s . c om*/ int noOfColumns = sheet.getRow(2).getLastCellNum(); for (int i = 0; i < noOfColumns; i++) { sheet.autoSizeColumn(i); } sheet.shiftRows(0, sheet.getLastRowNum(), 4); XSSFRow firstRow = sheet.createRow(1); firstRow.createCell(0).setCellValue("SALES AGEING REPORT"); firstRow.getCell(0).setCellStyle(headerCellStyle); XSSFRow secondRow = sheet.createRow(0); secondRow.createCell(0).setCellValue(getLoggedInOffice().getName()); secondRow.getCell(0).setCellStyle(headerCellStyle); // XSSFRow thirdRow = sheet.createRow(3); String date = ndc.convertToNepaliDate(new Date()); SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss a"); String time = sdf.format(new Date()); thirdRow.createCell(0) .setCellValue("Generated on:" + date + " " + time + " by:" + getLoggedInUser().getName()); thirdRow.getCell(0).setCellStyle(headerCellStyle2); XSSFRow fourthRow = sheet.createRow(2); fourthRow.createCell(0).setCellValue("FROM: " + startDateString + " TO: " + endDateString); fourthRow.getCell(0).setCellStyle(headerCellStyle); sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 7)); sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 7)); sheet.addMergedRegion(new CellRangeAddress(2, 2, 0, 7)); sheet.addMergedRegion(new CellRangeAddress(3, 3, 0, 7)); }
From source file:com.accounting.reportMBean.ReportCommonBean.java
public void simplePostProcessXLSXOfStock(Object document) { String startDateString = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap() .get("nepaliDate4"); String endDateString = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap() .get("nepaliDate1"); XSSFWorkbook wb = (XSSFWorkbook) document; XSSFCellStyle headerCellStyle = wb.createCellStyle(); XSSFCellStyle headerCellStyle1 = wb.createCellStyle(); XSSFCellStyle headerCellStyle2 = wb.createCellStyle(); Font headerFont = wb.createFont(); headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD); headerFont.setFontName(HSSFFont.FONT_ARIAL); headerCellStyle.setFont(headerFont); headerCellStyle.setAlignment(CellStyle.ALIGN_CENTER); Font headerFont1 = wb.createFont(); headerFont1.setBoldweight(Font.U_SINGLE_ACCOUNTING); headerFont1.setFontName(HSSFFont.FONT_ARIAL); headerCellStyle1.setFont(headerFont); headerCellStyle1.setAlignment(CellStyle.ALIGN_RIGHT); Font headerFont3 = wb.createFont(); headerFont3.setBoldweight(Font.U_SINGLE); headerFont3.setFontName(HSSFFont.FONT_ARIAL); headerCellStyle2.setFont(headerFont1); headerCellStyle2.setAlignment(CellStyle.ALIGN_RIGHT); XSSFSheet sheet = wb.getSheetAt(0);/* w w w . j a v a2s .c om*/ int noOfColumns = sheet.getRow(2).getLastCellNum(); for (int i = 0; i < noOfColumns; i++) { sheet.autoSizeColumn(i); } sheet.shiftRows(0, sheet.getLastRowNum(), 4); XSSFRow firstRow = sheet.createRow(1); firstRow.createCell(0).setCellValue("STOCK VALUE WITH VALUES"); firstRow.getCell(0).setCellStyle(headerCellStyle); XSSFRow secondRow = sheet.createRow(0); secondRow.createCell(0).setCellValue(getLoggedInOffice().getName()); secondRow.getCell(0).setCellStyle(headerCellStyle); // XSSFRow thirdRow = sheet.createRow(3); String date = ndc.convertToNepaliDate(new Date()); SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss a"); String time = sdf.format(new Date()); thirdRow.createCell(0) .setCellValue("Generated on:" + date + " " + time + " by:" + getLoggedInUser().getName()); thirdRow.getCell(0).setCellStyle(headerCellStyle2); XSSFRow fourthRow = sheet.createRow(2); fourthRow.createCell(0).setCellValue("FROM: " + startDateString + " TO: " + endDateString); fourthRow.getCell(0).setCellStyle(headerCellStyle); sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 7)); sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 7)); sheet.addMergedRegion(new CellRangeAddress(2, 2, 0, 7)); sheet.addMergedRegion(new CellRangeAddress(3, 3, 0, 7)); }
From source file:com.accounting.reportMBean.ReportCommonBean.java
public void simplePostProcessXLSX(Object document) { String startDateString = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap() .get("nepaliDate4"); String endDateString = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap() .get("nepaliDate1"); XSSFWorkbook wb = (XSSFWorkbook) document; XSSFCellStyle headerCellStyle = wb.createCellStyle(); XSSFCellStyle headerCellStyle1 = wb.createCellStyle(); XSSFCellStyle headerCellStyle2 = wb.createCellStyle(); Font headerFont = wb.createFont(); headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD); headerFont.setFontName(HSSFFont.FONT_ARIAL); headerCellStyle.setFont(headerFont); headerCellStyle.setAlignment(CellStyle.ALIGN_CENTER); Font headerFont1 = wb.createFont(); headerFont1.setBoldweight(Font.U_SINGLE_ACCOUNTING); headerFont1.setFontName(HSSFFont.FONT_ARIAL); headerCellStyle1.setFont(headerFont); headerCellStyle1.setAlignment(CellStyle.ALIGN_RIGHT); Font headerFont3 = wb.createFont(); headerFont3.setBoldweight(Font.U_SINGLE); headerFont3.setFontName(HSSFFont.FONT_ARIAL); headerCellStyle2.setFont(headerFont1); headerCellStyle2.setAlignment(CellStyle.ALIGN_RIGHT); XSSFSheet sheet = wb.getSheetAt(0);/*from w w w. ja va 2s . c o m*/ int noOfColumns = sheet.getRow(2).getLastCellNum(); for (int i = 0; i < noOfColumns; i++) { sheet.autoSizeColumn(i); } sheet.shiftRows(0, sheet.getLastRowNum(), 4); XSSFRow firstRow = sheet.createRow(1); firstRow.createCell(0).setCellValue(pageName); firstRow.getCell(0).setCellStyle(headerCellStyle); XSSFRow secondRow = sheet.createRow(0); secondRow.createCell(0).setCellValue(getLoggedInOffice().getName()); secondRow.getCell(0).setCellStyle(headerCellStyle); // XSSFRow thirdRow = sheet.createRow(3); String date = ndc.convertToNepaliDate(new Date()); SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss a"); String time = sdf.format(new Date()); thirdRow.createCell(0) .setCellValue("Generated on:" + date + " " + time + " by:" + getLoggedInUser().getName()); thirdRow.getCell(0).setCellStyle(headerCellStyle2); XSSFRow fourthRow = sheet.createRow(2); fourthRow.createCell(0).setCellValue("FROM: " + startDateString + " TO: " + endDateString); fourthRow.getCell(0).setCellStyle(headerCellStyle); sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 7)); sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 7)); sheet.addMergedRegion(new CellRangeAddress(2, 2, 0, 7)); sheet.addMergedRegion(new CellRangeAddress(3, 3, 0, 7)); }
From source file:com.cms.utils.CommonUtils.java
public static XSSFCellStyle styleCell(XSSFWorkbook workbook) { XSSFCellStyle cellStyle = workbook.createCellStyle(); cellStyle.setAlignment(XSSFCellStyle.ALIGN_CENTER); cellStyle.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER); cellStyle.setBorderLeft(XSSFCellStyle.BORDER_THIN); cellStyle.setBorderBottom(XSSFCellStyle.BORDER_THIN); cellStyle.setBorderRight(XSSFCellStyle.BORDER_THIN); cellStyle.setBorderTop(XSSFCellStyle.BORDER_THIN); cellStyle.setFillForegroundColor(HSSFColor.LIGHT_GREEN.index); cellStyle.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND); cellStyle.setWrapText(false);// w w w . j a v a 2 s .c o m return cellStyle; }
From source file:com.frameworkset.platform.sanylog.common.POIExcelUtil2007.java
License:Open Source License
private static XSSFCellStyle getHeadCellStyle(XSSFWorkbook wb, XSSFFont font) {// XSSFCellStyle headCellStyle = wb.createCellStyle(); headCellStyle.setFont(font);/* ww w . j a v a 2s . co m*/ headCellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); headCellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); headCellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN); headCellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN); headCellStyle.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index); headCellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); headCellStyle.setWrapText(false); headCellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); headCellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); return headCellStyle; }
From source file:com.frameworkset.platform.util.POIExcelUtil.java
License:Open Source License
public static XSSFCellStyle getHeadCellStyle(XSSFWorkbook wb, XSSFFont font) { XSSFCellStyle headCellStyle = wb.createCellStyle(); headCellStyle.setFont(font);/*w ww . j av a 2 s. c o m*/ headCellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); headCellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); headCellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN); headCellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN); headCellStyle.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index); headCellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); headCellStyle.setWrapText(false); headCellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); headCellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); return headCellStyle; }
From source file:com.github.igor_kudryashov.utils.excel.ExcelWriter.java
License:Apache License
/** * Returns a style of cell/*w ww .j a v a 2s .co m*/ * * @param rownum * the number of row for count odd/even rows * @param entry * value of cell * @param header * <code>true</code> if this row is the header, otherwise * <code>false</code> * @return the cell style */ private XSSFCellStyle getCellStyle(int rownum, Object entry, boolean header) { XSSFCellStyle style; String name = entry.getClass().getName(); if (header) { name += "_header"; } else if ((rownum % 2) == 0) { name += "_even"; } if (styles.containsKey(name)) { // if we already have a style for this class, return it style = styles.get(name); } else { // create new style style = (XSSFCellStyle) workbook.createCellStyle(); style.setVerticalAlignment(VerticalAlignment.TOP); style.setBorderBottom(CellStyle.BORDER_THIN); style.setBorderColor(XSSFCellBorder.BorderSide.BOTTOM, colorBorder); style.setBorderLeft(CellStyle.BORDER_THIN); style.setBorderColor(XSSFCellBorder.BorderSide.LEFT, colorBorder); style.setBorderRight(CellStyle.BORDER_THIN); style.setBorderColor(XSSFCellBorder.BorderSide.RIGHT, colorBorder); // format data XSSFDataFormat fmt = (XSSFDataFormat) workbook.createDataFormat(); short format = 0; if (name.contains("Date")) { format = fmt.getFormat(BuiltinFormats.getBuiltinFormat(0xe)); style.setAlignment(CellStyle.ALIGN_LEFT); } else if (name.contains("Double")) { format = fmt.getFormat(BuiltinFormats.getBuiltinFormat(2)); style.setAlignment(CellStyle.ALIGN_RIGHT); } else if (name.contains("Integer")) { format = fmt.getFormat(BuiltinFormats.getBuiltinFormat(1)); style.setAlignment(CellStyle.ALIGN_RIGHT); } else { style.setAlignment(CellStyle.ALIGN_LEFT); if (!header) { style.setWrapText(true); } } if (header) { // for header style.setFillForegroundColor(colorHeaderBackground); style.setFillPattern(CellStyle.SOLID_FOREGROUND); } else if (name.contains("_even")) { // for even rows style.setFillForegroundColor(colorEvenCellBackground); style.setFillPattern(CellStyle.SOLID_FOREGROUND); } style.setDataFormat(format); // keep the style for reuse styles.put(name, style); } return style; }
From source file:com.github.ukase.toolkit.xlsx.RenderingTable.java
License:Open Source License
private void updateRowStyle(Element tr, Row row) { XSSFCellStyle cellStyle = (XSSFCellStyle) wb.createCellStyle(); TableRowBox rowBox = (TableRowBox) (box.getElementBoxes(tr)).get(0); CalculatedStyle style = rowBox.getStyle(); cellStyle.setAlignment(prepareAlignment(style.getIdent(CSSName.TEXT_ALIGN))); row.setRowStyle(cellStyle);/*from ww w.j a v a 2s . c o m*/ }
From source file:com.github.ukase.toolkit.xlsx.RenderingTable.java
License:Open Source License
private CellStyle prepareCellStyle(CalculatedStyle style) { XSSFCellStyle cellStyle = (XSSFCellStyle) wb.createCellStyle(); BorderPropertySet border = style.getBorder(null); cellStyle.setBorderTop(prepareTopBorder(border)); cellStyle.setBorderRight(prepareRightBorder(border)); cellStyle.setBorderBottom(prepareBottomBorder(border)); cellStyle.setBorderLeft(prepareLeftBorder(border)); cellStyle.setAlignment(prepareAlignment(style.getIdent(CSSName.TEXT_ALIGN))); return cellStyle; }