List of usage examples for org.apache.poi.ss.usermodel HorizontalAlignment CENTER
HorizontalAlignment CENTER
To view the source code for org.apache.poi.ss.usermodel HorizontalAlignment CENTER.
Click Source Link
From source file:nc.noumea.mairie.appock.util.StockSpreadsheetExporter.java
License:Open Source License
private static void createRow(XSSFSheet worksheet, XSSFWorkbook workbook, ArticleStock article, CatalogueService catalogueService, int rowNumber) throws IOException { int col = 0;//from w ww . j a v a 2 s . co m XSSFCellStyle cellStyle = workbook.createCellStyle(); cellStyle.setBorderBottom(BorderStyle.THIN); cellStyle.setBorderLeft(BorderStyle.THIN); cellStyle.setBorderRight(BorderStyle.THIN); cellStyle.setVerticalAlignment(VerticalAlignment.CENTER); XSSFCellStyle cellImageStyle = workbook.createCellStyle(); cellImageStyle.setBorderBottom(BorderStyle.THIN); cellImageStyle.setBorderLeft(BorderStyle.THIN); cellImageStyle.setBorderRight(BorderStyle.THIN); cellImageStyle.setVerticalAlignment(VerticalAlignment.CENTER); cellImageStyle.setAlignment(HorizontalAlignment.CENTER); if (rowNumber != 1) { cellStyle.setBorderTop(BorderStyle.THIN); } XSSFFont txtFont = workbook.createFont(); txtFont.setFontName("calibri"); txtFont.setFontHeightInPoints((short) 9); txtFont.setBold(false); cellStyle.setFont(txtFont); XSSFRow row = worksheet.createRow(rowNumber); row.setHeight((short) ROW_HEIGHT_TWIPS);//80px 1600 // Photo File image = null; try { image = catalogueService.getFilePieceJointe(article.getArticleCatalogue().getPhotoArticleCatalogue()); } catch (IllegalArgumentException e) { log.warn("No image to display for article " + article.getArticleCatalogue().getLibelle()); } XSSFCell cell = row.createCell(col); cell.setCellStyle(cellImageStyle); if (image != null) addImage(workbook, worksheet, image, rowNumber); col = col + 1; // Rfrence cell = row.createCell(col); cell.setCellStyle(cellStyle); col = col + 1; cell.setCellValue(article.getReferenceArticleStock()); // Libell cell = row.createCell(col); cell.setCellStyle(cellStyle); col = col + 1; cell.setCellValue(article.getArticleCatalogue().getLibelle()); // Appock Stock cell = row.createCell(col); cell.setCellStyle(cellStyle); col = col + 1; cell.setCellValue(article.getQuantiteStock()); cell.setCellType(CellType.NUMERIC); // Stock reel cell = row.createCell(col); cell.setCellStyle(cellStyle); cell.setCellType(CellType.NUMERIC); }
From source file:offishell.excel.Excel.java
License:MIT License
/** * <p>// ww w.j a va2s . com * Create {@link Excel} wrapper. * </p> * * @param path * @param book */ private Excel(Path path, XSSFWorkbook book) { this.path = path; this.book = book; this.excel = Locator.file(path); this.sheet = book.getSheetAt(0); this.baseStyle = book.createCellStyle(); this.dateStyle = book.createCellStyle(); CreationHelper helper = book.getCreationHelper(); DataFormat dateFormat = helper.createDataFormat(); Font font = book.createFont(); font.setFontName(" Medium"); font.setFontHeightInPoints((short) 10); baseStyle.setFont(font); baseStyle.setAlignment(HorizontalAlignment.CENTER); baseStyle.setVerticalAlignment(VerticalAlignment.CENTER); baseStyle.setShrinkToFit(true); baseStyle.setWrapText(true); dateStyle.cloneStyleFrom(baseStyle); dateStyle.setDataFormat(dateFormat.getFormat("yyyy/mm/dd")); }
From source file:org.agmip.ui.afsirs.util.SummaryReportExcelFormat.java
private XSSFCellStyle getCellStyle(int type) { XSSFFont font = workbook.createFont(); XSSFCellStyle style = null;/*from w w w . j a va 2 s. com*/ switch (type) { case 1: font.setFontHeightInPoints((short) 15); font.setFontName("IMPACT"); font.setItalic(true); font.setColor(HSSFColor.BLUE.index); style = workbook.createCellStyle(); style.setWrapText(true); style.setVerticalAlignment(VerticalAlignment.CENTER); style.setAlignment(HorizontalAlignment.CENTER); style.setFont(font); break; case 2: font.setFontHeightInPoints((short) 15); font.setFontName("IMPACT"); font.setItalic(true); font.setColor(HSSFColor.BLUE.index); style = workbook.createCellStyle(); style.setWrapText(true); style.setShrinkToFit(true); style.setFont(font); break; case 3: font.setFontHeightInPoints((short) 15); font.setFontName("IMPACT"); font.setItalic(true); font.setColor(HSSFColor.BLUE.index); style = workbook.createCellStyle(); style.setWrapText(true); style.setShrinkToFit(true); style.setFont(font); break; case 4: font.setFontHeightInPoints((short) 15); font.setFontName("IMPACT"); font.setItalic(true); font.setColor(HSSFColor.BLUE.index); style = workbook.createCellStyle(); style.setWrapText(true); style.setVerticalAlignment(VerticalAlignment.CENTER); style.setAlignment(HorizontalAlignment.CENTER); style.setFont(font); break; case 5: font.setFontHeightInPoints((short) 15); font.setFontName("IMPACT"); font.setItalic(true); font.setColor(HSSFColor.BLUE.index); style = workbook.createCellStyle(); style.setWrapText(true); style.setVerticalAlignment(VerticalAlignment.CENTER); style.setAlignment(HorizontalAlignment.CENTER); style.setFont(font); break; } return style; }
From source file:org.alfresco.bm.report.XLSXReporter.java
License:Open Source License
/** * Creates a new line with values in the sheet. * /*w ww. ja va 2 s. c o m*/ * @param workbook * (XSSFWorkbook, required) workbook to create the row in * @param sheetRow * (XSSFSheetRow, required) sheet to create the data row in * @param sheetName * (String, required) name of the sheet * @param values * (String [], optional) if null or empty no work will be done, else the values written to the next line * @param bold * (boolean) true: the values will be set in bold font face, else normal * * @since 2.0.10 */ private void createSheetRow(XSSFWorkbook workbook, XSSFSheetRow sheetRow, String sheetName, List<String> values, boolean bold) { if (null != values && values.size() > 0) { // check if sheet exists and create if not if (null == sheetRow.sheet) { sheetRow.sheet = workbook.createSheet(sheetName); } // create cell style XSSFCellStyle cellStyle = workbook.createCellStyle(); cellStyle.setAlignment(HorizontalAlignment.CENTER); if (bold) { // Create bold font Font fontBold = workbook.createFont(); fontBold.setBoldweight(Font.BOLDWEIGHT_BOLD); cellStyle.setFont(fontBold); } // create row XSSFRow row = sheetRow.sheet.createRow(sheetRow.rowCount++); // set values for (int i = 0; i < values.size(); i++) { row.getCell(i).setCellValue(values.get(i)); row.getCell(i).setCellStyle(cellStyle); } } }
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 w ww .j a va 2 s . c om 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.fenixedu.academic.ui.struts.action.academicAdministration.executionCourseManagement.CourseLoadOverviewBean.java
License:Open Source License
public StyledExcelSpreadsheet getInconsistencySpreadsheet() { final StyledExcelSpreadsheet spreadsheet = new StyledExcelSpreadsheet( BundleUtil.getString(Bundle.ACADEMIC, "label.course.load.inconsistency.filename") + "_" + executionSemester.getExecutionYear().getYear().replace('/', '_') + "_" + executionSemester.getSemester()); CellStyle normalStyle = spreadsheet.getExcelStyle().getValueStyle(); normalStyle.setAlignment(HorizontalAlignment.CENTER); HSSFWorkbook wb = spreadsheet.getWorkbook(); HSSFFont font = wb.createFont();/*www . j ava 2s .c o m*/ font.setColor(HSSFColor.BLACK.index); font.setFontHeightInPoints((short) 8); HSSFCellStyle redStyle = wb.createCellStyle(); redStyle.setFont(font); redStyle.setAlignment(HorizontalAlignment.CENTER); redStyle.setFillForegroundColor(HSSFColor.ORANGE.index); redStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); HSSFCellStyle yellowStyle = wb.createCellStyle(); yellowStyle.setFont(font); yellowStyle.setAlignment(HorizontalAlignment.CENTER); yellowStyle.setFillForegroundColor(HSSFColor.YELLOW.index); yellowStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); spreadsheet.newHeaderRow(); spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.department")); spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.degree")); spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.executionCourse")); spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.shift")); spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.shiftType")); spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.load.competenceCourse")); spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.load.curricularCourse")); spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.load.executionCourse")); spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.load.lessonInstances")); spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.load.lesson.count")); spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.load.lessonInstances.count")); for (final ExecutionCourse executionCourse : executionSemester.getAssociatedExecutionCoursesSet()) { for (final CourseLoad courseLoad : executionCourse.getCourseLoadsSet()) { for (final Shift shift : courseLoad.getShiftsSet()) { spreadsheet.newRow(); spreadsheet.addCell(getDepartmentString(executionCourse)); spreadsheet.addCell(executionCourse.getDegreePresentationString()); spreadsheet.addCell(executionCourse.getName()); spreadsheet.addCell(shift.getNome()); spreadsheet.addCell(courseLoad.getType().getFullNameTipoAula()); final BigDecimal competenceCourseLoad = new BigDecimal(getCompetenceCourseLoad(courseLoad)) .setScale(2, RoundingMode.HALF_EVEN); final BigDecimal curricularCourseLoad = new BigDecimal(getCurricularCourseLoad(courseLoad)) .setScale(2, RoundingMode.HALF_EVEN); final BigDecimal executionLoad = courseLoad.getTotalQuantity().setScale(2, RoundingMode.HALF_EVEN); final BigDecimal shiftCourseLoad = getShiftCourseLoad(shift).setScale(2, RoundingMode.HALF_EVEN); if (competenceCourseLoad.signum() < 0) { spreadsheet.addCell(getCompetenceCourseLoadStrings(courseLoad), redStyle); } else { spreadsheet.addCell(competenceCourseLoad); } if (!competenceCourseLoad.equals(curricularCourseLoad) || curricularCourseLoad.signum() < 0) { spreadsheet.addCell(getCurricularCourseLoadString(courseLoad), redStyle); } else { spreadsheet.addCell(curricularCourseLoad); } if (!executionLoad.equals(curricularCourseLoad)) { spreadsheet.addCell(executionLoad, redStyle); } else { spreadsheet.addCell(executionLoad); } if (!shiftCourseLoad.equals(executionLoad)) { if (isLargeDifference(shiftCourseLoad, executionLoad, competenceCourseLoad.divide(new BigDecimal(14), 2, RoundingMode.HALF_EVEN))) { spreadsheet.addCell(shiftCourseLoad, redStyle); } else { spreadsheet.addCell(shiftCourseLoad, yellowStyle); } } else { spreadsheet.addCell(shiftCourseLoad); } spreadsheet.addCell(shift.getAssociatedLessonsSet().size()); spreadsheet.addCell(getLessonInstanceCount(shift)); } } } final HSSFSheet sheet = wb.getSheetAt(0); sheet.createFreezePane(0, 1, 0, 1); sheet.autoSizeColumn(1, true); sheet.autoSizeColumn(2, true); sheet.autoSizeColumn(3, true); sheet.autoSizeColumn(4, true); sheet.autoSizeColumn(5, true); sheet.autoSizeColumn(6, true); sheet.autoSizeColumn(7, true); sheet.autoSizeColumn(8, true); sheet.autoSizeColumn(9, true); return spreadsheet; }
From source file:org.haplo.jsinterface.generate.KGenerateXLS.java
License:Mozilla Public License
private void styleAlign(SheetStyleInstruction i) { HorizontalAlignment align = null;/*from w ww . ja v a2 s . co m*/ if (i.colour instanceof CharSequence) { switch (i.colour.toString()) { case "CENTRE": case "CENTER": align = HorizontalAlignment.CENTER; break; case "RIGHT": align = HorizontalAlignment.RIGHT; break; } } if (align == null) { return; } HashMap<String, Object> properties = new HashMap<String, Object>(1); properties.put(CellUtil.ALIGNMENT, align); styleApplyToRegion(i, properties); }
From source file:org.pentaho.reporting.engine.classic.core.modules.output.table.xls.helper.ExcelCellStyleBuilderTest.java
License:Open Source License
@Test public void testElementStyleSet() { when(workbook.createCellStyle()).thenReturn(xlsStyle); ExcelCellStyleBuilder builder = new ExcelCellStyleBuilder(workbook); when(workbook.createCellStyle()).thenReturn(xlsStyle); when(styleKey.getHorizontalAlignment()).thenReturn(HorizontalAlignment.CENTER); when(styleKey.getVerticalAlignment()).thenReturn(VerticalAlignment.CENTER); when(styleKey.isWrapText()).thenReturn(true); when(workbook.getFontAt(anyShort())).thenReturn(font); when(styleKey.getIndention()).thenReturn((short) 15); when(styleKey.getDataStyle()).thenReturn((short) -1); builder.withElementStyle(mock(StyleSheet.class), styleKey); verify(xlsStyle, times(1)).setAlignment(eq(HorizontalAlignment.CENTER)); verify(xlsStyle, times(1)).setVerticalAlignment(eq(VerticalAlignment.CENTER)); verify(xlsStyle, times(1)).setFont(any()); verify(xlsStyle, times(1)).setWrapText(eq(true)); verify(xlsStyle, times(1)).setIndention(eq((short) 15)); verify(xlsStyle, times(0)).setDataFormat(anyShort()); }
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 ww w . ja va2 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); }//w w w . j a va 2s . com 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; }