List of usage examples for org.apache.poi.ss.usermodel Sheet autoSizeColumn
void autoSizeColumn(int column);
From source file:org.primefaces.extensions.component.exporter.ExcelExporter.java
License:Apache License
@Override public void export(ActionEvent event, String tableId, FacesContext context, String filename, String tableTitle, boolean pageOnly, boolean selectionOnly, String encodingType, MethodExpression preProcessor, MethodExpression postProcessor, boolean subTable) throws IOException { wb = new XSSFWorkbook(); String safeName = WorkbookUtil.createSafeSheetName(filename); Sheet sheet = wb.createSheet(safeName); cellStyle = wb.createCellStyle();/* w w w .j av a 2 s .c om*/ facetStyle = wb.createCellStyle(); titleStyle = wb.createCellStyle(); facetStyleLeftAlign = wb.createCellStyle(); facetStyleCenterAlign = wb.createCellStyle(); facetStyleRightAlign = wb.createCellStyle(); cellStyleLeftAlign = wb.createCellStyle(); cellStyleCenterAlign = wb.createCellStyle(); cellStyleRightAlign = wb.createCellStyle(); createCustomFonts(); int maxColumns = 0; StringTokenizer st = new StringTokenizer(tableId, ","); while (st.hasMoreElements()) { String tableName = (String) st.nextElement(); UIComponent component = SearchExpressionFacade.resolveComponent(context, event.getComponent(), tableName); if (component == null) { throw new FacesException("Cannot find component \"" + tableName + "\" in view."); } if (!(component instanceof DataTable || component instanceof DataList)) { throw new FacesException("Unsupported datasource target:\"" + component.getClass().getName() + "\", exporter must target a PrimeFaces DataTable/DataList."); } DataList list = null; DataTable table = null; int cols = 0; if (preProcessor != null) { preProcessor.invoke(context.getELContext(), new Object[] { wb }); } if (tableTitle != null && !tableTitle.isEmpty() && !tableId.contains("" + ",")) { Row titleRow = sheet.createRow(sheet.getLastRowNum()); int cellIndex = titleRow.getLastCellNum() == -1 ? 0 : titleRow.getLastCellNum(); Cell cell = titleRow.createCell(cellIndex); cell.setCellValue(new XSSFRichTextString(tableTitle)); Font titleFont = wb.createFont(); titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD); titleStyle.setFont(titleFont); cell.setCellStyle(titleStyle); sheet.createRow(sheet.getLastRowNum() + 3); } if (component instanceof DataList) { list = (DataList) component; if (list.getHeader() != null) { tableFacet(context, sheet, list, "header"); } if (pageOnly) { exportPageOnly(context, list, sheet); } else { exportAll(context, list, sheet); } cols = list.getRowCount(); } else { table = (DataTable) component; int columnsCount = getColumnsCount(table); if (table.getHeader() != null && !subTable) { tableFacet(context, sheet, table, columnsCount, "header"); } if (!subTable) { tableColumnGroup(sheet, table, "header"); } addColumnFacets(table, sheet, ColumnType.HEADER); if (pageOnly) { exportPageOnly(context, table, sheet); } else if (selectionOnly) { exportSelectionOnly(context, table, sheet); } else { exportAll(context, table, sheet, subTable); } if (table.hasFooterColumn() && !subTable) { addColumnFacets(table, sheet, ColumnType.FOOTER); } if (!subTable) { tableColumnGroup(sheet, table, "footer"); } table.setRowIndex(-1); if (postProcessor != null) { postProcessor.invoke(context.getELContext(), new Object[] { wb }); } cols = table.getColumnsCount(); if (maxColumns < cols) { maxColumns = cols; } } sheet.createRow(sheet.getLastRowNum() + Integer.parseInt(datasetPadding)); } if (!subTable) for (int i = 0; i < maxColumns; i++) { sheet.autoSizeColumn((short) i); } PrintSetup printSetup = sheet.getPrintSetup(); printSetup.setLandscape(true); printSetup.setPaperSize(PrintSetup.A4_PAPERSIZE); sheet.setPrintGridlines(true); writeExcelToResponse(context.getExternalContext(), wb, filename); }
From source file:org.primefaces.extensions.showcase.util.ExcelCustomExporter.java
License:Apache License
@Override public void export(ActionEvent event, String tableId, FacesContext context, String filename, String tableTitle, boolean pageOnly, boolean selectionOnly, String encodingType, MethodExpression preProcessor, MethodExpression postProcessor, boolean subTable) throws IOException { wb = new XSSFWorkbook(); String safeName = WorkbookUtil.createSafeSheetName(filename); Sheet sheet = wb.createSheet(safeName); cellStyle = wb.createCellStyle();/*from w w w. j ava 2s .c om*/ facetStyle = wb.createCellStyle(); titleStyle = wb.createCellStyle(); createCustomFonts(); int maxColumns = 0; StringTokenizer st = new StringTokenizer(tableId, ","); while (st.hasMoreElements()) { String tableName = (String) st.nextElement(); UIComponent component = SearchExpressionFacade.resolveComponent(context, event.getComponent(), tableName); if (component == null) { throw new FacesException("Cannot find component \"" + tableName + "\" in view."); } if (!(component instanceof DataTable || component instanceof DataList)) { throw new FacesException("Unsupported datasource target:\"" + component.getClass().getName() + "\", exporter must target a PrimeFaces DataTable/DataList."); } DataList list = null; DataTable table = null; int cols = 0; if (preProcessor != null) { preProcessor.invoke(context.getELContext(), new Object[] { wb }); } if (tableTitle != null && !tableTitle.isEmpty() && !tableId.contains("" + ",")) { Row titleRow = sheet.createRow(sheet.getLastRowNum()); int cellIndex = titleRow.getLastCellNum() == -1 ? 0 : titleRow.getLastCellNum(); Cell cell = titleRow.createCell(cellIndex); cell.setCellValue(new XSSFRichTextString(tableTitle)); Font titleFont = wb.createFont(); titleFont.setBold(true); titleStyle.setFont(titleFont); cell.setCellStyle(titleStyle); sheet.createRow(sheet.getLastRowNum() + 3); } if (component instanceof DataList) { list = (DataList) component; if (list.getHeader() != null) { tableFacet(context, sheet, list, "header"); } if (pageOnly) { exportPageOnly(context, list, sheet); } else { exportAll(context, list, sheet); } cols = list.getRowCount(); } else { table = (DataTable) component; int columnsCount = getColumnsCount(table); if (table.getHeader() != null && !subTable) { tableFacet(context, sheet, table, columnsCount, "header"); } if (!subTable) { tableColumnGroup(sheet, table, "header"); } addColumnFacets(table, sheet, ColumnType.HEADER); if (pageOnly) { exportPageOnly(context, table, sheet); } else if (selectionOnly) { exportSelectionOnly(context, table, sheet); } else { exportAll(context, table, sheet, subTable); } if (table.hasFooterColumn() && !subTable) { addColumnFacets(table, sheet, ColumnType.FOOTER); } if (!subTable) { tableColumnGroup(sheet, table, "footer"); } table.setRowIndex(-1); if (postProcessor != null) { postProcessor.invoke(context.getELContext(), new Object[] { wb }); } cols = table.getColumnsCount(); if (maxColumns < cols) { maxColumns = cols; } } sheet.createRow(sheet.getLastRowNum() + Integer.parseInt(datasetPadding)); } if (!subTable) { for (int i = 0; i < maxColumns; i++) { sheet.autoSizeColumn((short) i); } } PrintSetup printSetup = sheet.getPrintSetup(); printSetup.setLandscape(true); printSetup.setPaperSize(PrintSetup.A4_PAPERSIZE); sheet.setPrintGridlines(true); writeExcelToResponse(context.getExternalContext(), wb, filename); }
From source file:org.rhq.helpers.perftest.support.reporting.ExcelExporter.java
License:Open Source License
/** * Create a sheet per test to show the individual timings we recorded * @param wb Workbook to attach the new sheet to * @param timings The map with timings from the test * @param result TestNG results of the test *///from w ww. j a va2 s.com private void createDetailsSheet(Workbook wb, Map<String, Long> timings, ITestResult result) { String name = result.getTestClass().getName(); if (name.contains(".")) name = name.substring(name.lastIndexOf(".") + 1); name += "." + result.getName(); Sheet sheet = wb.getSheet(name); if (sheet == null) sheet = wb.createSheet(name); Row row = appendRow(sheet); Cell cell = row.createCell(0); cell.setCellStyle(boldText); cell.setCellValue("Class"); name = result.getTestClass().getName(); if (name.contains(".")) name = name.substring(name.lastIndexOf(".") + 1); row.createCell(1).setCellValue(name); row = appendRow(sheet); cell = row.createCell(0); cell.setCellStyle(boldText); cell.setCellValue("Method"); row.createCell(1).setCellValue(result.getName()); cell = row.createCell(0); cell.setCellStyle(boldText); cell.setCellValue("Success:"); row.createCell(1).setCellValue(result.isSuccess()); row = appendRow(sheet); cell = row.createCell(0); cell.setCellStyle(boldText); cell.setCellValue("TestNG timing"); row.createCell(1).setCellValue(result.getEndMillis() - result.getStartMillis()); row = appendRow(sheet); cell = row.createCell(0); cell.setCellStyle(boldText); cell.setCellValue("Perf test timing"); row.createCell(1).setCellValue(getTotalTime(timings)); row = appendRow(sheet); // Empty row row = appendRow(sheet); cell = row.createCell(0); cell.setCellStyle(boldText); cell.setCellValue("Individual Timings"); // Now the timings row = appendRow(sheet); cell = row.createCell(0); cell.setCellStyle(boldText); cell.setCellValue("Name"); cell = row.createCell(1); cell.setCellStyle(boldText); cell.setCellValue("Duration"); Set<Map.Entry<String, Long>> data = timings.entrySet(); SortedSet<Map.Entry<String, Long>> sorted = new TreeSet<Map.Entry<String, Long>>( new Comparator<Map.Entry<String, Long>>() { public int compare(Map.Entry<String, Long> item1, Map.Entry<String, Long> item2) { return item1.getKey().compareTo(item2.getKey()); } }); sorted.addAll(data); for (Map.Entry<String, Long> entry : sorted) { row = appendRow(sheet); cell = row.createCell(0); cell.setCellValue(entry.getKey()); cell = row.createCell(1); cell.setCellStyle(integerStyle); cell.setCellValue(entry.getValue()); } sheet.autoSizeColumn(0); sheet.autoSizeColumn(1); }
From source file:org.rhq.helpers.perftest.support.reporting.ExcelExporter.java
License:Open Source License
/** * Create a header row that describes the columns on the overview sheet * @param sheet sheet to write to./*from w w w.jav a 2 s . com*/ */ private void createOverviewHeaderIfNeeded(Sheet sheet) { Row row = sheet.getRow(0); if (row == null) row = sheet.createRow(0); Cell cell = row.createCell(0); cell.setCellStyle(boldText); cell.setCellValue("Name"); cell = row.createCell(1); cell.setCellStyle(boldText); cell.setCellValue("Success"); cell = row.createCell(2); cell.setCellStyle(boldText); cell.setCellValue("TestNG timing"); cell.setCellStyle(boldText); cell = row.createCell(3); cell.setCellValue("Perf timing"); cell.setCellStyle(boldText); sheet.autoSizeColumn(0); sheet.autoSizeColumn(2); sheet.autoSizeColumn(3); }
From source file:org.riflemansd.businessprofit.excel.MyExcelDocument.java
License:Open Source License
public void autoFillColumhWidth(int nsheet, int ncolumn) { Sheet sheet = workbook.getSheetAt(nsheet); sheet.autoSizeColumn(ncolumn); }
From source file:org.sleuthkit.autopsy.report.ReportXLS.java
License:Apache License
@Override public String generateReport(ReportConfiguration reportconfig) throws ReportModuleException { config = reportconfig;/* w ww .j a v a2 s. c om*/ ReportGen reportobj = new ReportGen(); reportobj.populateReport(reportconfig); HashMap<BlackboardArtifact, ArrayList<BlackboardAttribute>> report = reportobj.Results; Workbook wbtemp = new XSSFWorkbook(); int countGen = 0; int countBookmark = 0; int countCookie = 0; int countHistory = 0; int countDownload = 0; int countRecentObjects = 0; int countTrackPoint = 0; int countInstalled = 0; int countKeyword = 0; int countHash = 0; int countDevice = 0; int countEmail = 0; for (Entry<BlackboardArtifact, ArrayList<BlackboardAttribute>> entry : report.entrySet()) { if (entry.getKey().getArtifactTypeID() == BlackboardArtifact.ARTIFACT_TYPE.TSK_GEN_INFO.getTypeID()) { countGen++; } if (entry.getKey().getArtifactTypeID() == BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_BOOKMARK .getTypeID()) { countBookmark++; } if (entry.getKey().getArtifactTypeID() == BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_COOKIE.getTypeID()) { countCookie++; } if (entry.getKey().getArtifactTypeID() == BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_HISTORY .getTypeID()) { countHistory++; } if (entry.getKey().getArtifactTypeID() == BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_DOWNLOAD .getTypeID()) { countDownload++; } if (entry.getKey().getArtifactTypeID() == BlackboardArtifact.ARTIFACT_TYPE.TSK_RECENT_OBJECT .getTypeID()) { countRecentObjects++; } if (entry.getKey().getArtifactTypeID() == BlackboardArtifact.ARTIFACT_TYPE.TSK_TRACKPOINT.getTypeID()) { countTrackPoint++; } if (entry.getKey().getArtifactTypeID() == BlackboardArtifact.ARTIFACT_TYPE.TSK_INSTALLED_PROG .getTypeID()) { countInstalled++; } if (entry.getKey().getArtifactTypeID() == BlackboardArtifact.ARTIFACT_TYPE.TSK_KEYWORD_HIT .getTypeID()) { countKeyword++; } if (entry.getKey().getArtifactTypeID() == BlackboardArtifact.ARTIFACT_TYPE.TSK_HASHSET_HIT .getTypeID()) { countHash++; } if (entry.getKey().getArtifactTypeID() == BlackboardArtifact.ARTIFACT_TYPE.TSK_DEVICE_ATTACHED .getTypeID()) { countDevice++; } if (entry.getKey().getArtifactTypeID() == BlackboardArtifact.ARTIFACT_TYPE.TSK_EMAIL_MSG.getTypeID()) { countEmail++; } } try { Case currentCase = Case.getCurrentCase(); // get the most updated case SleuthkitCase skCase = currentCase.getSleuthkitCase(); String caseName = currentCase.getName(); Integer imagecount = currentCase.getImageIDs().length; Integer filesystemcount = currentCase.getRootObjectsCount(); Integer totalfiles = skCase.countFsContentType(TskData.TSK_FS_META_TYPE_ENUM.TSK_FS_META_TYPE_REG); Integer totaldirs = skCase.countFsContentType(TskData.TSK_FS_META_TYPE_ENUM.TSK_FS_META_TYPE_DIR); DateFormat datetimeFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); DateFormat dateFormat = new SimpleDateFormat("MM-dd-yyyy-HH-mm-ss"); Date date = new Date(); String datetime = datetimeFormat.format(date); String datenotime = dateFormat.format(date); //The first summary report page Sheet sheetSummary = wbtemp.createSheet("Summary"); //Generate a sheet per artifact type // Sheet sheetGen = wbtemp.createSheet(BlackboardArtifact.ARTIFACT_TYPE.TSK_GEN_INFO.getDisplayName()); Sheet sheetHash = wbtemp.createSheet(BlackboardArtifact.ARTIFACT_TYPE.TSK_HASHSET_HIT.getDisplayName()); Sheet sheetDevice = wbtemp .createSheet(BlackboardArtifact.ARTIFACT_TYPE.TSK_DEVICE_ATTACHED.getDisplayName()); Sheet sheetInstalled = wbtemp .createSheet(BlackboardArtifact.ARTIFACT_TYPE.TSK_INSTALLED_PROG.getDisplayName()); Sheet sheetKeyword = wbtemp .createSheet(BlackboardArtifact.ARTIFACT_TYPE.TSK_KEYWORD_HIT.getDisplayName()); // Sheet sheetTrackpoint = wbtemp.createSheet(BlackboardArtifact.ARTIFACT_TYPE.TSK_TRACKPOINT.getDisplayName()); Sheet sheetRecent = wbtemp .createSheet(BlackboardArtifact.ARTIFACT_TYPE.TSK_RECENT_OBJECT.getDisplayName()); Sheet sheetCookie = wbtemp .createSheet(BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_COOKIE.getDisplayName()); Sheet sheetBookmark = wbtemp .createSheet(BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_BOOKMARK.getDisplayName()); Sheet sheetDownload = wbtemp .createSheet(BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_DOWNLOAD.getDisplayName()); Sheet sheetHistory = wbtemp .createSheet(BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_HISTORY.getDisplayName()); Sheet sheetEmail = wbtemp.createSheet(BlackboardArtifact.ARTIFACT_TYPE.TSK_EMAIL_MSG.getDisplayName()); //Bold/underline cell style for the top header rows CellStyle style = wbtemp.createCellStyle(); style.setBorderBottom((short) 2); Font font = wbtemp.createFont(); font.setFontHeightInPoints((short) 14); font.setFontName("Arial"); font.setBoldweight((short) 2); style.setFont(font); //create 'default' style CellStyle defaultstyle = wbtemp.createCellStyle(); defaultstyle.setBorderBottom((short) 2); Font defaultfont = wbtemp.createFont(); defaultfont.setFontHeightInPoints((short) 14); defaultfont.setFontName("Arial"); defaultfont.setBoldweight((short) 2); defaultstyle.setFont(defaultfont); //create the rows in the worksheet for our records //Create first row and header // sheetGen.createRow(0); // sheetGen.getRow(0).createCell(0).setCellValue("Name"); // sheetGen.getRow(0).createCell(1).setCellValue("Value"); // sheetGen.getRow(0).createCell(2).setCellValue("Date/Time"); sheetSummary.setDefaultColumnStyle(1, defaultstyle); sheetSummary.createRow(0).setRowStyle(style); sheetSummary.getRow(0).createCell(0).setCellValue("Summary Information"); sheetSummary.getRow(0).createCell(1).setCellValue(caseName); //add some basic information sheetSummary.createRow(1).setRowStyle(defaultstyle); sheetSummary.getRow(1).createCell(0).setCellValue("# of Images"); sheetSummary.getRow(1).createCell(1).setCellValue(imagecount); sheetSummary.createRow(2); sheetSummary.getRow(2).createCell(0).setCellValue("Filesystems found"); sheetSummary.getRow(2).createCell(1).setCellValue(imagecount); sheetSummary.createRow(3); sheetSummary.getRow(3).createCell(0).setCellValue("# of Files"); sheetSummary.getRow(3).createCell(1).setCellValue(totalfiles); sheetSummary.createRow(4); sheetSummary.getRow(4).createCell(0).setCellValue("# of Directories"); sheetSummary.getRow(4).createCell(1).setCellValue(totaldirs); sheetSummary.createRow(5); sheetSummary.getRow(5).createCell(0).setCellValue("Date/Time"); sheetSummary.getRow(5).createCell(1).setCellValue(datetime); sheetHash.setDefaultColumnStyle(1, defaultstyle); sheetHash.createRow(0).setRowStyle(style); sheetHash.getRow(0).createCell(0).setCellValue("Name"); sheetHash.getRow(0).createCell(1).setCellValue("Size"); sheetHash.getRow(0).createCell(2).setCellValue("Hashset Name"); sheetDevice.setDefaultColumnStyle(1, defaultstyle); sheetDevice.createRow(0).setRowStyle(style); sheetDevice.getRow(0).createCell(0).setCellValue("Name"); sheetDevice.getRow(0).createCell(1).setCellValue("Serial #"); sheetDevice.getRow(0).createCell(2).setCellValue("Time"); sheetInstalled.setDefaultColumnStyle(1, defaultstyle); sheetInstalled.createRow(0).setRowStyle(style); sheetInstalled.getRow(0).createCell(0).setCellValue("Program Name"); sheetInstalled.getRow(0).createCell(1).setCellValue("Install Date/Time"); sheetKeyword.setDefaultColumnStyle(1, defaultstyle); sheetKeyword.createRow(0).setRowStyle(style); sheetKeyword.getRow(0).createCell(0).setCellValue("Keyword"); sheetKeyword.getRow(0).createCell(1).setCellValue("File Name"); sheetKeyword.getRow(0).createCell(2).setCellValue("Preview"); sheetKeyword.getRow(0).createCell(3).setCellValue("Keyword List"); sheetRecent.setDefaultColumnStyle(1, defaultstyle); sheetRecent.createRow(0).setRowStyle(style); sheetRecent.getRow(0).createCell(0).setCellValue("Name"); sheetRecent.getRow(0).createCell(1).setCellValue("Path"); sheetRecent.getRow(0).createCell(2).setCellValue("Related Shortcut"); sheetCookie.setDefaultColumnStyle(1, defaultstyle); sheetCookie.createRow(0).setRowStyle(style); sheetCookie.getRow(0).createCell(0).setCellValue("URL"); sheetCookie.getRow(0).createCell(1).setCellValue("Date"); sheetCookie.getRow(0).createCell(2).setCellValue("Name"); sheetCookie.getRow(0).createCell(3).setCellValue("Value"); sheetCookie.getRow(0).createCell(4).setCellValue("Program"); sheetBookmark.setDefaultColumnStyle(1, defaultstyle); sheetBookmark.createRow(0).setRowStyle(style); sheetBookmark.getRow(0).createCell(0).setCellValue("URL"); sheetBookmark.getRow(0).createCell(1).setCellValue("Title"); sheetBookmark.getRow(0).createCell(2).setCellValue("Program"); sheetDownload.setDefaultColumnStyle(1, defaultstyle); sheetDownload.createRow(0).setRowStyle(style); sheetDownload.getRow(0).createCell(0).setCellValue("File"); sheetDownload.getRow(0).createCell(1).setCellValue("Source"); sheetDownload.getRow(0).createCell(2).setCellValue("Time"); sheetDownload.getRow(0).createCell(3).setCellValue("Program"); sheetHistory.setDefaultColumnStyle(1, defaultstyle); sheetHistory.createRow(0).setRowStyle(style); sheetHistory.getRow(0).createCell(0).setCellValue("URL"); sheetHistory.getRow(0).createCell(1).setCellValue("Date"); sheetHistory.getRow(0).createCell(2).setCellValue("Referrer"); sheetHistory.getRow(0).createCell(3).setCellValue("Title"); sheetHistory.getRow(0).createCell(4).setCellValue("Program"); sheetEmail.setDefaultColumnStyle(1, defaultstyle); sheetEmail.createRow(0).setRowStyle(style); sheetEmail.getRow(0).createCell(0).setCellValue("From"); sheetEmail.getRow(0).createCell(1).setCellValue("To"); sheetEmail.getRow(0).createCell(2).setCellValue("Subject"); sheetEmail.getRow(0).createCell(3).setCellValue("Date/Time"); sheetEmail.getRow(0).createCell(4).setCellValue("Content"); sheetEmail.getRow(0).createCell(5).setCellValue("CC"); sheetEmail.getRow(0).createCell(6).setCellValue("BCC"); sheetEmail.getRow(0).createCell(7).setCellValue("Path"); for (int i = 0; i < wbtemp.getNumberOfSheets(); i++) { Sheet tempsheet = wbtemp.getSheetAt(i); tempsheet.setAutobreaks(true); for (Row temprow : tempsheet) { for (Cell cell : temprow) { cell.setCellStyle(style); tempsheet.autoSizeColumn(cell.getColumnIndex()); } } } int countedGen = 0; int countedBookmark = 0; int countedCookie = 0; int countedHistory = 0; int countedDownload = 0; int countedRecentObjects = 0; int countedTrackPoint = 0; int countedInstalled = 0; int countedKeyword = 0; int countedHash = 0; int countedDevice = 0; int countedEmail = 0; //start populating the sheets in the workbook for (Entry<BlackboardArtifact, ArrayList<BlackboardAttribute>> entry : report.entrySet()) { if (ReportFilter.cancel == true) { break; } int cc = 0; Long objId = entry.getKey().getObjectID(); AbstractFile file = skCase.getAbstractFileById(objId); String filename = file.getName(); Long filesize = file.getSize(); TreeMap<Integer, String> attributes = new TreeMap<Integer, String>(); // Get all the attributes, line them up to be added. Place empty string placeholders for each attribute type int n; for (n = 1; n <= 36; n++) { attributes.put(n, ""); } for (BlackboardAttribute tempatt : entry.getValue()) { if (ReportFilter.cancel == true) { break; } String value = ""; int type = tempatt.getAttributeTypeID(); if (tempatt.getAttributeTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_RCVD .getTypeID() || tempatt.getAttributeTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME .getTypeID() || tempatt.getAttributeTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_LAST_ACCESSED .getTypeID()) { value = new java.text.SimpleDateFormat("MM/dd/yyyy HH:mm:ss") .format(new java.util.Date((tempatt.getValueLong()) * 1000)).toString(); } else { value = tempatt.getValueString(); } attributes.put(type, StringEscapeUtils.escapeXml(value)); cc++; } if (entry.getKey().getArtifactTypeID() == BlackboardArtifact.ARTIFACT_TYPE.TSK_GEN_INFO .getTypeID()) { countedGen++; // Row temp = sheetGen.getRow(countedGen); } if (entry.getKey().getArtifactTypeID() == BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_BOOKMARK .getTypeID()) { countedBookmark++; Row temp = sheetBookmark.createRow(countedBookmark); temp.createCell(0) .setCellValue(attributes.get(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_URL.getTypeID())); temp.createCell(1) .setCellValue(attributes.get(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_NAME.getTypeID())); temp.createCell(2).setCellValue( attributes.get(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PROG_NAME.getTypeID())); } if (entry.getKey().getArtifactTypeID() == BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_COOKIE .getTypeID()) { countedCookie++; Row temp = sheetCookie.createRow(countedCookie); temp.createCell(0) .setCellValue(attributes.get(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_URL.getTypeID())); temp.createCell(1).setCellValue( attributes.get(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME.getTypeID())); temp.createCell(2) .setCellValue(attributes.get(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_NAME.getTypeID())); temp.createCell(3) .setCellValue(attributes.get(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_VALUE.getTypeID())); temp.createCell(4).setCellValue( attributes.get(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PROG_NAME.getTypeID())); } if (entry.getKey().getArtifactTypeID() == BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_HISTORY .getTypeID()) { countedHistory++; Row temp = sheetHistory.createRow(countedHistory); temp.createCell(0) .setCellValue(attributes.get(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_URL.getTypeID())); temp.createCell(1).setCellValue( attributes.get(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_LAST_ACCESSED.getTypeID())); temp.createCell(2).setCellValue( attributes.get(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_REFERRER.getTypeID())); temp.createCell(3) .setCellValue(attributes.get(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_NAME.getTypeID())); temp.createCell(4).setCellValue( attributes.get(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PROG_NAME.getTypeID())); } if (entry.getKey().getArtifactTypeID() == BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_DOWNLOAD .getTypeID()) { countedDownload++; Row temp = sheetDownload.createRow(countedDownload); temp.createCell(0) .setCellValue(attributes.get(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PATH.getTypeID())); temp.createCell(1) .setCellValue(attributes.get(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_URL.getTypeID())); temp.createCell(2).setCellValue( attributes.get(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_LAST_ACCESSED.getTypeID())); temp.createCell(3).setCellValue( attributes.get(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PROG_NAME.getTypeID())); } if (entry.getKey().getArtifactTypeID() == BlackboardArtifact.ARTIFACT_TYPE.TSK_RECENT_OBJECT .getTypeID()) { countedRecentObjects++; Row temp = sheetRecent.createRow(countedRecentObjects); temp.createCell(0) .setCellValue(attributes.get(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_NAME.getTypeID())); temp.createCell(1) .setCellValue(attributes.get(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PATH.getTypeID())); temp.createCell(2).setCellValue(file.getName()); temp.createCell(3).setCellValue( attributes.get(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PROG_NAME.getTypeID())); } if (entry.getKey().getArtifactTypeID() == BlackboardArtifact.ARTIFACT_TYPE.TSK_TRACKPOINT .getTypeID()) { // sheetTrackpoint.addContent(artifact); } if (entry.getKey().getArtifactTypeID() == BlackboardArtifact.ARTIFACT_TYPE.TSK_INSTALLED_PROG .getTypeID()) { countedInstalled++; Row temp = sheetInstalled.createRow(countedInstalled); temp.createCell(0).setCellValue( attributes.get(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PROG_NAME.getTypeID())); temp.createCell(1).setCellValue( attributes.get(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME.getTypeID())); } if (entry.getKey().getArtifactTypeID() == BlackboardArtifact.ARTIFACT_TYPE.TSK_KEYWORD_HIT .getTypeID()) { countedKeyword++; Row temp = sheetKeyword.createRow(countedKeyword); temp.createCell(0).setCellValue( attributes.get(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_KEYWORD.getTypeID())); temp.createCell(1).setCellValue(filename); temp.createCell(2).setCellValue( attributes.get(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_KEYWORD_PREVIEW.getTypeID())); temp.createCell(3).setCellValue( attributes.get(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SET_NAME.getTypeID())); } if (entry.getKey().getArtifactTypeID() == BlackboardArtifact.ARTIFACT_TYPE.TSK_HASHSET_HIT .getTypeID()) { countedHash++; Row temp = sheetHash.createRow(countedHash); temp.createCell(0).setCellValue(file.getName().toString()); temp.createCell(1).setCellValue(filesize.toString()); temp.createCell(2).setCellValue( attributes.get(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SET_NAME.getTypeID())); } if (entry.getKey().getArtifactTypeID() == BlackboardArtifact.ARTIFACT_TYPE.TSK_DEVICE_ATTACHED .getTypeID()) { countedDevice++; Row temp = sheetDevice.createRow(countedDevice); temp.createCell(0).setCellValue( attributes.get(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DEVICE_MODEL.getTypeID())); temp.createCell(1).setCellValue( attributes.get(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DEVICE_ID.getTypeID())); temp.createCell(2).setCellValue( attributes.get(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME.getTypeID())); } if (entry.getKey().getArtifactTypeID() == BlackboardArtifact.ARTIFACT_TYPE.TSK_EMAIL_MSG .getTypeID()) { countedEmail++; Row temp = sheetEmail.createRow(countedEmail); temp.createCell(0).setCellValue( attributes.get(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_EMAIL_FROM.getTypeID())); temp.createCell(1).setCellValue( attributes.get(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_EMAIL_TO.getTypeID())); temp.createCell(2).setCellValue( attributes.get(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SUBJECT.getTypeID())); temp.createCell(3).setCellValue( attributes.get(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_RCVD.getTypeID())); temp.createCell(4).setCellValue( attributes.get(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_EMAIL_CONTENT_PLAIN.getTypeID())); temp.createCell(5).setCellValue( attributes.get(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_EMAIL_CC.getTypeID())); temp.createCell(6).setCellValue( attributes.get(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_EMAIL_BCC.getTypeID())); temp.createCell(7) .setCellValue(attributes.get(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PATH.getTypeID())); } } //write out the report to the reports folder, set the wbtemp to the primary wb object wb = wbtemp; xlsPath = currentCase.getCaseDirectory() + File.separator + "Reports" + File.separator + caseName + "-" + datenotime + ".xlsx"; this.save(xlsPath); } catch (Exception E) { String test = E.toString(); } return xlsPath; }
From source file:org.wurtele.ifttt.watchers.WorkTimesWatcher.java
License:Open Source License
private void processFile(Path input) { logger.info("Updating " + output); try (Workbook wb = new XSSFWorkbook(); OutputStream out = Files.newOutputStream(output, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) { Sheet sheet = wb.createSheet("Time Sheet"); List<WorkDay> days = new ArrayList<>(); DateFormat df = new SimpleDateFormat("MMMM dd, yyyy 'at' hh:mma"); for (String line : Files.readAllLines(input)) { String[] data = line.split(";"); LocationType type = LocationType.valueOf(data[0].toUpperCase()); Date time = df.parse(data[1]); Date day = DateUtils.truncate(time, Calendar.DATE); WorkDay wd = new WorkDay(day); if (days.contains(wd)) wd = days.get(days.indexOf(wd)); else//from w w w. ja va 2 s . c om days.add(wd); wd.getTimes().add(new WorkTime(time, type)); } CreationHelper helper = wb.getCreationHelper(); Font bold = wb.createFont(); bold.setBoldweight(Font.BOLDWEIGHT_BOLD); CellStyle dateStyle = wb.createCellStyle(); dateStyle.setDataFormat(helper.createDataFormat().getFormat("MMMM d, yyyy")); CellStyle timeStyle = wb.createCellStyle(); timeStyle.setDataFormat(helper.createDataFormat().getFormat("h:mm AM/PM")); CellStyle headerStyle = wb.createCellStyle(); headerStyle.setAlignment(CellStyle.ALIGN_CENTER); headerStyle.setFont(bold); CellStyle totalStyle = wb.createCellStyle(); totalStyle.setAlignment(CellStyle.ALIGN_RIGHT); Row header = sheet.createRow(0); header.createCell(0).setCellValue("DATE"); header.getCell(0).setCellStyle(headerStyle); Collections.sort(days); for (int r = 0; r < days.size(); r++) { WorkDay day = days.get(r); Row row = sheet.createRow(r + 1); row.createCell(0).setCellValue(day.getDate()); row.getCell(0).setCellStyle(dateStyle); Collections.sort(day.getTimes()); for (int c = 0; c < day.getTimes().size(); c++) { WorkTime time = day.getTimes().get(c); if (sheet.getRow(0).getCell(c + 1) != null && !sheet.getRow(0).getCell(c + 1).getStringCellValue().equals(time.getType().name())) { throw new Exception("Invalid data"); } else if (sheet.getRow(0).getCell(c + 1) == null) { sheet.getRow(0).createCell(c + 1).setCellValue(time.getType().name()); sheet.getRow(0).getCell(c + 1).setCellStyle(headerStyle); } row.createCell(c + 1).setCellValue(time.getTime()); row.getCell(c + 1).setCellStyle(timeStyle); } } int totalCol = header.getLastCellNum(); header.createCell(totalCol).setCellValue("TOTAL"); header.getCell(totalCol).setCellStyle(headerStyle); for (int r = 0; r < days.size(); r++) { sheet.getRow(r + 1).createCell(totalCol).setCellValue(days.get(r).getTotal()); sheet.getRow(r + 1).getCell(totalCol).setCellStyle(totalStyle); } for (int c = 0; c <= totalCol; c++) { sheet.autoSizeColumn(c); } wb.write(out); } catch (Exception e) { logger.error("Failed to update " + output, e); } }
From source file:org.xmlportletfactory.olafk.customer.CustomerExporter.java
License:Open Source License
public static Workbook generateExcel(long groupId, boolean first, boolean showTypes, LinkedHashMap<String, String> dataHeaders) throws SystemException { Workbook book = new HSSFWorkbook(); Sheet sheet = book.createSheet(); int itRow = 0; int itCell = 0; Row row = null;/*w w w. j av a 2 s .c om*/ Cell cell = null; row = sheet.createRow(itRow); itRow++; if (showTypes) { Row row2 = sheet.createRow(itRow); itRow++; Cell cell2 = null; for (String key : dataHeaders.keySet()) { //Head cell = row.createCell(itCell); cell.setCellValue(key); //Types cell2 = row2.createCell(itCell); cell2.setCellValue(dataHeaders.get(key)); itCell++; } } else { for (String key : dataHeaders.keySet()) { //Head cell = row.createCell(itCell); cell.setCellValue(key); itCell++; } } List<Customer> listEntities = CustomerLocalServiceUtil.findAllInGroup(groupId); if (first) { if (listEntities.size() > 0) { row = sheet.createRow(itRow); Customer entity = listEntities.get(0); row = generateRow(entity, row); itRow++; } } else { for (Customer entity : listEntities) { row = sheet.createRow(itRow); row = generateRow(entity, row); itRow++; } } //Autosize columns for (int x = 0; x < (itCell + 1); x++) { sheet.autoSizeColumn(x); } return book; }
From source file:org.xmlportletfactory.olafk.customer.InvoicesExporter.java
License:Open Source License
public static Workbook generateExcel(long groupId, boolean first, boolean showTypes, LinkedHashMap<String, String> dataHeaders) throws SystemException { Workbook book = new HSSFWorkbook(); Sheet sheet = book.createSheet(); int itRow = 0; int itCell = 0; Row row = null;// ww w. j av a 2 s . co m Cell cell = null; row = sheet.createRow(itRow); itRow++; if (showTypes) { Row row2 = sheet.createRow(itRow); itRow++; Cell cell2 = null; for (String key : dataHeaders.keySet()) { //Head cell = row.createCell(itCell); cell.setCellValue(key); //Types cell2 = row2.createCell(itCell); cell2.setCellValue(dataHeaders.get(key)); itCell++; } } else { for (String key : dataHeaders.keySet()) { //Head cell = row.createCell(itCell); cell.setCellValue(key); itCell++; } } List<Invoices> listEntities = InvoicesLocalServiceUtil.findAllInGroup(groupId); if (first) { if (listEntities.size() > 0) { row = sheet.createRow(itRow); Invoices entity = listEntities.get(0); row = generateRow(entity, row); itRow++; } } else { for (Invoices entity : listEntities) { row = sheet.createRow(itRow); row = generateRow(entity, row); itRow++; } } //Autosize columns for (int x = 0; x < (itCell + 1); x++) { sheet.autoSizeColumn(x); } return book; }
From source file:org.zephyrsoft.sdb2.StatisticsController.java
License:Open Source License
public void exportStatisticsAll(SongsModel songs, File targetExcelFile) { // collect basic data Map<String, Song> songsByUUID = new HashMap<>(); for (Song song : songs) { songsByUUID.put(song.getUUID(), song); }/*from w ww. j a v a2s.c o m*/ List<String> months = statistics.getUsedMonths(); // create a new workbook Workbook workbook = new HSSFWorkbook(); // define formats CellStyle integerStyle = workbook.createCellStyle(); DataFormat df = workbook.createDataFormat(); integerStyle.setDataFormat(df.getFormat("0")); CellStyle textStyle = workbook.createCellStyle(); textStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("text")); CellStyle textBoldStyle = workbook.createCellStyle(); textBoldStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("text")); org.apache.poi.ss.usermodel.Font font = workbook.createFont(); font.setColor(org.apache.poi.ss.usermodel.Font.COLOR_RED); font.setBoldweight(org.apache.poi.ss.usermodel.Font.BOLDWEIGHT_BOLD); textBoldStyle.setFont(font); for (String month : months) { Map<String, Integer> monthStatsByUUID = statistics.getStatisticsForMonth(month); Map<Song, Integer> monthStatsBySong = new TreeMap<>(); for (String uuid : monthStatsByUUID.keySet()) { Song song = songs.getByUUID(uuid); if (song != null) { monthStatsBySong.put(song, monthStatsByUUID.get(uuid)); } else { LOG.info("no song found in database for UUID {}", uuid); } } Sheet sheet = workbook.createSheet(month); Row row = null; int rownum = 0; row = sheet.createRow(rownum); int cellnum = 0; addTextCell(row, cellnum++, textBoldStyle, "Presentation Count"); addTextCell(row, cellnum++, textBoldStyle, "Song Title"); addTextCell(row, cellnum++, textBoldStyle, "Composer (Music)"); addTextCell(row, cellnum++, textBoldStyle, "Author (Text)"); addTextCell(row, cellnum++, textBoldStyle, "Publisher"); addTextCell(row, cellnum++, textBoldStyle, "Copyright Notes"); addTextCell(row, cellnum++, textBoldStyle, "Song Lyrics"); rownum++; for (Song song : monthStatsBySong.keySet()) { row = sheet.createRow(rownum); cellnum = 0; addIntegerCell(row, cellnum++, integerStyle, monthStatsBySong.get(song)); addTextCell(row, cellnum++, textStyle, song.getTitle()); addTextCell(row, cellnum++, textStyle, song.getComposer()); addTextCell(row, cellnum++, textStyle, song.getAuthorText()); addTextCell(row, cellnum++, textStyle, song.getPublisher()); addTextCell(row, cellnum++, textStyle, song.getAdditionalCopyrightNotes()); addTextCell(row, cellnum++, textStyle, song.getLyrics()); rownum++; } for (int i = 0; i < cellnum; i++) { sheet.autoSizeColumn(i); } sheet.createFreezePane(0, 1); } try (FileOutputStream out = new FileOutputStream(targetExcelFile)) { workbook.write(out); out.close(); LOG.info("all statistics exported"); } catch (IOException e) { ErrorDialog.openDialog(null, "Could not export the statistics to:\n" + targetExcelFile.getAbsolutePath() + "\n\nPlease verify that you have write access and the file is not opened by any other program!"); LOG.warn("could not write statistics to file", e); } }