List of usage examples for org.apache.poi.hssf.usermodel HSSFCellStyle setVerticalAlignment
@Override public void setVerticalAlignment(VerticalAlignment align)
From source file:is.idega.idegaweb.egov.cases.business.CasesWriterExtended.java
License:Open Source License
@Override public MemoryFileBuffer writeXLS(IWContext iwc, Collection cases) throws Exception { MemoryFileBuffer buffer = new MemoryFileBuffer(); MemoryOutputStream mos = new MemoryOutputStream(buffer); HSSFWorkbook workbook = new HSSFWorkbook(); HSSFSheet sheet = workbook.createSheet(StringHandler .shortenToLength(iwrb.getLocalizedString("cases_fetcher.statistics", "Statistics"), 30)); sheet.setColumnWidth((short) 0, (short) (38 * 256)); sheet.setColumnWidth((short) 1, (short) (85 * 256)); HSSFFont font = workbook.createFont(); font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); font.setFontHeightInPoints((short) 12); HSSFCellStyle style = workbook.createCellStyle(); style.setFont(font);//w w w. j a v a 2 s . c o m HSSFCellStyle style2 = workbook.createCellStyle(); style2.setBorderBottom(HSSFCellStyle.BORDER_THIN); style2.setVerticalAlignment(HSSFCellStyle.VERTICAL_TOP); style2.setWrapText(true); HSSFCellStyle style3 = workbook.createCellStyle(); style3.setBorderBottom(HSSFCellStyle.BORDER_THIN); style3.setFont(font); User currentUser = iwc.getCurrentUser(); int cellRow = 0; Iterator iter = cases.iterator(); while (iter.hasNext()) { GeneralCase element = (GeneralCase) iter.next(); CaseCategory category = element.getCaseCategory(); Group handlerGroup = category.getHandlerGroup(); if (!currentUser.hasRelationTo(handlerGroup)) { continue; } CaseType type = element.getCaseType(); CaseStatus status = element.getCaseStatus(); if (status.equals(getBusiness(iwc).getCaseStatusDeleted())) { continue; } User user = element.getOwner(); IWTimestamp created = new IWTimestamp(element.getCreated()); HSSFRow row = sheet.createRow(cellRow++); HSSFCell cell = row.createCell((short) 0); cell.setCellValue(this.iwrb.getLocalizedString("cases_fetcher.case_id", "Case ID")); cell.setCellStyle(style); cell = row.createCell((short) 1); cell.setCellValue(element.getPrimaryKey().toString()); row = sheet.createRow(cellRow++); cell = row.createCell((short) 0); cell.setCellValue(this.iwrb.getLocalizedString("created_date", "Created date")); cell.setCellStyle(style); cell = row.createCell((short) 1); cell.setCellValue(created.getLocaleDateAndTime(locale, IWTimestamp.SHORT, IWTimestamp.SHORT)); if (user != null) { row = sheet.createRow(cellRow++); cell = row.createCell((short) 0); cell.setCellValue(this.iwrb.getLocalizedString("name", "Name")); cell.setCellStyle(style); Name name = new Name(user.getFirstName(), user.getMiddleName(), user.getLastName()); cell = row.createCell((short) 1); cell.setCellValue(name.getName(locale)); row = sheet.createRow(cellRow++); cell = row.createCell((short) 0); cell.setCellValue(this.iwrb.getLocalizedString("personal_id", "Personal ID")); cell.setCellStyle(style); cell = row.createCell((short) 1); cell.setCellValue(PersonalIDFormatter.format(user.getPersonalID(), locale)); } row = sheet.createRow(cellRow++); cell = row.createCell((short) 0); cell.setCellValue(this.iwrb.getLocalizedString("case_category", "Case category")); cell.setCellStyle(style); cell = row.createCell((short) 1); cell.setCellValue(category.getLocalizedCategoryName(locale)); if (getBusiness(iwc).useTypes()) { row = sheet.createRow(cellRow++); cell = row.createCell((short) 0); cell.setCellValue(this.iwrb.getLocalizedString("case_type", "Case type")); cell.setCellStyle(style); cell = row.createCell((short) 1); cell.setCellValue(type.getName()); } if (element.getReference() != null) { row = sheet.createRow(cellRow++); cell = row.createCell((short) 0); cell.setCellValue(this.iwrb.getLocalizedString("reference", "Reference")); cell.setCellStyle(style); cell = row.createCell((short) 1); cell.setCellValue(element.getReference()); } row = sheet.createRow(cellRow++); cell = row.createCell((short) 0); cell.setCellValue(this.iwrb.getLocalizedString("status", "Status")); cell.setCellStyle(style); cell = row.createCell((short) 1); cell.setCellValue(getBusiness(iwc).getLocalizedCaseStatusDescription(element, status, locale)); row = sheet.createRow(cellRow++); cell = row.createCell((short) 0); cell.setCellValue(this.iwrb.getLocalizedString("regarding", "Regarding")); cell.setCellStyle(style); cell = row.createCell((short) 1); cell.setCellValue(element.getSubject() != null ? element.getSubject() : "-"); row = sheet.createRow(cellRow++); row = sheet.createRow(cellRow++); cell = row.createCell((short) 0); cell.setCellValue(this.iwrb.getLocalizedString("message", "Message")); cell.setCellStyle(style3); cell = row.createCell((short) 1); cell.setCellValue(element.getMessage()); cell.setCellStyle(style2); if (element.getReply() != null) { row = sheet.createRow(cellRow++); cell = row.createCell((short) 0); cell.setCellValue(this.iwrb.getLocalizedString("reply", "Reply")); cell.setCellStyle(style3); cell = row.createCell((short) 1); cell.setCellValue(element.getReply()); cell.setCellStyle(style2); } } workbook.write(mos); buffer.setMimeType(MimeTypeUtil.MIME_TYPE_EXCEL_2); return buffer; }
From source file:matriz.core.GerarXLS.java
public static void expExcel(String nomeArquivo, String demanda, List<LineMatriz> linhastabela) { HSSFWorkbook workbook = new HSSFWorkbook(); HSSFSheet firstSheet = workbook.createSheet("Aba1"); HSSFFont fontBranca = workbook.createFont(); fontBranca.setFontHeightInPoints((short) 16); fontBranca.setColor(HSSFColor.WHITE.index); fontBranca.setBoldweight(Font.BOLDWEIGHT_BOLD); HSSFFont fontBrancaMenor = workbook.createFont(); fontBrancaMenor.setFontHeightInPoints((short) 10); fontBrancaMenor.setColor(HSSFColor.WHITE.index); fontBrancaMenor.setBoldweight(Font.BOLDWEIGHT_BOLD); FileOutputStream fos = null;/* w w w . ja va 2s. c o m*/ nomeArquivo = nomeArquivo + "/Matriz de Rastreabilidade " + demanda + ".xls"; try { fos = new FileOutputStream(new File(nomeArquivo)); HSSFRow rowa = firstSheet.createRow(0); rowa.createCell(1); // criar titulo HSSFRow row0 = firstSheet.createRow(1); HSSFCellStyle style = workbook.createCellStyle(); style.setFont(fontBranca); style.setFillForegroundColor(HSSFColor.DARK_BLUE.index); style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); style.setAlignment(HSSFCellStyle.ALIGN_CENTER); style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); style.setBorderBottom(HSSFCellStyle.BORDER_THIN); style.setBorderTop(HSSFCellStyle.BORDER_THIN); style.setBorderLeft(HSSFCellStyle.BORDER_THIN); style.setBorderRight(HSSFCellStyle.BORDER_THIN); row0.createCell(0).setCellValue("Matriz de classes alteradas na " + demanda); row0.getCell(0).setCellStyle(style); //nome das colunas HSSFRow row1 = firstSheet.createRow(2); HSSFCellStyle style2 = workbook.createCellStyle(); style2.setFillForegroundColor(HSSFColor.DARK_BLUE.index); style2.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); style2.setAlignment(HSSFCellStyle.ALIGN_CENTER_SELECTION); style2.setFont(fontBrancaMenor); style2.setBorderBottom(HSSFCellStyle.BORDER_THIN); style2.setBorderTop(HSSFCellStyle.BORDER_THIN); style2.setBorderLeft(HSSFCellStyle.BORDER_THIN); style2.setBorderRight(HSSFCellStyle.BORDER_THIN); row1.createCell(0).setCellValue("Sistema"); row1.createCell(1).setCellValue("Mdulo"); row1.createCell(2).setCellValue("Diretrio"); row1.createCell(3).setCellValue("Arquivo"); row1.createCell(4).setCellValue("Ambiente"); row1.createCell(5).setCellValue("Tipo do Arquivo"); row1.createCell(6).setCellValue("Ao"); row1.createCell(7).setCellValue("Data"); row1.createCell(8).setCellValue("Reviso SVN"); row1.createCell(9).setCellValue("Autor"); row1.createCell(10).setCellValue("Motivo da alterao"); row1.getCell(0).setCellStyle(style2); row1.getCell(1).setCellStyle(style2); row1.getCell(2).setCellStyle(style2); row1.getCell(3).setCellStyle(style2); row1.getCell(4).setCellStyle(style2); row1.getCell(5).setCellStyle(style2); row1.getCell(6).setCellStyle(style2); row1.getCell(7).setCellStyle(style2); row1.getCell(8).setCellStyle(style2); row1.getCell(9).setCellStyle(style2); row1.getCell(10).setCellStyle(style2); firstSheet.setColumnWidth(0, 10000); firstSheet.setColumnWidth(1, 9000); firstSheet.setColumnWidth(2, 10000); firstSheet.setColumnWidth(3, 20000); firstSheet.setColumnWidth(4, 10000); firstSheet.setColumnWidth(5, 4000); firstSheet.setColumnWidth(6, 4000); firstSheet.setColumnWidth(7, 4000); firstSheet.setColumnWidth(8, 4000); firstSheet.setColumnWidth(9, 6000); firstSheet.setColumnWidth(10, 10000); HSSFCellStyle style3 = workbook.createCellStyle(); style3.setBorderBottom(HSSFCellStyle.BORDER_THIN); style3.setBorderTop(HSSFCellStyle.BORDER_THIN); style3.setBorderLeft(HSSFCellStyle.BORDER_THIN); style3.setBorderRight(HSSFCellStyle.BORDER_THIN); int i = 3; for (LineMatriz linha : linhastabela) { HSSFRow row = firstSheet.createRow(i); row.createCell(0).setCellValue(linha.getSistema()); row.createCell(1).setCellValue(linha.getModulo()); row.createCell(2).setCellValue(linha.getDiretorio()); row.createCell(3).setCellValue(linha.getArquivo()); row.createCell(4).setCellValue(linha.getAmbiente()); row.createCell(5).setCellValue(linha.getTipoArquivo()); row.createCell(6).setCellValue(linha.getAcao()); row.createCell(7).setCellValue(linha.getData()); row.createCell(8).setCellValue(linha.getRevisao()); row.createCell(9).setCellValue(linha.getAutor()); row.createCell(10).setCellValue(linha.getMotivo()); row.getCell(0).setCellStyle(style3); row.getCell(1).setCellStyle(style3); row.getCell(2).setCellStyle(style3); row.getCell(3).setCellStyle(style3); row.getCell(4).setCellStyle(style3); row.getCell(5).setCellStyle(style3); row.getCell(6).setCellStyle(style3); row.getCell(7).setCellStyle(style3); row.getCell(8).setCellStyle(style3); row.getCell(9).setCellStyle(style3); row.getCell(10).setCellStyle(style3); i++; } // fim do for firstSheet.addMergedRegion(new CellRangeAddress(1, //first row (0-based) 1, //last row (0-based) 0, //first column (0-based) 10 //last column (0-based) )); workbook.write(fos); JOptionPane.showMessageDialog(null, "Arquivo criado em " + nomeArquivo); } catch (Exception e) { e.printStackTrace(); JOptionPane.showMessageDialog(null, e.getMessage()); System.out.println("Erro ao exportar arquivo"); } finally { try { fos.flush(); fos.close(); } catch (Exception e) { JOptionPane.showMessageDialog(null, e.getMessage()); } } }
From source file:net.sf.jasperreports.engine.export.JRXlsExporter.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);/* w w w . j a v a 2s . c o m*/ cellStyle.setWrapText(style.lcWrapText); cellStyle.setLocked(style.lcCellLocked); cellStyle.setHidden(style.lcCellHidden); if (style.hasDataFormat()) { cellStyle.setDataFormat(style.getDataFormat()); } boolean isIgnoreCellBorder = getCurrentItemConfiguration().isIgnoreCellBorder(); if (!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.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);// w w w . j av a 2s . c o m cellStyle.setWrapText(style.lcWrapText); cellStyle.setLocked(style.lcCellLocked); cellStyle.setHidden(style.lcCellHidden); if (style.hasDataFormat()) { cellStyle.setDataFormat(style.getDataFormat()); } 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:org.anyframe.logmanager.web.LogManagerController.java
License:Apache License
/** * log data export for excel file type/*from w w w. j a v a2 s.co 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.EPStyle.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 a v a 2s . 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); EPStyleRegion sregion = (EPStyleRegion) parent; if (sregion.isValid()) { Hashtable colorhash = sregion.getColorHash(); HSSFCellStyle style = sregion.getStyle(); short cnvhalign = convertAlignment(getHorizontalAlignment().getCode()); style.setAlignment(cnvhalign); short cnvvalign = convertVAlignment(getVerticalAlignment().getCode()); style.setVerticalAlignment(cnvvalign); style.setFillPattern((short) getShade()); Workbook workbook = getWorkbook(); HSSFDataFormat dataformat = workbook.createDataFormat(); if (getShade() == 1) { // TODO: change to constant when upgrade to new HSSF // solid w/foreground, bg doesn't matter if (getLogger().isDebugEnabled()) { getLogger().debug("shade = 1"); } HSSFColor color = (HSSFColor) colorhash.get(getBackgroundColor().toString()); if (color == null) { if (getLogger().isDebugEnabled()) { getLogger().debug("s1 BG couldn't find color for " + getBackgroundColor().toString()); } color = new HSSFColor.WHITE(); } style.setFillForegroundColor(color.getIndex()); color = (HSSFColor) colorhash.get(getPatternColor().toString()); if (color == null) { if (getLogger().isDebugEnabled()) { getLogger().debug("s1 PC couldn't find color for " + getPatternColor().toString()); } color = new HSSFColor.BLACK(); } style.setFillBackgroundColor(color.getIndex()); } else { HSSFColor color = (HSSFColor) colorhash.get(getBackgroundColor().toString()); if (color == null) { if (getLogger().isDebugEnabled()) { getLogger().debug("BG couldn't find color for " + getBackgroundColor().toString()); } color = new HSSFColor.BLACK(); } style.setFillBackgroundColor(color.getIndex()); color = (HSSFColor) colorhash.get(getPatternColor().toString()); if (color == null) { if (getLogger().isDebugEnabled()) { getLogger().debug("PC couldn't find color for " + getPatternColor().toString()); } color = new HSSFColor.WHITE(); } style.setFillForegroundColor(color.getIndex()); } style.setWrapText(getWrapText()); style.setLocked(true); String format = null; try { format = getFormat(); } catch (NullPointerException e) { format = _general_format; } if (!_general_format.equals(format)) { short valuenumber; format = kludgeForGnumericMisformats(format); format = kludgeForGnumericDateDivergence(format); if (getLogger().isDebugEnabled()) { getLogger().debug("setting format to " + format); } Object o = workbook.getValidate(format, dataformat.getFormat(format)); Short sh = null; sh = (Short) o; valuenumber = sh.shortValue(); style.setDataFormat(valuenumber); } } else { invalid = true; } }
From source file:org.beangle.commons.transfer.excel.ExcelItemWriter.java
License:Open Source License
/** * <p>/*w w w. j a va 2s. co m*/ * getTitleStyle. * </p> * * @return a {@link org.apache.poi.hssf.usermodel.HSSFCellStyle} object. */ protected HSSFCellStyle getTitleStyle() { HSSFCellStyle style = workbook.createCellStyle(); // HSSFFont f = workbook.createFont(); // f.setFontHeightInPoints((short ) 10 ); //? // f.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);// // style.setFont(f); style.setAlignment(HSSFCellStyle.ALIGN_CENTER);// ? style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// style.setFillPattern(HSSFCellStyle.FINE_DOTS); style.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index); style.setFillBackgroundColor(HSSFColor.LIGHT_BLUE.index); return style; }
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();/* ww w .ja va 2 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; }
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();//from w w w.j a v a 2 s. c o m 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); 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.jfree.workbook.io.XLWriter.java
License:Open Source License
/** * Creates a new cell in the HSSFRow, based on the contents of the supplied cell. * /*from w w w .j a v a2s .co m*/ * @param hssfWorkbook the workbook. * @param hssfRow the row. * @param worksheet the worksheet. * @param cell the cell. */ private void createHSSFCell(HSSFWorkbook hssfWorkbook, HSSFRow hssfRow, Worksheet worksheet, Cell cell) { HSSFCell hssfCell = hssfRow.createCell((short) cell.getColumn()); if (cell.getType() == Cell.LABEL_TYPE) { hssfCell.setCellType(HSSFCell.CELL_TYPE_STRING); hssfCell.setCellValue(cell.getContent()); } else if (cell.getType() == Cell.VALUE_TYPE) { hssfCell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); hssfCell.setCellValue(Double.valueOf(cell.getContent()).doubleValue()); } else if (cell.getType() == Cell.DATE_TYPE) { hssfCell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); hssfCell.setCellValue(Double.valueOf(cell.getContent()).doubleValue()); } HSSFCellStyle hssfStyle = hssfWorkbook.createCellStyle(); Style style = worksheet.getStyles().getStyle(cell.getRow(), cell.getColumn()); hssfStyle.setAlignment(getXLHorizontalAlignment(style)); hssfStyle.setVerticalAlignment(getXLVerticalAlignment(style)); hssfStyle.setWrapText(style.isWrapText()); //hssfStyle.setFillBackgroundColor(style.getBackgroundColor()); hssfStyle.setBorderTop(getXLBorder(style.getBorder().getTop())); hssfStyle.setBorderBottom(getXLBorder(style.getBorder().getBottom())); hssfStyle.setBorderLeft(getXLBorder(style.getBorder().getLeft())); hssfStyle.setBorderRight(getXLBorder(style.getBorder().getRight())); hssfCell.setCellStyle(hssfStyle); }