List of usage examples for org.apache.poi.hssf.usermodel HSSFWorkbook getCreationHelper
@Override
public HSSFCreationHelper getCreationHelper()
From source file:co.turnus.analysis.data.bottlenecks.io.XlsAlgoBottlenecksDataWriter.java
License:Open Source License
public void write(AlgoBottlenecksData report, File file) { try {/*from w ww . ja va 2 s. c o m*/ HSSFWorkbook workbook = new HSSFWorkbook(); titleFont = workbook.createFont(); titleFont.setFontName("Arial"); titleFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); cellStyle = workbook.createCellStyle(); cellStyle.setDataFormat(workbook.getCreationHelper().createDataFormat().getFormat("m/d/yy h:mm")); HotspotsDataAnalyser analyzer = new HotspotsDataAnalyser(report); writeSummary(workbook, report.getNetwork(), analyzer); writeActorClassesTable(workbook, analyzer); writeActorsTable(workbook, analyzer); writeActionActorClassTable(workbook, analyzer); writeActionActorTable(workbook, analyzer); // check if there are also impact analysis data ImpactData impactData = report.getImpactData(); if (impactData != null) { writeImpactAnalysis(workbook, impactData); } OutputStream out = new FileOutputStream(file); out = new BufferedOutputStream(out); workbook.write(out); out.close(); } catch (Exception e) { throw new TurnusRuntimeException("Error writing the excel file " + file, e.getCause()); } }
From source file:co.turnus.analysis.data.pipelining.io.XlsSimplePipeliningDataWriter.java
License:Open Source License
public void write(SimplePipelingData report, File file) { try {//from w ww . jav a2 s . c om HSSFWorkbook workbook = new HSSFWorkbook(); titleFont = workbook.createFont(); titleFont.setFontName("Arial"); titleFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); cellStyle = workbook.createCellStyle(); cellStyle.setDataFormat(workbook.getCreationHelper().createDataFormat().getFormat("m/d/yy h:mm")); HSSFSheet sheet = workbook.createSheet("Pipelinable <Actor, Action>"); // Action Actor Class Results Cell cell = sheet.createRow(0).createCell(0); HSSFRichTextString title = new HSSFRichTextString("Action and Actor Pipelining Results"); title.applyFont(titleFont); cell.setCellValue(title); Row row = sheet.createRow(1); sheet.addMergedRegion(new CellRangeAddress(1, 3, 0, 0)); row.createCell(0).setCellValue("Actor"); sheet.addMergedRegion(new CellRangeAddress(1, 3, 1, 1)); row.createCell(1).setCellValue("Action"); sheet.addMergedRegion(new CellRangeAddress(1, 3, 2, 2)); row.createCell(2).setCellValue("pipelinable"); sheet.addMergedRegion(new CellRangeAddress(1, 1, 3, 10)); row.createCell(3).setCellValue("Consecutive Executions"); sheet.addMergedRegion(new CellRangeAddress(1, 3, 11, 11)); row.createCell(11).setCellValue("Splittable Actions"); row = sheet.createRow(2); sheet.addMergedRegion(new CellRangeAddress(2, 2, 3, 6)); row.createCell(3).setCellValue("Pipelinable"); sheet.addMergedRegion(new CellRangeAddress(2, 2, 7, 10)); row.createCell(7).setCellValue("Unconstrained"); row = sheet.createRow(3); row.createCell(3).setCellValue("min"); row.createCell(4).setCellValue("mean"); row.createCell(5).setCellValue("max"); row.createCell(6).setCellValue("var"); row.createCell(7).setCellValue("min"); row.createCell(8).setCellValue("mean"); row.createCell(9).setCellValue("max"); row.createCell(10).setCellValue("var"); int rowId = 4; Map<Actor, Map<Action, SimpleActionPipeliningData>> table = report.asTable().rowMap(); for (Map<Action, SimpleActionPipeliningData> ac : table.values()) { for (SimpleActionPipeliningData data : ac.values()) { row = sheet.createRow(rowId); row.createCell(0).setCellValue(data.getActor().getId()); row.createCell(1).setCellValue(data.getAction().getId()); row.createCell(2).setCellValue(data.isPipelinable()); StatisticalData stat = data.getPipelinableRepetitions(); if (stat.getSamples() > 0) { row.createCell(3).setCellValue(stat.getMin()); row.createCell(4).setCellValue(stat.getMean()); row.createCell(5).setCellValue(stat.getMax()); row.createCell(6).setCellValue(stat.getVariance()); } else { row.createCell(3).setCellValue("-"); row.createCell(4).setCellValue("-"); row.createCell(5).setCellValue("-"); row.createCell(6).setCellValue("-"); } stat = data.getUnconstrainedRepetitions(); if (stat.getSamples() > 0) { row.createCell(7).setCellValue(stat.getMin()); row.createCell(8).setCellValue(stat.getMean()); row.createCell(9).setCellValue(stat.getMax()); row.createCell(10).setCellValue(stat.getVariance()); } else { row.createCell(7).setCellValue("-"); row.createCell(8).setCellValue("-"); row.createCell(9).setCellValue("-"); row.createCell(10).setCellValue("-"); } StringBuffer b = new StringBuffer(); for (Action action : data.getSplittableActions()) { b.append(action.getId()).append(" "); } row.createCell(11).setCellValue(b.toString()); rowId++; } } OutputStream out = new FileOutputStream(file); out = new BufferedOutputStream(out); workbook.write(out); out.close(); } catch (Exception e) { throw new TurnusRuntimeException("Error writing the excel file " + file, e.getCause()); } }
From source file:co.turnus.profiling.io.XlsHalsteadAnalysisWriter.java
License:Open Source License
public void write(SourceCodeData report, File file) { try {// www . jav a2 s . c om HSSFWorkbook workbook = new HSSFWorkbook(); titleFont = workbook.createFont(); titleFont.setFontName("Arial"); titleFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); cellStyle = workbook.createCellStyle(); cellStyle.setDataFormat(workbook.getCreationHelper().createDataFormat().getFormat("m/d/yy h:mm")); writeSummary(workbook, report.getNetwork(), report); writeActorClassesTable(workbook, report); OutputStream out = new FileOutputStream(file); out = new BufferedOutputStream(out); workbook.write(out); out.close(); } catch (Exception e) { throw new TurnusRuntimeException("Error writing the excel file " + file, e.getCause()); } }
From source file:co.turnus.profiling.io.XlsProfilingDataWriter.java
License:Open Source License
public void write(File file, ProfilingData data) { try {//from w w w . j av a 2 s . c o m HSSFWorkbook workbook = new HSSFWorkbook(); titleFont = workbook.createFont(); titleFont.setFontName("Arial"); titleFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); cellStyle = workbook.createCellStyle(); cellStyle.setDataFormat(workbook.getCreationHelper().createDataFormat().getFormat("m/d/yy h:mm")); // writeSummary(workbook, data.getNetwork(), data); writeFifosData(workbook, data); OutputStream out = new FileOutputStream(file); out = new BufferedOutputStream(out); workbook.write(out); out.close(); } catch (Exception e) { throw new TurnusRuntimeException("Error writing the excel file " + file, e.getCause()); } }
From source file:com.github.camaral.sheeco.Sheeco.java
License:Apache License
/** * Creates a spreadsheet with only the headers as described by the set of * payloadClass, but no data. For each payloadClass a sheet will be created. * //from ww w . j ava2s . co m * @param stream * The output which will receive the content of the spreadsheet * @param payloadClasses * Java types annotated with {@link SpreadsheetPayload} * */ public void toSpreadsheet(final OutputStream stream, final Set<Class<? extends Object>> payloadClasses) throws IOException { if (payloadClasses.size() < 1) { throw new IllegalArgumentException("At least one payload class must be present"); } final HSSFWorkbook wb = new HSSFWorkbook(); final CreationHelper creationHelper = wb.getCreationHelper(); for (final Class<? extends Object> clazz : payloadClasses) { final Payload<? extends Object> payload = new Payload<>(clazz); final Sheet sheet = createSheet(wb, payload.getName()); final Row row = createRow(sheet); createCells(payload, row, creationHelper); } wb.write(stream); }
From source file:com.haulmont.yarg.formatters.impl.inline.AbstractInliner.java
License:Apache License
@Override public void inlineToXls(HSSFPatriarch patriarch, HSSFCell resultCell, Object paramValue, Matcher paramsMatcher) {/*from ww w.jav a 2 s . c o m*/ try { Image image = new Image(paramValue, paramsMatcher); if (image.isValid()) { HSSFSheet sheet = resultCell.getSheet(); HSSFWorkbook workbook = sheet.getWorkbook(); int pictureIdx = workbook.addPicture(image.imageContent, Workbook.PICTURE_TYPE_JPEG); CreationHelper helper = workbook.getCreationHelper(); ClientAnchor anchor = helper.createClientAnchor(); anchor.setCol1(resultCell.getColumnIndex()); anchor.setRow1(resultCell.getRowIndex()); anchor.setCol2(resultCell.getColumnIndex()); anchor.setRow2(resultCell.getRowIndex()); if (patriarch == null) { throw new IllegalArgumentException(String.format( "No HSSFPatriarch object provided. Charts on this sheet could cause this effect. Please check sheet %s", resultCell.getSheet().getSheetName())); } HSSFPicture picture = patriarch.createPicture(anchor, pictureIdx); Dimension size = ImageUtils.getDimensionFromAnchor(picture); double actualHeight = size.getHeight() / EMU_PER_PIXEL; double actualWidth = size.getWidth() / EMU_PER_PIXEL; picture.resize((double) image.width / actualWidth, (double) image.height / actualHeight); } } catch (IllegalArgumentException e) { throw new ReportFormattingException("An error occurred while inserting bitmap to xls file", e); } }
From source file:com.haulmont.yarg.formatters.impl.xls.hints.CustomCellStyleHint.java
License:Apache License
@Override public void apply() { for (DataObject dataObject : data) { HSSFCell templateCell = dataObject.templateCell; HSSFCell resultCell = dataObject.resultCell; BandData bandData = dataObject.bandData; HSSFWorkbook resultWorkbook = resultCell.getSheet().getWorkbook(); HSSFWorkbook templateWorkbook = templateCell.getSheet().getWorkbook(); String templateCellValue = templateCell.getStringCellValue(); Matcher matcher = pattern.matcher(templateCellValue); if (matcher.find()) { String paramName = matcher.group(1); String styleName = (String) bandData.getParameterValue(paramName); if (styleName == null) continue; HSSFCellStyle cellStyle = styleCache.getStyleByName(styleName); if (cellStyle == null) continue; HSSFCellStyle resultStyle = styleCache.getNamedCachedStyle(cellStyle); if (resultStyle == null) { HSSFCellStyle newStyle = resultWorkbook.createCellStyle(); // color newStyle.setFillBackgroundColor(cellStyle.getFillBackgroundColor()); newStyle.setFillForegroundColor(cellStyle.getFillForegroundColor()); newStyle.setFillPattern(cellStyle.getFillPattern()); // borders newStyle.setBorderLeft(cellStyle.getBorderLeft()); newStyle.setBorderRight(cellStyle.getBorderRight()); newStyle.setBorderTop(cellStyle.getBorderTop()); newStyle.setBorderBottom(cellStyle.getBorderBottom()); // border colors newStyle.setLeftBorderColor(cellStyle.getLeftBorderColor()); newStyle.setRightBorderColor(cellStyle.getRightBorderColor()); newStyle.setBottomBorderColor(cellStyle.getBottomBorderColor()); newStyle.setTopBorderColor(cellStyle.getTopBorderColor()); // alignment newStyle.setAlignment(cellStyle.getAlignment()); newStyle.setVerticalAlignment(cellStyle.getVerticalAlignment()); // misc DataFormat dataFormat = resultWorkbook.getCreationHelper().createDataFormat(); newStyle.setDataFormat(dataFormat.getFormat(cellStyle.getDataFormatString())); newStyle.setHidden(cellStyle.getHidden()); newStyle.setLocked(cellStyle.getLocked()); newStyle.setIndention(cellStyle.getIndention()); newStyle.setRotation(cellStyle.getRotation()); newStyle.setWrapText(cellStyle.getWrapText()); // font HSSFFont cellFont = cellStyle.getFont(templateWorkbook); HSSFFont newFont = fontCache.getFontByTemplate(cellFont); if (newFont == null) { newFont = resultWorkbook.createFont(); newFont.setFontName(cellFont.getFontName()); newFont.setItalic(cellFont.getItalic()); newFont.setStrikeout(cellFont.getStrikeout()); newFont.setTypeOffset(cellFont.getTypeOffset()); newFont.setBoldweight(cellFont.getBoldweight()); newFont.setCharSet(cellFont.getCharSet()); newFont.setColor(cellFont.getColor()); newFont.setUnderline(cellFont.getUnderline()); newFont.setFontHeight(cellFont.getFontHeight()); newFont.setFontHeightInPoints(cellFont.getFontHeightInPoints()); fontCache.addCachedFont(cellFont, newFont); }//ww w.ja va2 s . co m newStyle.setFont(newFont); resultStyle = newStyle; styleCache.addCachedNamedStyle(cellStyle, resultStyle); } fixNeighbourCellBorders(cellStyle, resultCell); resultCell.setCellStyle(resultStyle); Sheet sheet = resultCell.getSheet(); for (int i = 0; i < sheet.getNumMergedRegions(); i++) { CellRangeAddress mergedRegion = sheet.getMergedRegion(i); if (mergedRegion.isInRange(resultCell.getRowIndex(), resultCell.getColumnIndex())) { int firstRow = mergedRegion.getFirstRow(); int lastRow = mergedRegion.getLastRow(); int firstCol = mergedRegion.getFirstColumn(); int lastCol = mergedRegion.getLastColumn(); for (int row = firstRow; row <= lastRow; row++) for (int col = firstCol; col <= lastCol; col++) sheet.getRow(row).getCell(col).setCellStyle(resultStyle); // cell includes only in one merged region break; } } } } }
From source file:com.report.excel.ExcelToHtmlConverter.java
License:Apache License
public void processWorkbook(HSSFWorkbook workbook) { evaluator = workbook.getCreationHelper().createFormulaEvaluator(); for (int sheetNum = 0; sheetNum < workbook.getNumberOfSheets(); sheetNum++) { HSSFSheet sheet = workbook.getSheetAt(sheetNum); for (Row r : sheet) { for (Cell c : r) { if (c.getCellType() == Cell.CELL_TYPE_FORMULA) { evaluator.evaluateFormulaCell(c); }/* ww w . java2 s . c o m*/ } } } final SummaryInformation summaryInformation = workbook.getSummaryInformation(); if (summaryInformation != null) { processDocumentInformation(summaryInformation); } if (isUseDivsToSpan()) { // prepare CSS classes for later usage this.cssClassContainerCell = htmlDocumentFacade.getOrCreateCssClass(cssClassPrefixCell, "padding:0;margin:0;align:left;vertical-align:top;"); this.cssClassContainerDiv = htmlDocumentFacade.getOrCreateCssClass(cssClassPrefixDiv, "position:relative;"); } for (int s = 0; s < workbook.getNumberOfSheets(); s++) { HSSFSheet sheet = workbook.getSheetAt(s); processSheet(sheet); } htmlDocumentFacade.updateStylesheet(); }
From source file:com.sevenorcas.openstyle.app.service.spreadsheet.SpreadsheetCell.java
/** * Get cell format<p>//from w w w . java2s. c o m * * Thanks to http://stackoverflow.com/questions/15248284/using-poi-how-to-set-the-cell-type-as-number * @param wb * @return */ public HSSFCellStyle getCellStyle(HSSFWorkbook wb) { //EX1 if (sheet.containsStyleId(styleId)) { return sheet.getStyle(styleId); } HSSFCellStyle style = wb.createCellStyle(); Integer clazzX = clazz != null ? clazz : (headerCell != null ? headerCell.clazz : null); switch (clazzX != null ? clazzX : CLASS_STRING) { case CLASS_DATE: if (!isHeader()) { CreationHelper createHelper = wb.getCreationHelper(); style = wb.createCellStyle(); style.setDataFormat(createHelper.createDataFormat() .getFormat(sheet.getDateFormat() != null ? sheet.getDateFormat() : "m/d/yy")); } style.setAlignment(HSSFCellStyle.ALIGN_RIGHT); break; case CLASS_PERCENTAGE: style = wb.createCellStyle(); style.setDataFormat(wb.createDataFormat().getFormat("0.00%")); style.setAlignment(HSSFCellStyle.ALIGN_RIGHT); break; case CLASS_INTEGER: case CLASS_LONG: style.setAlignment(HSSFCellStyle.ALIGN_RIGHT); style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0")); break; case CLASS_DOUBLE: case CLASS_UKURS: style.setAlignment(HSSFCellStyle.ALIGN_RIGHT); style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0.00")); break; case CLASS_STRING: case CLASS_INTEGER_LEFT: case CLASS_BOOLEAN: case CLASS_CHARACTER: default: style.setAlignment(HSSFCellStyle.ALIGN_LEFT); } sheet.setCellStyle(wb, style, this, styleId); return style; }
From source file:com.tecnosur.util.Excel.java
private static void createTituloCell(HSSFWorkbook wb, Row row, int column, short halign, short valign, String strContenido) {/* w ww . j a v a 2 s . c o m*/ CreationHelper ch = wb.getCreationHelper(); Cell cell = row.createCell(column); cell.setCellValue(ch.createRichTextString(strContenido)); HSSFFont cellFont = wb.createFont(); cellFont.setFontHeightInPoints((short) 11); cellFont.setFontName(HSSFFont.FONT_ARIAL); cellFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); CellStyle cellStyle = wb.createCellStyle(); cellStyle.setAlignment(halign); cellStyle.setVerticalAlignment(valign); cellStyle.setFont(cellFont); cell.setCellStyle(cellStyle); }