Example usage for org.apache.poi.ss.usermodel Workbook createCellStyle

List of usage examples for org.apache.poi.ss.usermodel Workbook createCellStyle

Introduction

In this page you can find the example usage for org.apache.poi.ss.usermodel Workbook createCellStyle.

Prototype

CellStyle createCellStyle();

Source Link

Document

Create a new Cell style and add it to the workbook's style table

Usage

From source file:org.sigmah.server.report.renderer.excel.ExcelPivotTableRenderer.java

License:Open Source License

@Override
public void render(Workbook book, PivotTableElement element) {

    /* Generate the actual pivot table data */

    final PivotTableData table = element.getContent().getData();

    /* Generate the excel sheet */

    new BaseExcelTableRenderer<PivotTableElement, PivotTableData.Axis>(book, element) {

        @Override//from w  w  w  .  ja v a2s  .  c  o m
        public List<FilterDescription> generateFilterDescriptions() {
            return element.getContent().getFilterDescriptions();
        }

        protected CellStyle[] rowHeaderStyles;

        @Override
        public void generate() {

            /* Initialize Cell Styles */

            initColHeaderStyles(table.getRootColumn());
            initRowHeaderStyles();

            /* Generate the column headers */

            generateColumnHeaders(1, table.getRootColumn());

            int headerHeight = rowIndex;

            /* Create the rows */
            // row headers are in column 1
            sheet.setColumnWidth(0, 40 * 256);
            generateRows(table.getRootRow().getChildList(), 0);

            /* Finalize the sheet */

            sheet.setRowSumsBelow(false);
            sheet.createFreezePane(1, headerHeight);

        }

        protected void initRowHeaderStyles() {

            int depth = table.getRootRow().getDepth();
            rowHeaderStyles = new CellStyle[depth];

            for (int i = 0; i != depth; ++i) {

                CellStyle style = book.createCellStyle();
                style.setIndention((short) i);
                style.setWrapText(true);

                Font font = createBaseFont();
                if (i + 1 != depth) {
                    /* Has sub headers */
                    font.setBoldweight(Font.BOLDWEIGHT_BOLD);
                } else {
                    font.setBoldweight(Font.BOLDWEIGHT_NORMAL);
                }
                style.setFont(font);

                rowHeaderStyles[i] = style;
            }
        }

        protected void generateRows(List<PivotTableData.Axis> rows, int indent) {

            for (PivotTableData.Axis pivotRow : rows) {

                Row row = sheet.createRow(rowIndex++);
                Cell headerCell = row.createCell(0);
                headerCell.setCellValue(factory.createRichTextString(pivotRow.getLabel()));
                headerCell.setCellStyle(rowHeaderStyles[indent]);

                if (pivotRow.isLeaf()) {

                    for (Entry<PivotTableData.Axis, Integer> entry : colIndexMap.entrySet()) {

                        PivotTableData.Cell pivotCell = pivotRow.getCell(entry.getKey());
                        if (pivotCell != null) {

                            Cell cell = row.createCell(entry.getValue());
                            cell.setCellValue(pivotCell.getValue());
                        }
                    }
                } else {

                    int groupStart = rowIndex;

                    generateRows(pivotRow.getChildList(), indent + 1);

                    int groupEnd = rowIndex;

                    sheet.groupRow(groupStart, groupEnd);
                }
            }
        }
    };
}

From source file:org.sleuthkit.autopsy.report.ReportXLS.java

License:Apache License

@Override
public String generateReport(ReportConfiguration reportconfig) throws ReportModuleException {
    config = reportconfig;/*from   ww  w  . j a v  a 2s  .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.spdx.spdxspreadsheet.AbstractSheet.java

License:Apache License

/**
 * create the styles in the workbook/*  w w  w .ja  v  a2 s.c o  m*/
 */
private void createStyles(Workbook wb) {
    // create the styles
    this.checkboxStyle = wb.createCellStyle();
    this.checkboxStyle.setAlignment(CellStyle.ALIGN_CENTER);
    this.checkboxStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    this.checkboxStyle.setBorderBottom(CellStyle.BORDER_THIN);
    this.checkboxStyle.setBorderLeft(CellStyle.BORDER_THIN);
    this.checkboxStyle.setBorderRight(CellStyle.BORDER_THIN);
    this.checkboxStyle.setBorderTop(CellStyle.BORDER_THIN);
    Font checkboxFont = wb.createFont();
    checkboxFont.setFontHeight(FONT_SIZE);
    checkboxFont.setFontName(CHECKBOX_FONT_NAME);
    this.checkboxStyle.setFont(checkboxFont);

    this.dateStyle = wb.createCellStyle();
    DataFormat df = wb.createDataFormat();
    this.dateStyle.setDataFormat(df.getFormat("m/d/yy h:mm"));
}

From source file:org.spdx.spdxspreadsheet.AbstractSheet.java

License:Apache License

public static CellStyle createHeaderStyle(Workbook wb) {
    CellStyle headerStyle = wb.createCellStyle();
    headerStyle.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);
    headerStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
    Font headerFont = wb.createFont();
    headerFont.setFontName("Arial");
    headerFont.setFontHeight(FONT_SIZE);
    headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    headerStyle.setFont(headerFont);//from   www.  j  a  v  a 2 s .  c  o m
    headerStyle.setAlignment(CellStyle.ALIGN_CENTER);
    return headerStyle;
}

From source file:org.spdx.spdxspreadsheet.AbstractSheet.java

License:Apache License

public static CellStyle createLeftWrapStyle(Workbook wb) {
    CellStyle wrapStyle = wb.createCellStyle();
    wrapStyle.setWrapText(true);/*  ww  w  . j  a va2  s  . co  m*/
    wrapStyle.setAlignment(CellStyle.ALIGN_LEFT);
    return wrapStyle;
}

From source file:org.spdx.spdxspreadsheet.AbstractSheet.java

License:Apache License

public static CellStyle createCenterStyle(Workbook wb) {
    CellStyle centerStyle = wb.createCellStyle();
    centerStyle.setWrapText(false);//from w  w w  . java2 s  .c  om
    centerStyle.setAlignment(CellStyle.ALIGN_CENTER);
    return centerStyle;
}

From source file:org.tiefaces.components.websheet.utility.CellUtility.java

License:MIT License

/**
 * create cell style from source cell./*from www  .  j  a v  a  2 s . c  om*/
 * 
 * @param destSheet
 *            dest sheet.
 * @param sourceCell
 *            source cell.
 * @return cell style.
 */
private static CellStyle getCellStyleFromSourceCell(final Sheet destSheet, final Cell sourceCell) {
    Workbook wb = destSheet.getWorkbook();
    // Copy style from old cell and apply to new cell
    CellStyle newCellStyle = wb.createCellStyle();
    newCellStyle.cloneStyleFrom(sourceCell.getCellStyle());
    return newCellStyle;
}

From source file:org.waterforpeople.mapping.dataexport.GraphicalSurveySummaryExporter.java

License:Open Source License

@Override
public void export(Map<String, String> criteria, File fileName, String serverBase,
        Map<String, String> options) {
    processOptions(options);/* w  w  w. j  a  v  a 2s  .  co  m*/
    if (!GraphicsEnvironment.isHeadless()) {
        progressDialog = new ProgressDialog(maxSteps, locale);
        progressDialog.setVisible(true);
    }
    questionsById = new HashMap<Long, QuestionDto>();
    currentStep = 1;
    this.serverBase = serverBase;
    PrintWriter pw = null;
    boolean useQuestionId = "true".equals(options.get("useQuestionId"));
    String from = options.get("from");
    String to = options.get("to");
    String limit = options.get("maxDataReportRows");
    try {
        SwingUtilities.invokeLater(new StatusUpdater(currentStep++, LOADING_QUESTIONS.get(locale)));

        List<SurveyGroupDto> sgs = fetchSurveyGroup(criteria.get(SurveyRestRequest.SURVEY_ID_PARAM), serverBase,
                criteria.get("apiKey"));

        if (sgs != null && !sgs.isEmpty()) {
            monitoringGroup = sgs.get(0).getMonitoringGroup();
        }

        Map<QuestionGroupDto, List<QuestionDto>> questionMap = loadAllQuestions(
                criteria.get(SurveyRestRequest.SURVEY_ID_PARAM), performGeoRollup, serverBase,
                criteria.get("apiKey"));
        if (questionMap != null) {
            for (List<QuestionDto> qList : questionMap.values()) {
                for (QuestionDto q : qList) {
                    questionsById.put(q.getKeyId(), q);
                    if (q.getLocaleNameFlag() != null && q.getLocaleNameFlag()) {
                        displayNameQuestionIds.add(q.getKeyId());
                    }
                }
            }
        }
        if (!DEFAULT_LOCALE.equals(locale) && questionMap.size() > 0) {
            // if we are using some other locale, we need to check for
            // translations
            SwingUtilities.invokeLater(new StatusUpdater(currentStep++, LOADING_DETAILS.get(locale)));
            loadFullQuestions(questionMap, criteria.get("apiKey"));
        } else {
            currentStep++;
        }
        Workbook wb = new SXSSFWorkbook(100);
        if (questionMap != null && questionMap.size() > 0) {

            headerStyle = wb.createCellStyle();
            headerStyle.setAlignment(CellStyle.ALIGN_CENTER);
            Font headerFont = wb.createFont();
            headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
            headerStyle.setFont(headerFont);

            SummaryModel model = fetchAndWriteRawData(criteria.get(SurveyRestRequest.SURVEY_ID_PARAM),
                    serverBase, questionMap, wb, isFullReport, fileName, criteria.get("apiKey"), lastCollection,
                    useQuestionId, from, to, limit);
            if (isFullReport) {
                SwingUtilities.invokeLater(new StatusUpdater(currentStep++, WRITING_SUMMARY.get(locale)));
                writeSummaryReport(questionMap, model, null, wb);
                SwingUtilities.invokeLater(new StatusUpdater(currentStep++, WRITING_ROLLUPS.get(locale)));
            }
            if (model.getSectorList() != null && model.getSectorList().size() > 0) {

                Collections.sort(model.getSectorList(), new Comparator<String>() {
                    @Override
                    public int compare(String o1, String o2) {
                        if (o1 != null && o2 != null) {
                            return o1.toLowerCase().compareTo(o2.toLowerCase());
                        } else {
                            return 0;
                        }
                    }
                });
                for (String sector : model.getSectorList()) {
                    writeSummaryReport(questionMap, model, sector, wb);
                }
            }

            FileOutputStream fileOut = new FileOutputStream(fileName);
            wb.setActiveSheet(isFullReport ? 1 : 0);
            wb.write(fileOut);
            fileOut.close();

            SwingUtilities.invokeLater(new StatusUpdater(currentStep++, COMPLETE.get(locale)));
        } else {
            log.info("No questions for survey: " + criteria.get(SurveyRestRequest.SURVEY_ID_PARAM)
                    + " - instance: " + serverBase);
        }

    } catch (Exception e) {
        log.error("Error generating report: " + e.getMessage(), e);
    } finally {
        if (pw != null) {
            pw.close();
        }
    }
}

From source file:org.xianairlines.action.staffs.StaffsList.java

public void exportStaffsByColumNames() throws UnsupportedEncodingException {
    ServletOutputStream os = null;//from   ww w. j  av a 2s .  co  m
    try {
        final HttpServletResponse response = (HttpServletResponse) extCtx.getResponse();
        os = response.getOutputStream();
        response.setContentType("application/x-download");
        final String newFileName = encodeFileName("??.xls");
        response.addHeader("Content-disposition", "attachment;filename=" + newFileName + ";charset=UTF-8");
        Workbook wb = new HSSFWorkbook();
        Sheet sheet1 = wb.createSheet("sheet1");
        Row row = null;
        Cell cell = null;
        CellStyle cellStyle = wb.createCellStyle();
        // ?
        cellStyle.setBorderBottom(CellStyle.BORDER_THIN);
        cellStyle.setBorderTop(CellStyle.BORDER_THIN);
        cellStyle.setBorderLeft(CellStyle.BORDER_THIN);
        cellStyle.setBorderRight(CellStyle.BORDER_THIN);
        // ?
        cellStyle.setRightBorderColor(IndexedColors.BLACK.getIndex());
        cellStyle.setLeftBorderColor(IndexedColors.BLACK.getIndex());
        cellStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex());
        cellStyle.setTopBorderColor(IndexedColors.BLACK.getIndex());
        cellStyle.setAlignment(CellStyle.ALIGN_CENTER);
        cellStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
        // Font
        Font font = wb.createFont();
        font.setFontName("");
        font.setColor(HSSFColor.BLUE.index);
        font.setItalic(true);
        font.setFontHeight((short) 300);
        row = sheet1.createRow(0);
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
        for (int i = 0; i < columNames.length; i++) {
            sheet1.setColumnWidth(i, (short) 6000);
            String[] colums = columNames[i].split(",");
            cell = row.createCell(i);
            cell.setCellStyle(cellStyle);
            cell.setCellValue(colums[1]);
        }
        List<Staffs> list = this.getResultList();
        for (int i = 1; i <= list.size(); i = i + 1) {
            row = sheet1.createRow(i);
            row.setHeightInPoints(20);
            for (int j = 0; j < columNames.length; j++) {
                String[] colums = columNames[j].split(",");
                cell = row.createCell(j);
                cell.setCellStyle(cellStyle);
                Object value = this.getStaffsFieldValue((Staffs) list.get(i - 1), colums[0]);
                if (value == null) {
                    cell.setCellValue("");
                } else if (value instanceof java.util.Date) {
                    String cellValue = dateFormat.format((java.util.Date) value);
                    cell.setCellValue(cellValue);
                } else {
                    cell.setCellValue(value.toString());
                }

            }
        }
        wb.write(os);
        os.flush();
    } catch (Exception e) {
    } finally {
        if (os != null) {
            try {
                os.close();
            } catch (IOException e) {
            }
        }
        facesContext.responseComplete();
    }

}

From source file:org.zafritech.zidingorms.io.excel.ExcelFunctions.java

private static CellStyle createBorderedStyle(Workbook wb) {

    CellStyle style = wb.createCellStyle();
    style.setBorderRight(BorderStyle.THIN);
    style.setRightBorderColor(IndexedColors.BLACK.getIndex());
    style.setBorderBottom(BorderStyle.THIN);
    style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
    style.setBorderLeft(BorderStyle.THIN);
    style.setLeftBorderColor(IndexedColors.BLACK.getIndex());
    style.setBorderTop(BorderStyle.THIN);
    style.setTopBorderColor(IndexedColors.BLACK.getIndex());

    return style;
}