List of usage examples for org.apache.poi.ss.usermodel HorizontalAlignment LEFT
HorizontalAlignment LEFT
To view the source code for org.apache.poi.ss.usermodel HorizontalAlignment LEFT.
Click Source Link
From source file:DSC.QuantityReport.java
private static void processQuantityReport() { int excelNumber = 0; int sheetNumber = 0; workbook = new XSSFWorkbook(); Map<String, String[]> data = new TreeMap<>(); data.put(0 + "", new String[] { "Doorstep Chef - Quantity Report " + currentWeek(), "", "", "Week : " + returnWeekInt() + " " + " " }); data.put(1 + "", new String[] { "", "", "", "", "", "", "" }); data.put(2 + "", new String[] { "Total Of ", "Single", "Couple", "Three", "Four", "Five", "Six", "Extra" }); XSSFSheet sheet = workbook.createSheet("Quantity Report " + sheetNumber); int rowNum = 0; int cellNum = 0; for (int i = 3; i < 19; i++) { if (i == 3) { data.put(i + "", new String[] { "Orders", quantityObj.getCountFamilySize_1() + "", quantityObj.getCountFamilySize_2() + "", quantityObj.getCountFamilySize_3() + "", quantityObj.getCountFamilySize_4() + "", quantityObj.getCountFamilySize_5() + "", quantityObj.getCountFamilySize_6() + "", quantityObj.getCountFamilySizeMoreThanSix() + "" }); } else if (i == 4) { data.put(i + "", new String[] { "", "", "", "", "", "", "", "" }); } else if (i == 5) { data.put(i + "", new String[] { "Meals", quantityObj.getQuantityFamSize1() + "", quantityObj.getQuantityFamSize2() + "", quantityObj.getQuantityFamSize3() + "", quantityObj.getQuantityFamSize4() + "", quantityObj.getQuantityFamSize5() + "", quantityObj.getQuantityFamSize6() + "", quantityObj.getQuantityFamSizeMoreThanSix() + "" }); } else if (i == 6) { data.put(i + "", new String[] { "", "", "", "", "", "", "", "" }); } else if (i == 7) { data.put(i + "", new String[] { "Standard Meals", quantityObj.getCountFamSize1_Standard() + "", quantityObj.getCountFamSize2_Standard() + "", quantityObj.getCountFamSize3_Standard() + "", quantityObj.getCountFamSize4_Standard() + "", quantityObj.getCountFamSize5_Standard() + "", quantityObj.getCountFamSize6_Standard() + "", quantityObj.getCountFamilySizeMoreThanSix_Standard() + "" }); } else if (i == 8) { data.put(i + "", new String[] { "Low Carb Meals", quantityObj.getCountFamSize1_LC() + "", quantityObj.getCountFamSize2_LC() + "", quantityObj.getCountFamSize3_LC() + "", quantityObj.getCountFamSize4_LC() + "", quantityObj.getCountFamSize5_LC() + "", quantityObj.getCountFamSize6_LC() + "", quantityObj.getCountFamilySizeMoreThanSix_LC() + "" }); } else if (i == 9) { data.put(i + "", new String[] { "Kiddies Meals", quantityObj.getCountFamSize1_KD() + "", quantityObj.getCountFamSize2_KD() + "", quantityObj.getCountFamSize3_KD() + "", quantityObj.getCountFamSize4_KD() + "", quantityObj.getCountFamSize5_KD() + "", quantityObj.getCountFamSize6_KD() + "", quantityObj.getCountFamilySizeMoreThanSix_KD() + "" }); } else if (i == 10) { data.put(i + "", new String[] { "", "", "", "", "", "", "", "" }); } else if (i == 11) { data.put(i + "", new String[] { "Totals", quantityObj.totalSingleMeals() + "", quantityObj.totalCoupleMeals() + "", quantityObj.totalThreeMeals() + "", quantityObj.totalFourMeals() + "", quantityObj.totalFiveMeals() + "", quantityObj.totalSixMeals() + "", quantityObj.totalExtraMeals() + "" }); } else if (i == 12) { data.put(i + "", new String[] { "", "", "", "", "", "", "", "" }); } else if (i == 13) { data.put(i + "", new String[] { "Standard Individuals", "", "", "", "", "", "", quantityObj.returnTotalStandardMeals() + "" }); } else if (i == 14) { data.put(i + "", new String[] { "Low Carb Individuals", "", "", "", "", "", "", quantityObj.returnTotalLowCarbMeals() + "" }); } else if (i == 15) { data.put(i + "", new String[] { "Kiddies Individuals", "", "", "", "", "", "", quantityObj.returnTotalKiddiesMeals() + "" }); } else if (i == 16) { data.put(i + "", new String[] { "", "", "", "", "", "", "", "" }); } else if (i == 17) { data.put(i + "", new String[] { "Total Clients", "", "", "", "", "", "", quantityObj.returnTotalClients() + "" }); } else if (i == 18) { int totalIndividuals = quantityObj.returnTotalStandardMeals() + quantityObj.returnTotalLowCarbMeals() + quantityObj.returnTotalKiddiesMeals(); data.put(i + "", new String[] { "Total Individuals", "", "", "", "", "", "", totalIndividuals + "" }); }/*from w w w. jav a 2 s.c o m*/ } Set<String> keySet = data.keySet(); for (int keyIterate = 0; keyIterate < keySet.size(); keyIterate++) { Row row = sheet.createRow(rowNum); Object[] arr = data.get(keyIterate + ""); XSSFCellStyle borderStyle = workbook.createCellStyle(); XSSFCellStyle borderStyle2 = workbook.createCellStyle(); for (int i = 0; i < arr.length; i++) { XSSFFont font = workbook.createFont(); Cell cell = row.createCell(i); cell.setCellValue((String) arr[i]); if ((keyIterate + "").equals("0") || (keyIterate + "").equals("1")) { font.setFontName("Calibri"); font.setFontHeightInPoints((short) 13); font.setBold(true); borderStyle.setFont(font); borderStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex()); borderStyle.setLeftBorderColor(IndexedColors.BLACK.getIndex()); borderStyle.setTopBorderColor(IndexedColors.BLACK.getIndex()); borderStyle.setRightBorderColor(IndexedColors.BLACK.getIndex()); borderStyle.setAlignment(HorizontalAlignment.LEFT); } else if (keyIterate > 1 && keyIterate < 12) { borderStyle.setBorderBottom(BorderStyle.THIN); borderStyle.setBorderTop(BorderStyle.THIN); borderStyle.setBorderLeft(BorderStyle.THIN); borderStyle.setBorderRight(BorderStyle.THIN); } if ((keyIterate + "").equals("2")) { borderStyle.setBorderBottom(XSSFCellStyle.BORDER_MEDIUM); borderStyle.setBorderLeft(XSSFCellStyle.BORDER_MEDIUM); borderStyle.setBorderTop(XSSFCellStyle.BORDER_MEDIUM); borderStyle.setBorderRight(XSSFCellStyle.BORDER_MEDIUM); borderStyle.setAlignment(HorizontalAlignment.CENTER); borderStyle.setFillPattern(XSSFCellStyle.LESS_DOTS); borderStyle.setFillBackgroundColor(IndexedColors.GREY_50_PERCENT.getIndex()); XSSFFont font2 = workbook.createFont(); font2.setColor(IndexedColors.WHITE.getIndex()); borderStyle.setFont(font2); } cell.setCellStyle(borderStyle); } rowNum++; cellNum++; sheetNumber++; } sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 4)); for (int i = 0; i < 8; i++) { if (i == 0) { sheet.setColumnWidth(i, 5000); } else { sheet.setColumnWidth(i, 2000); } } try { creatSheet(sheetNumber + "", workbook); } catch (IOException ex) { JOptionPane.showMessageDialog(null, "File Could Not Be Found."); } excelNumber++; }
From source file:jdbreport.model.io.xls.poi.Excel2003Writer.java
License:Apache License
protected HorizontalAlignment convertHorizontalAlign(int hAlignment) { switch (hAlignment) { case jdbreport.model.CellStyle.LEFT: return HorizontalAlignment.LEFT; case jdbreport.model.CellStyle.RIGHT: return HorizontalAlignment.RIGHT; case jdbreport.model.CellStyle.CENTER: return HorizontalAlignment.CENTER; case jdbreport.model.CellStyle.JUSTIFY: return HorizontalAlignment.JUSTIFY; }/*from w ww.j a v a 2s . co m*/ return HorizontalAlignment.LEFT; }
From source file:org.cgiar.ccafs.ap.summaries.projects.xlsx.BaseXLS.java
License:Open Source License
/** * Method used to initialize the different styles according to the type of value *//*from w w w . j a v a 2 s. c o m*/ private void initializeStyles(int[] columnTypes) { // Style header styleHeader = (XSSFCellStyle) workbook.createCellStyle(); styleHeader.setAlignment(CellStyle.ALIGN_CENTER); styleHeader.setVerticalAlignment(CellStyle.VERTICAL_CENTER); styleHeader.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND); styleHeader.setFillForegroundColor(new XSSFColor(Color.decode(HEADER_BG_COLOR_HEX))); styleHeader.setWrapText(true); // Font XSSFFont font = (XSSFFont) workbook.createFont(); font.setBold(true); font.setFontName(HEADER_FONT_NAME); font.setColor(new XSSFColor(Color.decode(HEADER_FONT_COLOR_HEX))); font.setFontHeightInPoints(HEADER_FONT_SIZE); styleHeader.setFont(font); richTextFont = workbook.createFont(); richTextFont.setFontName("Tahoma"); richTextFont.setBold(true); richTextFont.setColor(HSSFColor.RED.index); // border this.setBottomBorderCell(styleHeader, Color.decode(HEADER_BORDER_COLOR_HEX)); CreationHelper createHelper = workbook.getCreationHelper(); columnStyles = new XSSFCellStyle[columnTypes.length]; for (int c = 0; c < columnTypes.length; c++) { columnStyles[c] = (XSSFCellStyle) workbook.createCellStyle(); switch (columnTypes[c]) { // Style numeric case COLUMN_TYPE_NUMERIC: columnStyles[c].setAlignment(CellStyle.ALIGN_CENTER); break; // Style date case COLUMN_TYPE_DATE: columnStyles[c].setDataFormat(createHelper.createDataFormat().getFormat(CELL_DATE_FORMAT)); columnStyles[c].setAlignment(CellStyle.ALIGN_CENTER); break; // styleBoleean case COLUMN_TYPE_BOOLEAN: columnStyles[c].setAlignment(CellStyle.ALIGN_CENTER); columnStyles[c].setDataFormat(workbook.createDataFormat().getFormat("#.##")); break; // styleBudget case COLUMN_TYPE_BUDGET: columnStyles[c].setAlignment(CellStyle.ALIGN_CENTER); columnStyles[c].setDataFormat(workbook.createDataFormat().getFormat("$#,##0.00")); // "_($* #,##0.00_);_($* (#,##0.00);_($* \"-\"??_);_(@_)" break; // Style decimal case COLUMN_TYPE_DECIMAL: columnStyles[c].setAlignment(CellStyle.ALIGN_CENTER); columnStyles[c].setDataFormat(workbook.createDataFormat().getFormat("#.##")); break; // Style long string case COLUMN_TYPE_TEXT_LONG: columnStyles[c].setAlignment(HorizontalAlignment.LEFT); columnStyles[c].setWrapText(true); break; // Style short string case COLUMN_TYPE_TEXT_SHORT: columnStyles[c].setAlignment(CellStyle.ALIGN_CENTER); break; // Style hyperlink case COLUMN_TYPE_HYPERLINK: XSSFFont hlinkfont = (XSSFFont) workbook.createFont(); hlinkfont.setUnderline(XSSFFont.U_SINGLE); hlinkfont.setColor(HSSFColor.BLUE.index); columnStyles[c].setFont(hlinkfont); columnStyles[c].setAlignment(CellStyle.ALIGN_CENTER); break; // Style hyperlink case COLUMN_TYPE_DATE_TIME: columnStyles[c].setDataFormat(createHelper.createDataFormat().getFormat(CELL_DATE_TIME_FORMAT)); columnStyles[c].setAlignment(CellStyle.ALIGN_CENTER); break; } this.setBottomBorderCell(columnStyles[c], Color.decode(CELL_BORDER_COLOR_HEX)); if (c == 0) { columnStyles[c].setBorderLeft(CELL_BORDER_TYPE_LEFT); columnStyles[c].setBorderColor(BorderSide.LEFT, new XSSFColor(Color.decode(CELL_BORDER_COLOR_HEX))); } else if (c == columnTypes.length - 1) { columnStyles[c].setBorderRight(CELL_BORDER_TYPE_RIGHT); columnStyles[c].setBorderColor(BorderSide.RIGHT, new XSSFColor(Color.decode(CELL_BORDER_COLOR_HEX))); } } }
From source file:org.dashbuilder.dataset.service.DataSetExportServicesImpl.java
License:Apache License
private Map<String, CellStyle> createStyles(Workbook wb) { Map<String, CellStyle> styles = new HashMap<>(); CellStyle style;//from ww w. j av a 2 s .c o m Font titleFont = wb.createFont(); titleFont.setFontHeightInPoints((short) 12); titleFont.setBold(true); style = wb.createCellStyle(); style.setAlignment(HorizontalAlignment.CENTER); style.setVerticalAlignment(VerticalAlignment.CENTER); style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); style.setFillPattern(FillPatternType.SOLID_FOREGROUND); style.setFont(titleFont); style.setWrapText(false); style.setBorderBottom(BorderStyle.THIN); style.setBottomBorderColor(IndexedColors.GREY_80_PERCENT.getIndex()); styles.put("header", style); Font cellFont = wb.createFont(); cellFont.setFontHeightInPoints((short) 10); cellFont.setBold(true); style = wb.createCellStyle(); style.setAlignment(HorizontalAlignment.RIGHT); style.setVerticalAlignment(VerticalAlignment.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(HorizontalAlignment.RIGHT); style.setVerticalAlignment(VerticalAlignment.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(HorizontalAlignment.LEFT); style.setVerticalAlignment(VerticalAlignment.BOTTOM); style.setFont(cellFont); style.setWrapText(false); style.setDataFormat((short) BuiltinFormats.getBuiltinFormat("text")); styles.put(TEXT_CELL, style); style = wb.createCellStyle(); style.setAlignment(HorizontalAlignment.CENTER); style.setVerticalAlignment(VerticalAlignment.BOTTOM); style.setFont(cellFont); style.setWrapText(false); style.setDataFormat(wb.createDataFormat() .getFormat(DateFormatConverter.convert(Locale.getDefault(), dateFormatPattern))); styles.put("date_cell", style); return styles; }
From source file:org.pentaho.reporting.engine.classic.core.modules.output.table.xls.helper.HSSFCellStyleProducer.java
License:Open Source License
/** * Converts the given element alignment into one of the HorizontalAlignment-constants. * * @param e the JFreeReport element alignment. * @return the HorizontalAlignment-Alignment. * @throws IllegalArgumentException if an Unknown JFreeReport alignment is given. *///from w w w . j a v a 2 s .c om protected static HorizontalAlignment convertHorizontalAlignment(final ElementAlignment e) { if (ElementAlignment.LEFT.equals(e)) { return HorizontalAlignment.LEFT; } else if (ElementAlignment.RIGHT.equals(e)) { return HorizontalAlignment.RIGHT; } else if (ElementAlignment.JUSTIFY.equals(e)) { return HorizontalAlignment.JUSTIFY; } else if (ElementAlignment.CENTER.equals(e)) { return HorizontalAlignment.CENTER; } throw new IllegalArgumentException("Invalid alignment"); }
From source file:org.primefaces.extensions.showcase.util.ExcelCustomExporter.java
License:Apache License
protected CellStyle addColumnAlignments(UIComponent component, CellStyle style) { if (component instanceof HtmlOutputText) { HtmlOutputText output = (HtmlOutputText) component; if (output.getStyle() != null && output.getStyle().contains("left")) { style.setAlignment(HorizontalAlignment.LEFT); }/*from w ww . j a va2 s . c om*/ if (output.getStyle() != null && output.getStyle().contains("right")) { style.setAlignment(HorizontalAlignment.RIGHT); } if (output.getStyle() != null && output.getStyle().contains("center")) { style.setAlignment(HorizontalAlignment.CENTER); } } return style; }
From source file:org.tsukuba_bunko.lilac.helper.port.impl.ExportAuthorHelperImpl.java
License:Open Source License
/** * @see org.tsukuba_bunko.lilac.helper.port.impl.ExportDataHelperBase#prepare(org.apache.poi.xssf.usermodel.XSSFWorkbook) *//*from w w w . j a v a 2 s . c o m*/ @Override protected void prepare(XSSFWorkbook book) { flagCellStyle = book.createCellStyle(); flagCellStyle.setAlignment(HorizontalAlignment.CENTER); flagCellStyle.setVerticalAlignment(VerticalAlignment.CENTER); idCellStyle = book.createCellStyle(); commonCellStyle = book.createCellStyle(); commonCellStyle.setAlignment(HorizontalAlignment.LEFT); commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP); noteCellStyle = book.createCellStyle(); XSSFFont noteFont = book.createFont(); noteFont.setFontHeightInPoints((short) 9); noteCellStyle.setFont(noteFont); noteCellStyle.setAlignment(HorizontalAlignment.LEFT); noteCellStyle.setVerticalAlignment(VerticalAlignment.TOP); noteCellStyle.setWrapText(true); }
From source file:org.tsukuba_bunko.lilac.helper.port.impl.ExportBibliographyHelperImpl.java
License:Open Source License
/** * @see org.tsukuba_bunko.lilac.helper.port.impl.ExportDataHelperBase#prepare(org.apache.poi.xssf.usermodel.XSSFWorkbook) *///from w w w. j a va 2 s. c om @Override protected void prepare(XSSFWorkbook book) { flagCellStyle = book.createCellStyle(); flagCellStyle.setAlignment(HorizontalAlignment.CENTER); flagCellStyle.setVerticalAlignment(VerticalAlignment.CENTER); idCellStyle = book.createCellStyle(); commonCellStyle = book.createCellStyle(); commonCellStyle.setAlignment(HorizontalAlignment.LEFT); commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP); authorsCellStyle = book.createCellStyle(); authorsCellStyle.setWrapText(true); authorsCellStyle.setAlignment(HorizontalAlignment.LEFT); authorsCellStyle.setVerticalAlignment(VerticalAlignment.TOP); dateCellStyle = book.createCellStyle(); dateCellStyle.setAlignment(HorizontalAlignment.LEFT); dateCellStyle.setVerticalAlignment(VerticalAlignment.TOP); }
From source file:org.tsukuba_bunko.lilac.helper.port.impl.ExportBookHelperImpl.java
License:Open Source License
/** * @see org.tsukuba_bunko.lilac.helper.port.impl.ExportDataHelperBase#prepare(org.apache.poi.xssf.usermodel.XSSFWorkbook) */// ww w. j ava 2s .com @Override protected void prepare(XSSFWorkbook book) { flagCellStyle = book.createCellStyle(); flagCellStyle.setAlignment(HorizontalAlignment.CENTER); flagCellStyle.setVerticalAlignment(VerticalAlignment.CENTER); idCellStyle = book.createCellStyle(); XSSFFont idFont = book.createFont(); idFont.setFontHeightInPoints((short) 9); idCellStyle.setFont(idFont); commonCellStyle = book.createCellStyle(); commonCellStyle.setAlignment(HorizontalAlignment.LEFT); commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP); dateCellStyle = book.createCellStyle(); dateCellStyle.setAlignment(HorizontalAlignment.LEFT); dateCellStyle.setVerticalAlignment(VerticalAlignment.TOP); }
From source file:org.tsukuba_bunko.lilac.helper.port.impl.ExportBookshelfHelperImpl.java
License:Open Source License
/** * @see org.tsukuba_bunko.lilac.helper.port.impl.ExportDataHelperBase#prepare(org.apache.poi.xssf.usermodel.XSSFWorkbook) *//*w w w . ja v a 2s.c o m*/ @Override protected void prepare(XSSFWorkbook book) { flagCellStyle = book.createCellStyle(); flagCellStyle.setAlignment(HorizontalAlignment.CENTER); flagCellStyle.setVerticalAlignment(VerticalAlignment.CENTER); idCellStyle = book.createCellStyle(); noteCellStyle = book.createCellStyle(); XSSFFont noteFont = book.createFont(); noteFont.setFontHeightInPoints((short) 9); noteCellStyle.setFont(noteFont); noteCellStyle.setAlignment(HorizontalAlignment.LEFT); noteCellStyle.setVerticalAlignment(VerticalAlignment.TOP); noteCellStyle.setWrapText(true); }