List of usage examples for org.apache.poi.ss.usermodel Cell setCellStyle
void setCellStyle(CellStyle style);
Set the style for the cell.
From source file:com.accenture.ts.dao.TesteCaseTSDAO.java
public boolean updateTsSheet(String pathSheet, String nameSheet, TesteCaseTSBean testCase) throws FileNotFoundException, IOException { boolean sucess = false; destinationSheet = new File(pathSheet); destinationSheet.mkdirs();//from w ww. j a v a 2 s . c o m destinationSheet = new File(pathSheet + "\\" + nameSheet); sourceStheet = new File(sheetDefault); copySheet(sourceStheet, destinationSheet); FileInputStream fileSheet = new FileInputStream(destinationSheet); XSSFWorkbook workbook = new XSSFWorkbook(fileSheet); XSSFSheet sheetTS = workbook.getSheetAt(0); XSSFDataFormat format = workbook.createDataFormat(); XSSFCellStyle estilo = workbook.createCellStyle(); // String formatData = "aaaa-mm-dd\"T12:00:00-03:00\""; int linha = 1; Row row = sheetTS.getRow(linha); Cell descriptionPlan = row.getCell(0); Cell prj = row.getCell(1); Cell fase = row.getCell(2); Cell testPhase = row.getCell(3); Cell testScriptName = row.getCell(4); Cell testScriptDescription = row.getCell(5); Cell stepNo = row.getCell(6); Cell stepDescription = row.getCell(7); Cell expectedResults = row.getCell(8); Cell product = row.getCell(9); Cell dataPlanejada = row.getCell(10); Cell complexidade = row.getCell(11); Cell automatizado = row.getCell(12); descriptionPlan.setCellValue(testCase.getTestPlan()); prj.setCellValue(testCase.getSTIPRJ()); fase.setCellValue(testCase.getFASE()); testPhase.setCellValue(testCase.getTestPhase()); // estilo.setDataFormat(format.getFormat(formatData)); // estilo.setFillBackgroundColor(HSSFColor.GREEN.index); row = sheetTS.getRow(linha); prj = row.getCell(1); fase = row.getCell(2); testPhase = row.getCell(3); testScriptName = row.getCell(4); testScriptDescription = row.getCell(5); stepNo = row.getCell(6); stepDescription = row.getCell(7); expectedResults = row.getCell(8); product = row.getCell(9); dataPlanejada = row.getCell(10); complexidade = row.getCell(11); automatizado = row.getCell(12); testScriptName.setCellValue(testCase.getTestScriptName()); testScriptDescription.setCellValue(testCase.getTestScriptDescription()); stepNo.setCellValue(testCase.getSTEP_NUMERO()); stepDescription.setCellValue(testCase.getStepDescription()); expectedResults.setCellValue(testCase.getExpectedResults()); product.setCellValue(testCase.getProduct()); estilo = (XSSFCellStyle) dataPlanejada.getCellStyle(); dataPlanejada.setCellValue(testCase.getDataPlanejada()); dataPlanejada.setCellStyle(estilo); complexidade.setCellValue(testCase.getComplexidade()); automatizado.setCellValue(testCase.isAutomatizado()); linha = linha + 2; FileOutputStream fileOut = new FileOutputStream(destinationSheet); workbook.write(fileOut); fileOut.close(); fileSheet.close(); sucess = true; return sucess; }
From source file:com.actelion.research.spiritapp.report.AbstractReport.java
License:Open Source License
protected Cell set(Sheet sheet, int row, int col, Object text, Style style, int rowspan, int colspan) { Row r = sheet.getRow(row);//w w w . j av a2 s .c o m if (r == null) r = sheet.createRow(row); Cell c = r.getCell(col); if (c == null) c = r.createCell(col); c.setCellStyle(styles.get(style)); if (text == null) { if (c.getCellStyle().getDataFormatString().startsWith("0")) { c.setCellType(Cell.CELL_TYPE_NUMERIC); c.setCellValue(""); } else { c.setCellType(Cell.CELL_TYPE_STRING); c.setCellValue(""); } } else if (text instanceof String) { try { c.setCellType(Cell.CELL_TYPE_NUMERIC); c.setCellValue(Integer.parseInt((String) text)); } catch (Exception e) { try { c.setCellType(Cell.CELL_TYPE_NUMERIC); c.setCellValue(Double.parseDouble((String) text)); } catch (Exception e2) { c.setCellType(Cell.CELL_TYPE_STRING); c.setCellValue((String) text); } } } else if (text instanceof Double) { c.setCellValue((Double) text); c.setCellType(Cell.CELL_TYPE_NUMERIC); } else if (text instanceof Integer) { c.setCellValue((Integer) text); c.setCellType(Cell.CELL_TYPE_NUMERIC); } else if (text instanceof Date) { c.setCellValue((Date) text); } if (rowspan > 1 || colspan > 1) { sheet.addMergedRegion(new CellRangeAddress(row, row + rowspan - 1, col, col + colspan - 1)); for (int i = 0; i < rowspan; i++) { for (int j = 0; j < colspan; j++) { if (i > 0 || j > 0) set(sheet, row + i, col + j, "", style); } } } return c; }
From source file:com.actelion.research.spiritapp.report.AbstractReport.java
License:Open Source License
protected Cell setFormula(Sheet sheet, int row, int col, String text, Style style) { Row r = sheet.getRow(row);//from ww w .jav a 2 s.c o m if (r == null) r = sheet.createRow(row); Cell c = r.getCell(col); if (c == null) c = r.createCell(col); c.setCellStyle(styles.get(style)); c.setCellType(Cell.CELL_TYPE_STRING); try { c.setCellFormula(text); } catch (Exception e) { e.printStackTrace(); c.setCellValue("Err. " + e.getMessage()); } return c; }
From source file:com.actelion.research.spiritapp.report.AbstractReport.java
License:Open Source License
protected void drawLineUnder(Sheet sheet, int row, int colMin, int colMax, short thickness) { Row r = sheet.getRow(row);// w ww . ja v a 2 s . c om if (r == null) r = sheet.createRow(row); for (int col = colMin; col <= colMax; col++) { Cell c = r.getCell(col); if (c == null) c = r.createCell(col); CellStyle style = styleWithBordersUnder.get((c.getCellStyle().getIndex() << 4) + thickness); if (style == null) { style = sheet.getWorkbook().createCellStyle(); style.cloneStyleFrom(c.getCellStyle()); style.setBorderBottom(thickness); styleWithBordersUnder.put((c.getCellStyle().getIndex() << 4) + thickness, style); } c.setCellStyle(style); } }
From source file:com.actelion.research.spiritapp.report.AbstractReport.java
License:Open Source License
protected void drawLineAbove(Sheet sheet, int row, int colMin, int colMax, short thickness) { Row r = sheet.getRow(row);//w ww .ja va 2 s. co m if (r == null) r = sheet.createRow(row); for (int col = colMin; col <= colMax; col++) { Cell c = r.getCell(col); if (c == null) c = r.createCell(col); CellStyle style = styleWithBordersAbove.get(c.getCellStyle().getIndex() << 4 + thickness); if (style == null) { style = sheet.getWorkbook().createCellStyle(); style.cloneStyleFrom(c.getCellStyle()); style.setBorderTop(thickness); styleWithBordersAbove.put(c.getCellStyle().getIndex() << 4 + thickness, style); } c.setCellStyle(style); } }
From source file:com.actelion.research.spiritapp.ui.util.POIUtils.java
License:Open Source License
@SuppressWarnings("rawtypes") public static void exportToExcel(String[][] table, ExportMode exportMode) throws IOException { Class[] types = getTypes(table); Workbook wb = new XSSFWorkbook(); Map<String, CellStyle> styles = new HashMap<String, CellStyle>(); CellStyle style;/*w w w . jav a2 s. c o m*/ DataFormat df = wb.createDataFormat(); Font font = wb.createFont(); font.setFontName("Serif"); font.setBoldweight(Font.BOLDWEIGHT_BOLD); font.setFontHeightInPoints((short) 15); style = wb.createCellStyle(); style.setFont(font); styles.put("title", style); font = wb.createFont(); font.setFontName("Serif"); font.setFontHeightInPoints((short) 10); style = wb.createCellStyle(); style.setBorderRight(CellStyle.BORDER_THIN); style.setRightBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderBottom(CellStyle.BORDER_THIN); style.setBottomBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderLeft(CellStyle.BORDER_THIN); style.setLeftBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderTop(CellStyle.BORDER_THIN); style.setTopBorderColor(IndexedColors.BLACK.getIndex()); style.setAlignment(CellStyle.ALIGN_CENTER); style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setFont(font); style.setWrapText(true); style.setVerticalAlignment(CellStyle.VERTICAL_TOP); styles.put("th", style); font = wb.createFont(); font.setFontName("Serif"); font.setFontHeightInPoints((short) 9); style = wb.createCellStyle(); style.setBorderRight(CellStyle.BORDER_THIN); style.setRightBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderLeft(CellStyle.BORDER_THIN); style.setLeftBorderColor(IndexedColors.BLACK.getIndex()); style.setAlignment(CellStyle.ALIGN_LEFT); style.setFont(font); style.setWrapText(true); style.setVerticalAlignment(CellStyle.VERTICAL_TOP); styles.put("td", style); font = wb.createFont(); font.setFontName("Serif"); font.setFontHeightInPoints((short) 9); style = wb.createCellStyle(); style.setBorderRight(CellStyle.BORDER_THIN); style.setRightBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderLeft(CellStyle.BORDER_THIN); style.setLeftBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderTop(CellStyle.BORDER_THIN); style.setTopBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderBottom(CellStyle.BORDER_THIN); style.setBottomBorderColor(IndexedColors.BLACK.getIndex()); style.setAlignment(CellStyle.ALIGN_LEFT); style.setFont(font); style.setWrapText(true); style.setVerticalAlignment(CellStyle.VERTICAL_TOP); styles.put("td-border", style); font = wb.createFont(); font.setFontName("Serif"); font.setFontHeightInPoints((short) 9); style = wb.createCellStyle(); style.setBorderRight(CellStyle.BORDER_THIN); style.setRightBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderLeft(CellStyle.BORDER_THIN); style.setLeftBorderColor(IndexedColors.BLACK.getIndex()); style.setAlignment(CellStyle.ALIGN_RIGHT); style.setFont(font); style.setVerticalAlignment(CellStyle.VERTICAL_TOP); styles.put("td-double", style); font = wb.createFont(); font.setFontName("Serif"); font.setFontHeightInPoints((short) 9); style = wb.createCellStyle(); style.setBorderRight(CellStyle.BORDER_THIN); style.setRightBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderLeft(CellStyle.BORDER_THIN); style.setLeftBorderColor(IndexedColors.BLACK.getIndex()); style.setAlignment(CellStyle.ALIGN_RIGHT); style.setFont(font); style.setVerticalAlignment(CellStyle.VERTICAL_TOP); styles.put("td-right", style); font = wb.createFont(); font.setFontName("Serif"); font.setBoldweight(Font.BOLDWEIGHT_BOLD); font.setFontHeightInPoints((short) 9); style = wb.createCellStyle(); style.setBorderRight(CellStyle.BORDER_THIN); style.setRightBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderLeft(CellStyle.BORDER_THIN); style.setLeftBorderColor(IndexedColors.BLACK.getIndex()); style.setAlignment(CellStyle.ALIGN_RIGHT); style.setFont(font); style.setVerticalAlignment(CellStyle.VERTICAL_TOP); styles.put("td-bold", style); font = wb.createFont(); font.setFontName("Serif"); font.setFontHeightInPoints((short) 9); style = wb.createCellStyle(); style.setBorderRight(CellStyle.BORDER_THIN); style.setRightBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderLeft(CellStyle.BORDER_THIN); style.setLeftBorderColor(IndexedColors.BLACK.getIndex()); style.setAlignment(CellStyle.ALIGN_RIGHT); style.setFont(font); style.setDataFormat(df.getFormat("d.mm.yyyy h:MM")); style.setVerticalAlignment(CellStyle.VERTICAL_TOP); styles.put("td-date", style); Sheet sheet = wb.createSheet(); sheet.setFitToPage(true); Cell cell; int maxRows = 0; for (int r = 0; r < table.length; r++) { Row row = sheet.createRow(r); if (r == 0) { row.setRowStyle(styles.get("th")); } int rows = 1; for (int c = 0; c < table[r].length; c++) { cell = row.createCell(c); String s = table[r][c]; if (s == null) continue; rows = Math.max(rows, s.split("\n").length); try { if (exportMode == ExportMode.HEADERS_TOP && r == 0) { cell.setCellStyle(styles.get("th")); cell.setCellValue(s); } else if (exportMode == ExportMode.HEADERS_TOPLEFT && (r == 0 || c == 0)) { if (r == 0 && c == 0) { cell.setCellStyle(styles.get("td")); } else { cell.setCellStyle(styles.get("th")); } cell.setCellValue(s); } else if (types[c] == Double.class) { cell.setCellStyle(styles.get("td-double")); cell.setCellType(Cell.CELL_TYPE_NUMERIC); cell.setCellValue(Double.parseDouble(s)); } else if (types[c] == String.class) { cell.setCellStyle( styles.get(exportMode == ExportMode.HEADERS_TOPLEFT ? "td-border" : "td")); cell.setCellType(Cell.CELL_TYPE_NUMERIC); cell.setCellValue(s); } else { cell.setCellStyle(styles.get("td-right")); cell.setCellValue(s); } } catch (Exception e) { cell.setCellStyle(styles.get("td")); cell.setCellValue(s); } } maxRows = Math.max(maxRows, rows); row.setHeightInPoints(rows * 16f); } // Add footer notes if (footerData.size() > 0) { Row row = sheet.createRow(table.length); row.setHeightInPoints((footerData.size() * sheet.getDefaultRowHeightInPoints())); cell = row.createCell(0); sheet.addMergedRegion(new CellRangeAddress(row.getRowNum(), //first row (0-based) row.getRowNum(), //last row (0-based) 0, //first column (0-based) table[0].length - 1 //last column (0-based) )); //for ( String data : footerData ) { style = wb.createCellStyle(); style.setWrapText(true); cell.setCellStyle(style); cell.setCellValue(MiscUtils.flatten(footerData, "\n")); //} } footerData.clear(); autoSizeColumns(sheet); if (table.length > 0) { for (int c = 0; c < table[0].length; c++) { if (sheet.getColumnWidth(c) > 10000) sheet.setColumnWidth(c, 3000); } } if (exportMode == ExportMode.HEADERS_TOPLEFT) { for (int r = 1; r < table.length; r++) { sheet.getRow(r).setHeightInPoints(maxRows * 16f); } } File reportFile = IOUtils.createTempFile("export_", ".xlsx"); FileOutputStream out = new FileOutputStream(reportFile); wb.write(out); wb.close(); out.close(); Desktop.getDesktop().open(reportFile); }
From source file:com.adobe.acs.commons.mcp.impl.ProcessErrorReportExcelServlet.java
License:Apache License
@SuppressWarnings("squid:S3776") protected Workbook createSpreadsheet(ManagedProcess report) { Workbook wb = new XSSFWorkbook(); String name = report.getName(); for (char ch : new char[] { '\\', '/', '*', '[', ']', ':', '?' }) { name = StringUtils.remove(name, ch); }/*from w ww . j a v a2s. c o m*/ Sheet sheet = wb.createSheet(name); sheet.createFreezePane(0, 1, 0, 1); Row headerRow = sheet.createRow(0); CellStyle headerStyle = createHeaderStyle(wb); CellStyle dateStyle = wb.createCellStyle(); CreationHelper createHelper = wb.getCreationHelper(); dateStyle.setDataFormat(createHelper.createDataFormat().getFormat("yyy/mm/dd h:mm:ss")); for (String columnName : Arrays.asList("Time", "Path", "Error", "Stack trace")) { Cell headerCell = headerRow.createCell(headerRow.getPhysicalNumberOfCells()); headerCell.setCellValue(columnName); headerCell.setCellStyle(headerStyle); } Collection<ArchivedProcessFailure> rows = report.getReportedErrorsList(); //make rows, don't forget the header row for (ArchivedProcessFailure error : rows) { Row row = sheet.createRow(sheet.getPhysicalNumberOfRows()); Cell c; c = row.createCell(0); c.setCellValue(error.time); c.setCellStyle(dateStyle); c = row.createCell(1); c.setCellValue(error.nodePath); c = row.createCell(2); c.setCellValue(error.error); c = row.createCell(3); c.setCellValue(error.stackTrace); } autosize(sheet, 4); sheet.setAutoFilter(new CellRangeAddress(0, 1 + rows.size(), 0, 3)); return wb; }
From source file:com.aistor.common.utils.excel.ExportExcel.java
License:Open Source License
/** * ?/*from w ww . j av a 2 s . c o m*/ * @param row * @param column ? * @param val * @param align ??1?23?? * @return ? */ public Cell addCell(Row row, int column, Object val, int align, Class<?> fieldType) { Cell cell = row.createCell(column); CellStyle style = wb.createCellStyle(); style.cloneStyleFrom(styles.get("data")); if (align == 1) { style.setAlignment(CellStyle.ALIGN_LEFT); } else if (align == 2) { style.setAlignment(CellStyle.ALIGN_CENTER); } else if (align == 3) { style.setAlignment(CellStyle.ALIGN_RIGHT); } try { if (val == null) { cell.setCellValue(""); } else if (val instanceof String) { cell.setCellValue((String) val); } else if (val instanceof Integer) { cell.setCellValue((Integer) val); } else if (val instanceof Long) { cell.setCellValue((Long) val); } else if (val instanceof Double) { cell.setCellValue((Double) val); } else if (val instanceof Float) { cell.setCellValue((Float) val); } else if (val instanceof Date) { DataFormat format = wb.createDataFormat(); style.setDataFormat(format.getFormat("yyyy-MM-dd")); cell.setCellValue((Date) val); } else { if (fieldType != Class.class) { cell.setCellValue((String) fieldType.getMethod("setValue", Object.class).invoke(null, val)); } else { cell.setCellValue((String) Class .forName(this.getClass().getName().replaceAll(this.getClass().getSimpleName(), "fieldtype." + val.getClass().getSimpleName() + "Type")) .getMethod("setValue", Object.class).invoke(null, val)); } } } catch (Exception ex) { log.info("Set cell value [" + row.getRowNum() + "," + column + "] error: " + ex.toString()); cell.setCellValue(val.toString()); } cell.setCellStyle(style); return cell; }
From source file:com.anritsu.mcrepositorymanager.utils.GenerateRSS.java
public String getRSS() { FileInputStream file = null;/*from w w w .java2s . c o m*/ String rssFileName = rssTemplateFileName.replaceAll("template", mcVersion); try { file = new FileInputStream( new File(Configuration.getInstance().getRssTemplatePath() + rssTemplateFileName)); XSSFWorkbook workbook = new XSSFWorkbook(file); workbook.setSheetName(workbook.getSheetIndex("MC X.X.X"), "MC " + mcVersion); XSSFSheet sheet = workbook.getSheet("MC " + mcVersion); CreationHelper createHelper = workbook.getCreationHelper(); Cell cell = null; // Update the sheet title cell = sheet.getRow(0).getCell(0); cell.setCellValue(cell.getStringCellValue().replaceAll("template", mcVersion)); XSSFCellStyle cellStyle = workbook.createCellStyle(); cellStyle.setBorderBottom(XSSFCellStyle.BORDER_THIN); cellStyle.setBorderTop(XSSFCellStyle.BORDER_THIN); cellStyle.setBorderRight(XSSFCellStyle.BORDER_THIN); cellStyle.setBorderLeft(XSSFCellStyle.BORDER_THIN); XSSFCellStyle hlinkstyle = workbook.createCellStyle(); XSSFFont hlinkfont = workbook.createFont(); hlinkfont.setUnderline(XSSFFont.U_SINGLE); hlinkfont.setColor(HSSFColor.BLUE.index); hlinkstyle.setFont(hlinkfont); hlinkstyle.setBorderBottom(XSSFCellStyle.BORDER_THIN); hlinkstyle.setBorderTop(XSSFCellStyle.BORDER_THIN); hlinkstyle.setBorderRight(XSSFCellStyle.BORDER_THIN); hlinkstyle.setBorderLeft(XSSFCellStyle.BORDER_THIN); XSSFCellStyle dateCellStyle = workbook.createCellStyle(); dateCellStyle.setDataFormat(createHelper.createDataFormat().getFormat("dd-MMMM-yyyy")); dateCellStyle.setBorderBottom(XSSFCellStyle.BORDER_THIN); dateCellStyle.setBorderTop(XSSFCellStyle.BORDER_THIN); dateCellStyle.setBorderRight(XSSFCellStyle.BORDER_THIN); dateCellStyle.setBorderLeft(XSSFCellStyle.BORDER_THIN); // Populate the table int rowCount = 1; for (RecommendedMcPackage rmcp : sortedMcPackages) { if (rmcp.getRecommendedVersion() != null && rmcp.isShowInTable()) { Row row = sheet.createRow(rowCount + 1); rowCount++; cell = row.createCell(0); cell.setCellValue(rmcp.getTier().replaceAll("Anritsu/MasterClaw/", "")); cell.setCellStyle(cellStyle); cell = row.createCell(1); cell.setCellValue(rmcp.getGroup()); cell.setCellStyle(cellStyle); cell = row.createCell(2); cell.setCellValue(rmcp.getPackageName()); UrlValidator defaultValidator = new UrlValidator(UrlValidator.ALLOW_LOCAL_URLS); if (rmcp.getRecommendedVersion().getReleaseNote() != null && defaultValidator.isValid(rmcp.getRecommendedVersion().getReleaseNote())) { XSSFHyperlink releaseNotelink = (XSSFHyperlink) createHelper .createHyperlink(Hyperlink.LINK_URL); releaseNotelink.setAddress(rmcp.getRecommendedVersion().getReleaseNote()); //System.out.println("Inside(if) RN: " + rmcp.getRecommendedVersion().getReleaseNote() + " Valid: " + defaultValidator.isValid(rmcp.getRecommendedVersion().getReleaseNote())); cell.setHyperlink(releaseNotelink); } cell.setCellStyle(hlinkstyle); cell = row.createCell(3); cell.setCellValue(rmcp.getRecommendedVersion().getPackageVersion()); cell.setCellStyle(cellStyle); cell = row.createCell(4); cell.setCellValue(rmcp.getAvailability()); cell.setCellStyle(cellStyle); cell = row.createCell(5); String customers = Arrays.asList(rmcp.getRecommendedVersion().getCustomerList().toArray()) .toString(); if (customers.equalsIgnoreCase("[All]")) { customers = ""; } cell.setCellValue(customers); cell.setCellStyle(cellStyle); cell = row.createCell(6); cell.setCellValue(rmcp.getRecommendedVersion().getRisk()); cell.setCellStyle(cellStyle); cell = row.createCell(7); cell.setCellValue(rmcp.getPackageName()); XSSFHyperlink link = (XSSFHyperlink) createHelper.createHyperlink(Hyperlink.LINK_URL); link.setAddress(rmcp.getRecommendedVersion().getDownloadLinks().iterator().next()); cell.setHyperlink((XSSFHyperlink) link); cell.setCellStyle(hlinkstyle); cell = row.createCell(8); cell.setCellValue((rmcp.getRecommendedVersion() != null && rmcp.getRecommendedVersion().isLessRecommended()) ? "#" : ""); cell.setCellStyle(cellStyle); cell = row.createCell(9); cell.setCellValue(rmcp.getRecommendedVersion().getNotes()); cell.setCellStyle(cellStyle); StringBuilder newFeatures = new StringBuilder(); for (MCPackageActivities mcpa : rmcp.getRecommendedVersion().getActivities()) { if (!mcpa.getActivityType().equalsIgnoreCase("epr")) { newFeatures.append(mcpa.getActivityType() + " " + mcpa.getActivityId() + "; "); } } cell = row.createCell(10); cell.setCellValue(newFeatures.toString()); cell.setCellStyle(cellStyle); cell = row.createCell(11); cell.setCellValue(rmcp.getRecommendedVersion().getReleaseDate()); cell.setCellStyle(dateCellStyle); } sheet.autoSizeColumn(0); sheet.autoSizeColumn(1); sheet.autoSizeColumn(2); sheet.autoSizeColumn(3); sheet.autoSizeColumn(4); sheet.autoSizeColumn(6); sheet.autoSizeColumn(7); sheet.autoSizeColumn(8); sheet.autoSizeColumn(11); } FileOutputStream outFile = new FileOutputStream( new File(Configuration.getInstance().getRssTemplatePath() + rssFileName)); workbook.write(outFile); outFile.close(); return Configuration.getInstance().getRssTemplatePath() + rssFileName; } catch (FileNotFoundException ex) { Logger.getLogger(GenerateRSS.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(GenerateRSS.class.getName()).log(Level.SEVERE, null, ex); } finally { try { file.close(); } catch (IOException ex) { Logger.getLogger(GenerateRSS.class.getName()).log(Level.SEVERE, null, ex); } } return ""; }
From source file:com.asakusafw.testdata.generator.excel.SheetEditor.java
License:Apache License
/** * Creates a data sheet with specified name. * @param name sheet name// www .ja va2 s .co m * @param model the target model * @throws IllegalArgumentException if some parameters were {@code null} */ public void addData(String name, ModelDeclaration model) { if (name == null) { throw new IllegalArgumentException("name must not be null"); //$NON-NLS-1$ } if (model == null) { throw new IllegalArgumentException("model must not be null"); //$NON-NLS-1$ } Sheet sheet = info.workbook.createSheet(name); Row titleRow = sheet.createRow(0); Row valueRow = sheet.createRow(1); int index = 0; for (PropertyDeclaration property : model.getDeclaredProperties()) { if (index >= info.version.getMaxColumns()) { LOG.warn(MessageFormat.format(Messages.getString("SheetEditor.warnExceedColumnCount"), //$NON-NLS-1$ info.version.getMaxColumns(), model.getName())); break; } Cell title = titleRow.createCell(index); title.setCellStyle(info.titleStyle); title.setCellValue(property.getName().identifier); Cell value = valueRow.createCell(index); value.setCellStyle(info.dataStyle); if (property.getType() instanceof BasicType) { BasicType type = (BasicType) property.getType(); switch (type.getKind()) { case DATE: value.setCellStyle(info.dateDataStyle); break; case DATETIME: value.setCellStyle(info.datetimeDataStyle); break; default: break; } } index++; } adjustDataWidth(sheet); }