List of usage examples for org.apache.poi.hssf.usermodel HSSFFont setFontHeightInPoints
public void setFontHeightInPoints(short height)
From source file:org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EPFont.java
License:Apache License
/** * Override of Initialize() implementation * @param attributes the array of Attribute instances; may be empty, will * never be null/* www. jav a2s . com*/ * @param parent the parent ElementProcessor; may be null * @exception IOException if anything is wrong */ public void initialize(final Attribute[] attributes, final ElementProcessor parent) throws IOException { super.initialize(attributes, parent); EPStyle pstyle = (EPStyle) parent; if (pstyle.isValid()) { Hashtable colorhash = pstyle.getColorHash(); HSSFColor color = null; HSSFCellStyle style = pstyle.getStyle(); //style.setFillForegroundColor( Workbook workbook = getWorkbook(); HSSFFont font = workbook.createFont(); style.setFont(font); font.setFontHeightInPoints((short) getUnit()); //font.setFontName(getFont()); font.setItalic(getItalic()); if (getBold()) { font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); } else { font.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL); } font.setUnderline((byte) getUnderline()); font.setStrikeout(getStrikeThrough()); color = (HSSFColor) colorhash.get(pstyle.getForegroundColor().toString()); //System.out.println(pstyle.getForegroundColor().toString()); if (color == null) color = new HSSFColor.BLACK(); font.setColor(color.getIndex()); hssfFont = font; } }
From source file:org.beangle.model.transfer.excel.ExcelItemWriter.java
License:Open Source License
protected HSSFCellStyle getTitleStyle() { HSSFCellStyle style = workbook.createCellStyle(); HSSFFont f = workbook.createFont(); f.setFontHeightInPoints((short) 10); // ? // f.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);// f.setColor(HSSFColor.WHITE.index);/* w ww . j a v a2 s .com*/ style.setFont(f); style.setAlignment(HSSFCellStyle.ALIGN_CENTER);// ? style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); style.setFillForegroundColor(HSSFColor.DARK_TEAL.index); // style.setFillBackgroundColor(HSSFColor.LIGHT_BLUE.index); return style; }
From source file:org.cyberoam.iview.servlets.ExcelFileGenerator.java
License:Open Source License
void getWorkBook(ResultSetWrapper rsw, ReportBean reportBean, HSSFWorkbook wb) { try {/* ww w . ja v a2s. c om*/ ReportColumnBean[] reportColumns = (ReportColumnBean[]) ReportColumnBean .getReportColumnsByReportID(reportBean.getReportId()).toArray(new ReportColumnBean[0]); HSSFSheet newSheet = wb.createSheet(reportBean.getTitle()); HSSFRow row; HSSFCell cell; HSSFCellStyle cellStyle = wb.createCellStyle(); HSSFFont fontStyle = wb.createFont(); fontStyle.setFontHeightInPoints((short) 10); fontStyle.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); cellStyle.setFont(fontStyle); // getting number of records & fields for report rsw.last(); int rowCount = rsw.getRow(); int colCount = reportColumns.length; //For Freezing the first row newSheet.createFreezePane(0, 1, 0, 1); // Adding column headings to Excel row = newSheet.createRow((short) 0); for (int cCount = 0; cCount < colCount; cCount++) { cell = row.createCell(cCount); cell.setCellStyle(cellStyle); cell.setCellValue(reportColumns[cCount].getColumnName()); } //Adding data for each record to Excel rsw.first(); for (int rcount = 1; rcount <= rowCount; rcount++) { row = newSheet.createRow(rcount); for (int cCount = 0; cCount < colCount; cCount++) { String data = rsw.getString(reportColumns[cCount].getDbColumnName()); cell = row.createCell(cCount); newSheet.autoSizeColumn((short) cCount); if (reportColumns[cCount].getColumnFormat() == TabularReportConstants.BYTE_FORMATTING) { data = ByteInUnit.getBytesInUnit(rsw.getLong(reportColumns[cCount].getDbColumnName())); } else if (reportColumns[cCount].getColumnFormat() == TabularReportConstants.PROTOCOL_FORMATTING && data.indexOf(':') != -1) { String xdata = ProtocolBean.getProtocolNameById( Integer.parseInt(rsw.getString(reportColumns[cCount].getDbColumnName()).substring(0, data.indexOf(':')))); data = xdata + rsw.getString(reportColumns[cCount].getDbColumnName()) .substring(data.indexOf(':'), data.length()); } // Setting value to the cell if (cCount == 0 && (data == null || "".equalsIgnoreCase(data))) data = "N/A"; if (reportColumns[cCount].getColumnFormat() == TabularReportConstants.PERCENTAGE_FORMATTING) { try { cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); cell.setCellValue(Double.parseDouble(data)); } catch (NumberFormatException e) { cell.setCellValue(data); } } else if (rsw.getMetaData().getColumnTypeName(cCount + 1).equalsIgnoreCase("numeric") && reportColumns[cCount].getColumnFormat() != TabularReportConstants.BYTE_FORMATTING) { try { cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); cell.setCellValue(Integer.parseInt(data)); } catch (NumberFormatException e) { cell.setCellValue(data); } } else { cell.setCellValue(data); } } rsw.next(); } } catch (Exception e) { CyberoamLogger.appLog.error("***Error in getWorkbook function***" + e, e); } }
From source file:org.displaytag.render.HssfTableWriter.java
License:Open Source License
/** * @see org.displaytag.render.TableWriterTemplate#writeCaption(org.displaytag.model.TableModel) *///from w ww. java2 s . co m @Override protected void writeCaption(TableModel model) throws Exception { HSSFCellStyle style = this.wb.createCellStyle(); HSSFFont bold = this.wb.createFont(); bold.setBoldweight(Font.BOLDWEIGHT_BOLD); bold.setFontHeightInPoints((short) 14); style.setFont(bold); style.setAlignment(CellStyle.ALIGN_CENTER); this.colNum = 0; this.currentRow = this.sheet.createRow(this.sheetRowNum++); this.currentCell = this.currentRow.createCell(this.colNum); this.currentCell.setCellStyle(style); String caption = model.getCaption(); this.currentCell.setCellValue(new HSSFRichTextString(caption)); this.rowSpanTable(model); }
From source file:org.extremecomponents.table.view.ExtendXlsView.java
License:Apache License
private Map initStyles(HSSFWorkbook wb, short fontHeight) { Map result = new HashMap(); HSSFCellStyle titleStyle = wb.createCellStyle(); HSSFCellStyle textStyle = wb.createCellStyle(); HSSFCellStyle boldStyle = wb.createCellStyle(); HSSFCellStyle numericStyle = wb.createCellStyle(); HSSFCellStyle numericStyleBold = wb.createCellStyle(); HSSFCellStyle moneyStyle = wb.createCellStyle(); HSSFCellStyle moneyStyleBold = wb.createCellStyle(); HSSFCellStyle percentStyle = wb.createCellStyle(); HSSFCellStyle percentStyleBold = wb.createCellStyle(); result.put("titleStyle", titleStyle); result.put("textStyle", textStyle); result.put("boldStyle", boldStyle); result.put("numericStyle", numericStyle); result.put("numericStyleBold", numericStyleBold); result.put("moneyStyle", moneyStyle); result.put("moneyStyleBold", moneyStyleBold); result.put("percentStyle", percentStyle); result.put("percentStyleBold", percentStyleBold); HSSFDataFormat format = wb.createDataFormat(); // Global fonts HSSFFont font = wb.createFont(); font.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL); font.setColor(HSSFColor.BLACK.index); font.setFontName(HSSFFont.FONT_ARIAL); font.setFontHeightInPoints(fontHeight); HSSFFont fontBold = wb.createFont(); fontBold.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); fontBold.setColor(HSSFColor.BLACK.index); fontBold.setFontName(HSSFFont.FONT_ARIAL); fontBold.setFontHeightInPoints(fontHeight); // Money Style moneyStyle.setFont(font);/*from w ww. j a v a 2 s. co m*/ moneyStyle.setAlignment(HSSFCellStyle.ALIGN_RIGHT); moneyStyle.setDataFormat(format.getFormat(moneyFormat)); // Money Style Bold moneyStyleBold.setFont(fontBold); moneyStyleBold.setAlignment(HSSFCellStyle.ALIGN_RIGHT); moneyStyleBold.setDataFormat(format.getFormat(moneyFormat)); // Percent Style percentStyle.setFont(font); percentStyle.setAlignment(HSSFCellStyle.ALIGN_RIGHT); percentStyle.setDataFormat(format.getFormat(percentFormat)); // Percent Style Bold percentStyleBold.setFont(fontBold); percentStyleBold.setAlignment(HSSFCellStyle.ALIGN_RIGHT); percentStyleBold.setDataFormat(format.getFormat(percentFormat)); // Standard Numeric Style numericStyle.setFont(font); numericStyle.setAlignment(HSSFCellStyle.ALIGN_RIGHT); // Standard Numeric Style Bold numericStyleBold.setFont(fontBold); numericStyleBold.setAlignment(HSSFCellStyle.ALIGN_RIGHT); // Title Style titleStyle.setFont(font); titleStyle.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index); titleStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); titleStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); titleStyle.setBottomBorderColor(HSSFColor.BLACK.index); titleStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); titleStyle.setLeftBorderColor(HSSFColor.BLACK.index); titleStyle.setBorderRight(HSSFCellStyle.BORDER_THIN); titleStyle.setRightBorderColor(HSSFColor.BLACK.index); titleStyle.setBorderTop(HSSFCellStyle.BORDER_THIN); titleStyle.setTopBorderColor(HSSFColor.BLACK.index); titleStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); titleStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); // Standard Text Style textStyle.setFont(font); textStyle.setWrapText(true); // Standard Text Style boldStyle.setFont(fontBold); boldStyle.setWrapText(true); return result; }
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(); font.setColor(HSSFColor.BLACK.index); font.setFontHeightInPoints((short) 8); HSSFCellStyle redStyle = wb.createCellStyle(); redStyle.setFont(font);/*from w w w .j a v a2 s. co m*/ 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.forzaframework.util.XlsUtils.java
License:Apache License
static public void modelToExcelSheet(HSSFWorkbook wb, String sheetName, List<Map<String, Object>> headers, List<Map<String, Object>> data, List<Map<String, Object>> footers, Integer freezePane, Boolean defaultFormat, Boolean createNewSheet, Integer indexSheet, Integer startInRow, Boolean printHeader, Boolean autoSizeColumns) { HSSFSheet sheet = getSheet(wb, sheetName, createNewSheet, indexSheet); HSSFCellStyle headerCellStyle = getDefaultHeaderCellStyle(wb, defaultFormat); HSSFCellStyle titlesCellStyle = null; if (defaultFormat != null && defaultFormat) { titlesCellStyle = wb.createCellStyle(); //Creamos el tipo de fuente HSSFFont titleFont = wb.createFont(); // headerFont.setFontName(HSSFFont.FONT_ARIAL); titleFont.setBold(Boolean.TRUE); titleFont.setColor(HSSFFont.COLOR_NORMAL); titleFont.setFontHeightInPoints((short) 8); titlesCellStyle.setFont(titleFont); }/* w w w .j av a 2 s.c om*/ Integer col = 0; Integer row = 0; if (startInRow != null) { row = startInRow; } Map<Integer, Integer> columnWidthMap = new HashMap<Integer, Integer>(); //Indice de la fila donde empieza los encabezados de titulo de cada columna Integer principalHeaderIndex = headers.size() - 1; if (printHeader != null && printHeader) { //Armamos el encabezado for (Map<String, Object> header : headers) { for (Map.Entry<String, Object> entry : header.entrySet()) { HSSFCell cell = getCell(sheet, row, col); if (defaultFormat != null && defaultFormat) { if (principalHeaderIndex.equals(row)) { //Colocamos el formato de la celda cell.setCellStyle(headerCellStyle); } else { cell.setCellStyle(titlesCellStyle); } } setValue(cell, entry.getValue()); //Especificamos el ancho que tendra la columna if (autoSizeColumns != null && autoSizeColumns) { columnWidthMap.put(col, entry.getValue().toString().length()); } col++; } row++; col = 0; } //Ponemos la altura del encabezado setRowHeight(sheet, row - 1, (short) 420); } HSSFCellStyle detailCellStyle = getDefaultDetailCellStyle(wb, defaultFormat); Map<String, Object> principalHeader = headers.get(principalHeaderIndex); // datos for (Map<String, Object> map : data) { for (Map.Entry<String, Object> entry : principalHeader.entrySet()) { Object value = map.get(entry.getKey()); buildCellAndCalculateColumnWidth(sheet, value, col, row, detailCellStyle, columnWidthMap, autoSizeColumns); col++; } col = 0; row++; } HSSFCellStyle totalCellStyle = null; if (defaultFormat != null && defaultFormat) { //Armamos el formato los totales totalCellStyle = wb.createCellStyle(); HSSFFont totalFont = wb.createFont(); totalFont.setBold(Boolean.TRUE); totalFont.setColor(HSSFFont.COLOR_NORMAL); totalFont.setFontHeightInPoints((short) 8); totalCellStyle.setFont(totalFont); } if (footers != null) { for (Map<String, Object> footer : footers) { for (Map.Entry<String, Object> entry : principalHeader.entrySet()) { HSSFCell cell = getCell(sheet, row, col++); if (totalCellStyle != null) { //Colocamos el formato de la celda cell.setCellStyle(totalCellStyle); } Object object = footer.get(entry.getKey()); if (object != null) { setValue(cell, object); } else { setText(cell, ""); } } } } if (autoSizeColumns != null && autoSizeColumns) { setColumnsWidth(sheet, columnWidthMap, principalHeader.size()); } if (freezePane != null && freezePane > 0) { //Colocamos la columna estatica y las filas del encabezado estaticas sheet.createFreezePane(freezePane, headers.size()); } }
From source file:org.forzaframework.util.XlsUtils.java
License:Apache License
public static HSSFCellStyle getDefaultDetailCellStyle(HSSFWorkbook wb, Boolean defaultFormat) { HSSFCellStyle detailCellStyle = null; if (defaultFormat != null && defaultFormat) { //Armamos el formato para los datos del detalle detailCellStyle = wb.createCellStyle(); HSSFFont detailFont = wb.createFont(); detailFont.setFontHeightInPoints((short) 8); detailCellStyle.setFont(detailFont); }/*w w w .j av a 2s . c o m*/ return detailCellStyle; }
From source file:org.forzaframework.util.XlsUtils.java
License:Apache License
public static HSSFCellStyle getDefaultHeaderCellStyle(HSSFWorkbook wb, Boolean defaultFormat) { HSSFCellStyle headerCellStyle = null; if (defaultFormat != null && defaultFormat) { //Le damos formato a los encabezados headerCellStyle = wb.createCellStyle(); headerCellStyle.setBorderBottom(BorderStyle.DOTTED); headerCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); // headerCellStyle.setFillBackgroundColor(HSSFColor.GREY_25_PERCENT.index); headerCellStyle.setFillForegroundColor(HSSFColor.HSSFColorPredefined.GREY_25_PERCENT.getIndex()); //Creamos el tipo de fuente HSSFFont headerFont = wb.createFont(); // headerFont.setFontName(HSSFFont.FONT_ARIAL); headerFont.setBold(Boolean.TRUE); headerFont.setColor(HSSFFont.COLOR_NORMAL); headerFont.setFontHeightInPoints((short) 8); headerCellStyle.setFont(headerFont); }//from w w w. ja v a 2s .c o m return headerCellStyle; }
From source file:org.jxstar.report.studio.ExportXlsBO.java
/** * ?/*from w ww. j a v a2 s .c om*/ * @param wb -- ? * @return */ public HSSFCellStyle createTitleStyle(HSSFWorkbook wb) { // HSSFFont cellFont = wb.createFont(); cellFont.setFontName(""); cellFont.setFontHeightInPoints((short) 16); cellFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); //? HSSFCellStyle cellStyle = wb.createCellStyle(); cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER_SELECTION); cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); cellStyle.setFont(cellFont); return cellStyle; }