List of usage examples for org.apache.poi.hssf.usermodel HSSFCellStyle setFont
public void setFont(HSSFFont font)
From source file:net.sf.jasperreports.engine.export.JRXlsMetadataExporter.java
License:Open Source License
protected HSSFCellStyle getLoadedCellStyle(StyleInfo style) { HSSFCellStyle cellStyle = loadedCellStyles.get(style); if (cellStyle == null) { cellStyle = workbook.createCellStyle(); cellStyle.setFillForegroundColor(style.backcolor); cellStyle.setFillPattern(style.mode); cellStyle.setAlignment(style.horizontalAlignment); cellStyle.setVerticalAlignment(style.verticalAlignment); cellStyle.setRotation(style.rotation); cellStyle.setFont(style.font); cellStyle.setWrapText(style.lcWrapText); cellStyle.setLocked(style.lcCellLocked); cellStyle.setHidden(style.lcCellHidden); if (style.hasDataFormat()) { cellStyle.setDataFormat(style.getDataFormat()); }//w w w . j av a 2 s .c om if (!getCurrentItemConfiguration().isIgnoreCellBorder()) { BoxStyle box = style.box; cellStyle.setBorderTop(box.borderStyle[BoxStyle.TOP]); cellStyle.setTopBorderColor(box.borderColour[BoxStyle.TOP]); cellStyle.setBorderLeft(box.borderStyle[BoxStyle.LEFT]); cellStyle.setLeftBorderColor(box.borderColour[BoxStyle.LEFT]); cellStyle.setBorderBottom(box.borderStyle[BoxStyle.BOTTOM]); cellStyle.setBottomBorderColor(box.borderColour[BoxStyle.BOTTOM]); cellStyle.setBorderRight(box.borderStyle[BoxStyle.RIGHT]); cellStyle.setRightBorderColor(box.borderColour[BoxStyle.RIGHT]); } loadedCellStyles.put(style, cellStyle); } return cellStyle; }
From source file:net.sourceforge.fenixedu.presentationTier.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()); HSSFCellStyle normalStyle = spreadsheet.getExcelStyle().getValueStyle(); normalStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); HSSFWorkbook wb = spreadsheet.getWorkbook(); HSSFFont font = wb.createFont();/*from ww w. jav a2 s. c o m*/ font.setColor(HSSFColor.BLACK.index); font.setFontHeightInPoints((short) 8); HSSFCellStyle redStyle = wb.createCellStyle(); redStyle.setFont(font); redStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); redStyle.setFillForegroundColor(HSSFColor.ORANGE.index); redStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); HSSFCellStyle yellowStyle = wb.createCellStyle(); yellowStyle.setFont(font); yellowStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); yellowStyle.setFillForegroundColor(HSSFColor.YELLOW.index); yellowStyle.setFillPattern(HSSFCellStyle.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:net.triptech.buildulator.view.ExcelTemplateView.java
License:Open Source License
@Override protected void buildExcelDocument(Map<String, Object> model, HSSFWorkbook workbook, HttpServletRequest request, HttpServletResponse response) throws Exception { DataGrid dataGrid = (DataGrid) model.get("dataGrid"); String sheetName = "Sheet 1"; if (StringUtils.isNotBlank(dataGrid.getTitle())) { sheetName = dataGrid.getTitle(); }//w w w . j a v a2 s.co m HSSFSheet sheet = workbook.createSheet(sheetName); Font font = workbook.createFont(); font.setColor(HSSFColor.WHITE.index); HSSFCellStyle style = workbook.createCellStyle(); style.setFillForegroundColor(HSSFColor.GREY_50_PERCENT.index); style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); style.setFont(font); int rowNum = 0; int maxColumnCount = 0; if (dataGrid.getHeaderFields().size() > 0) { HSSFRow header = sheet.createRow(rowNum); rowNum++; maxColumnCount = dataGrid.getHeaderFields().size(); int i = 0; for (String field : dataGrid.getHeaderFields()) { HSSFCell cell = header.createCell(i); cell.setCellValue(field); cell.setCellStyle(style); i++; } } for (int y = 0; y < dataGrid.getRowCount(); y++) { HSSFRow row = sheet.createRow(rowNum++); List<String> rowData = dataGrid.getRowFields(y); if (rowData.size() > maxColumnCount) { maxColumnCount = rowData.size(); } int x = 0; for (String data : rowData) { HSSFCell cell = row.createCell(x); try { double dbValue = Double.parseDouble(data); cell.setCellValue(dbValue); } catch (NumberFormatException nfe) { cell.setCellValue(data); } x++; } } for (int i = 0; i < maxColumnCount; i++) { sheet.autoSizeColumn(i); } }
From source file:opisiame.controller.gestion_resultat.Choix_exportController.java
@FXML public void excel_export() { File excel_file = choix_chemin_enregistrement("Excel files (*.xls)", "*.xls"); if (onglet_actif.equals("questions")) { if (excel_file != null) { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.createSheet("Resultat par question"); sheet.autoSizeColumn(5);/*from ww w .j a va 2 s .c om*/ create_data1(sheet, 0, "Question", "Pourcentage reponse A", "Pourcentage reponse B", "Pourcentage reponse C", "Pourcentage reponse D", "Pourcentage bonne rponse"); Row row = sheet.getRow(0); HSSFCellStyle cellStyle = null; HSSFFont font = wb.createFont(); font.setBold(true); cellStyle = wb.createCellStyle(); cellStyle.setFont(font); row.setRowStyle(cellStyle); for (int i = 0; i < reponse_questions.size(); i++) { Reponse_question rq = reponse_questions.get(i); create_data1(sheet, i + 1, rq.getQuestion(), rq.getStr_pourcentage_rep_a(), rq.getStr_pourcentage_rep_b(), rq.getStr_pourcentage_rep_c(), rq.getStr_pourcentage_rep_d(), rq.getStr_pourcentage()); } FileOutputStream fileOut; try { fileOut = new FileOutputStream(excel_file); wb.write(fileOut); fileOut.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } } else if (onglet_actif.equals("eleves")) { if (excel_file != null) { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.createSheet("Resultat des tudiants"); sheet.autoSizeColumn(5); create_data2(sheet, 0, "Nom", "Prnom", "N tudiant", "Note", "Pourcentage"); Row row = sheet.getRow(0); HSSFCellStyle cellStyle = null; HSSFFont font = wb.createFont(); font.setBold(true); cellStyle = wb.createCellStyle(); cellStyle.setFont(font); row.setRowStyle(cellStyle); for (int i = 0; i < resultats_eleves.size(); i++) { Rep_eleves_quiz re = resultats_eleves.get(i); create_data2(sheet, i + 1, re.getNom_eleve(), re.getPrenom_eleve(), re.getNum_eleve().toString(), re.getNote_eleve().toString(), re.getPourcent_eleve().toString()); } FileOutputStream fileOut; try { fileOut = new FileOutputStream(excel_file); wb.write(fileOut); fileOut.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } } else if (onglet_actif.equals("eleves_pas_num")) { if (excel_file != null) { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.createSheet("Resultat des tudiants"); sheet.autoSizeColumn(4); create_data3(sheet, 0, "Nom", "Prnom", "Note", "Pourcentage"); Row row = sheet.getRow(0); HSSFCellStyle cellStyle = null; HSSFFont font = wb.createFont(); font.setBold(true); cellStyle = wb.createCellStyle(); cellStyle.setFont(font); row.setRowStyle(cellStyle); for (int i = 0; i < resultats_eleves.size(); i++) { Rep_eleves_quiz re = resultats_eleves.get(i); create_data3(sheet, i + 1, re.getNom_eleve(), re.getPrenom_eleve(), re.getNote_eleve().toString(), re.getPourcent_eleve().toString()); } FileOutputStream fileOut; try { fileOut = new FileOutputStream(excel_file); wb.write(fileOut); fileOut.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } } close_window(); }
From source file:opn.greenwebs.Hyperlinks.java
public static void main(String[] args) throws IOException { HSSFWorkbook wb = new HSSFWorkbook(); //cell style for hyperlinks //by default hyperlinks are blue and underlined HSSFCellStyle hlink_style = wb.createCellStyle(); HSSFFont hlink_font = wb.createFont(); hlink_font.setUnderline(HSSFFont.U_SINGLE); hlink_font.setColor(HSSFColor.BLUE.index); hlink_style.setFont(hlink_font); HSSFCell cell;/* w w w . j ava 2 s. c o m*/ HSSFSheet sheet = wb.createSheet("Hyperlinks"); //URL cell = sheet.createRow(0).createCell(0); cell.setCellValue("URL Link"); HSSFHyperlink link = new HSSFHyperlink(HSSFHyperlink.LINK_URL); link.setAddress("http://poi.apache.org/"); cell.setHyperlink(link); cell.setCellStyle(hlink_style); //link to a file in the current directory cell = sheet.createRow(1).createCell(0); cell.setCellValue("File Link"); link = new HSSFHyperlink(HSSFHyperlink.LINK_FILE); link.setAddress("link1.xls"); cell.setHyperlink(link); cell.setCellStyle(hlink_style); //e-mail link cell = sheet.createRow(2).createCell(0); cell.setCellValue("Email Link"); link = new HSSFHyperlink(HSSFHyperlink.LINK_EMAIL); //note, if subject contains white spaces, make sure they are url-encoded link.setAddress("mailto:poi@apache.org?subject=Hyperlinks"); cell.setHyperlink(link); cell.setCellStyle(hlink_style); //link to a place in this workbook //create a target sheet and cell HSSFSheet sheet2 = wb.createSheet("Target Sheet"); sheet2.createRow(0).createCell(0).setCellValue("Target Cell"); cell = sheet.createRow(3).createCell(0); cell.setCellValue("Worksheet Link"); link = new HSSFHyperlink(HSSFHyperlink.LINK_DOCUMENT); link.setAddress("'Target Sheet'!A1"); cell.setHyperlink(link); cell.setCellStyle(hlink_style); FileOutputStream out = new FileOutputStream("hssf-links.xls"); wb.write(out); out.close(); }
From source file:org.adempiere.impexp.AbstractExcelExporter.java
License:Open Source License
private HSSFCellStyle getStyle(int row, int col) { int displayType = getDisplayType(row, col); String key = "cell-" + col + "-" + displayType; HSSFCellStyle cs = m_styles.get(key); if (cs == null) { boolean isHighlightNegativeNumbers = true; cs = m_workbook.createCellStyle(); HSSFFont font = getFont(false);// w w w . j a v a 2 s .c o m cs.setFont(font); // Border cs.setBorderLeft((short) 1); cs.setBorderTop((short) 1); cs.setBorderRight((short) 1); cs.setBorderBottom((short) 1); // if (DisplayType.isDate(displayType)) { cs.setDataFormat(m_dataFormat.getFormat("DD.MM.YYYY")); } else if (DisplayType.isNumeric(displayType)) { DecimalFormat df = DisplayType.getNumberFormat(displayType, getLanguage()); String format = getFormatString(df, isHighlightNegativeNumbers); cs.setDataFormat(m_dataFormat.getFormat(format)); } m_styles.put(key, cs); } return cs; }
From source file:org.adempiere.impexp.AbstractExcelExporter.java
License:Open Source License
private HSSFCellStyle getHeaderStyle(int col) { String key = "header-" + col; HSSFCellStyle cs_header = m_styles.get(key); if (cs_header == null) { HSSFFont font_header = getFont(true); cs_header = m_workbook.createCellStyle(); cs_header.setFont(font_header); cs_header.setBorderLeft((short) 2); cs_header.setBorderTop((short) 2); cs_header.setBorderRight((short) 2); cs_header.setBorderBottom((short) 2); cs_header.setDataFormat(HSSFDataFormat.getBuiltinFormat("text")); cs_header.setWrapText(true);// ww w . j av a2s .c om m_styles.put(key, cs_header); } return cs_header; }
From source file:org.anyframe.logmanager.web.LogManagerController.java
License:Apache License
/** * log data export for excel file type// w w w. j ava 2s . c o m * * @param searchCondition * @param model * @param request * @return * @throws Exception */ @RequestMapping(params = "method=xlsExport") public void xlsExport(LogSearchCondition searchCondition, Model model, HttpServletRequest request, HttpServletResponse response) throws Exception { searchCondition.setPageIndex(-1); searchCondition.setCollection(searchCondition.getRepositoryName()); String fileName = null; String sDate = null; SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss", new Locale("ko_KR")); sDate = sdf.format(new Date()); StringBuffer sb = new StringBuffer(); sb.append(searchCondition.getAppName().substring(searchCondition.getAppName().lastIndexOf("/") + 1)); sb.append("_").append(searchCondition.getCollection()).append("_").append(sDate).append(".xls"); fileName = sb.toString(); SimpleDateFormat dateTimeFormat = new SimpleDateFormat("yyyy-MM-ddHHmm"); logger.debug("from:{}", searchCondition.getFromDate() + searchCondition.getFromHour() + searchCondition.getFromMinute()); logger.debug("to:{}", searchCondition.getToDate() + searchCondition.getToHour() + searchCondition.getToMinute()); if (searchCondition.isUseFromDate()) searchCondition.setFromDateTime(dateTimeFormat.parse(searchCondition.getFromDate() + searchCondition.getFromHour() + searchCondition.getFromMinute())); if (searchCondition.isUseToDate()) searchCondition.setToDateTime(dateTimeFormat.parse( searchCondition.getToDate() + searchCondition.getToHour() + searchCondition.getToMinute())); List<LogDataMap> resultList = service.searchAnalysisLog(searchCondition); response.reset(); response.setContentType("application/x-msexcel;charset=MS949"); // response.setContentType("application/octet-stream"); String userAgent = request.getHeader("User-Agent"); if (userAgent.indexOf("MSIE 5.5") > -1) { response.setHeader("Content-Disposition", "filename=\"" + URLEncoder.encode(fileName, "UTF-8") + "\";"); } else if (userAgent.indexOf("MSIE") > -1) { response.setHeader("Content-Disposition", "attachment; filename=\"" + java.net.URLEncoder.encode(fileName, "UTF-8") + "\";"); } else { response.setHeader("Content-Disposition", "attachment; filename=\"" + new String(fileName.getBytes("euc-kr"), "latin1") + "\";"); } response.setHeader("Content-Description", "JSP Generated Data"); response.setHeader("Content-Transfer-Encoding", "binary;"); response.setHeader("Pragma", "no-cache;"); response.setHeader("Expires", "-1;"); HSSFWorkbook workbook = new HSSFWorkbook(); HSSFSheet sheet = workbook.createSheet(fileName); OutputStream fileOut = null; try { fileOut = response.getOutputStream(); HSSFRow row = null; HSSFRow headerRow = null; HSSFDataFormat df = workbook.createDataFormat(); HSSFCellStyle headerStyle = workbook.createCellStyle(); HSSFFont boldFont = workbook.createFont(); boldFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); headerStyle.setFont(boldFont); headerStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); HSSFCellStyle style = workbook.createCellStyle(); style.setAlignment(HSSFCellStyle.ALIGN_LEFT); style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); HSSFCellStyle dateStyle = workbook.createCellStyle(); dateStyle.setDataFormat(df.getFormat("yyyy-mm-dd h:mm:ss.000")); dateStyle.setAlignment(HSSFCellStyle.ALIGN_LEFT); dateStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); HSSFCellStyle messageStyle = workbook.createCellStyle(); messageStyle.setWrapText(true); messageStyle.setAlignment(HSSFCellStyle.ALIGN_LEFT); messageStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); HSSFCell cell; HSSFCell headerCell; short width = 265; Iterator<String> j = null; String key = null; int cellIndex = 0; int listSize = 0; String level = null; Date timestamp = null; String message = null; if (resultList != null) { listSize = resultList.size(); for (int i = 0; i < listSize; i++) { LogDataMap log = (LogDataMap) resultList.get(i); if (i == 0) { headerRow = sheet.createRow(i); // level header sheet.setColumnWidth(0, 7 * width); headerCell = headerRow.createCell(0); HSSFRichTextString headerValue = new HSSFRichTextString("level"); headerCell.setCellValue(headerValue); headerCell.setCellStyle(headerStyle); headerCell = headerRow.createCell(1); // time stamp header sheet.setColumnWidth(1, 24 * width); headerValue = new HSSFRichTextString("timestamp"); headerCell.setCellValue(headerValue); headerCell.setCellStyle(headerStyle); headerCell = headerRow.createCell(2); // message header sheet.setColumnWidth(2, 70 * width); headerValue = new HSSFRichTextString("message"); headerCell.setCellValue(headerValue); headerCell.setCellStyle(headerStyle); } row = sheet.createRow(i + 1); // level level = (String) log.get("level"); cell = row.createCell(0); cell.setCellStyle(style); cell.setCellType(HSSFCell.CELL_TYPE_STRING); cell.setCellValue(level); // timestamp timestamp = (Date) log.get("timestamp"); cell = row.createCell(1); cell.setCellStyle(dateStyle); cell.setCellValue(timestamp); // message message = (String) log.get("message"); HSSFRichTextString messageValue = new HSSFRichTextString(message); cell = row.createCell(2); cell.setCellStyle(messageStyle); cell.setCellType(HSSFCell.CELL_TYPE_STRING); cell.setCellValue(messageValue); cellIndex = 3; j = log.keySet().iterator(); while (j.hasNext()) { key = j.next(); if ("_id".equals(key) || "message".equals(key) || "timestamp".equals(key) || "level".equals(key)) { continue; } //logger.debug("key=" + key); if (i == 0) { sheet.setColumnWidth(cellIndex, 20 * width); headerCell = headerRow.createCell(cellIndex); HSSFRichTextString headerValue = new HSSFRichTextString(key); headerCell.setCellValue(headerValue); headerCell.setCellStyle(headerStyle); } cell = row.createCell(cellIndex); Object value = log.get(key); if (value instanceof Date) { cell.setCellStyle(dateStyle); cell.setCellValue((Date) value); } else { cell.setCellStyle(style); cell.setCellType(HSSFCell.CELL_TYPE_STRING); cell.setCellValue((String) log.get(key)); } cellIndex++; } } workbook.write(fileOut); } } catch (Exception e) { throw e; } finally { try { if (fileOut != null) { fileOut.flush(); fileOut.close(); } } catch (IOException ex) { logger.warn(ex.getMessage(), ex); } } }
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/*from w ww. j av a 2 s. c o m*/ * @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();//from ww w .ja v a2 s . c o m f.setFontHeightInPoints((short) 10); // ? // f.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);// f.setColor(HSSFColor.WHITE.index); 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; }