Example usage for org.apache.poi.ss.usermodel Sheet setAutobreaks

List of usage examples for org.apache.poi.ss.usermodel Sheet setAutobreaks

Introduction

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

Prototype

void setAutobreaks(boolean value);

Source Link

Document

Flag indicating whether the sheet displays Automatic Page Breaks.

Usage

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. java2  s . c  o  m*/
    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:packtest.FitSheetToOnePage.java

License:Apache License

public static void main(String[] args) throws Exception {
    Workbook wb = new XSSFWorkbook(); //or new HSSFWorkbook();
    Sheet sheet = wb.createSheet("format sheet");
    PrintSetup ps = sheet.getPrintSetup();

    sheet.setAutobreaks(true);

    ps.setFitHeight((short) 1);
    ps.setFitWidth((short) 1);

    // Create various cells and rows for spreadsheet.

    FileOutputStream fileOut = new FileOutputStream("fitSheetToOnePage.xlsx");
    wb.write(fileOut);/*from w w w  .  j ava  2s  .  c  o  m*/
    fileOut.close();

}

From source file:ro.dabuno.office.integration.BusinessPlan.java

License:Apache License

public static void main(String[] args) throws Exception {
    Workbook wb;/*from   w w w. ja  v a  2 s .c  o m*/

    if (args.length > 0 && args[0].equals("-xls"))
        wb = new HSSFWorkbook();
    else
        wb = new XSSFWorkbook();

    Map<String, CellStyle> styles = createStyles(wb);

    Sheet sheet = wb.createSheet("Business Plan");

    //turn off gridlines
    sheet.setDisplayGridlines(false);
    sheet.setPrintGridlines(false);
    sheet.setFitToPage(true);
    sheet.setHorizontallyCenter(true);
    PrintSetup printSetup = sheet.getPrintSetup();
    printSetup.setLandscape(true);

    //the following three statements are required only for HSSF
    sheet.setAutobreaks(true);
    printSetup.setFitHeight((short) 1);
    printSetup.setFitWidth((short) 1);

    //the header row: centered text in 48pt font
    Row headerRow = sheet.createRow(0);
    headerRow.setHeightInPoints(12.75f);
    for (int i = 0; i < titles.length; i++) {
        Cell cell = headerRow.createCell(i);
        cell.setCellValue(titles[i]);
        cell.setCellStyle(styles.get("header"));
    }
    //columns for 11 weeks starting from 9-Jul
    Calendar calendar = Calendar.getInstance();
    int year = calendar.get(Calendar.YEAR);

    calendar.setTime(fmt.parse("9-Jul"));
    calendar.set(Calendar.YEAR, year);
    for (int i = 0; i < 11; i++) {
        Cell cell = headerRow.createCell(titles.length + i);
        cell.setCellValue(calendar);
        cell.setCellStyle(styles.get("header_date"));
        calendar.roll(Calendar.WEEK_OF_YEAR, true);
    }
    //freeze the first row
    sheet.createFreezePane(0, 1);

    Row row;
    Cell cell;
    int rownum = 1;
    for (int i = 0; i < data.length; i++, rownum++) {
        row = sheet.createRow(rownum);
        if (data[i] == null)
            continue;

        for (int j = 0; j < data[i].length; j++) {
            cell = row.createCell(j);
            String styleName;
            boolean isHeader = i == 0 || data[i - 1] == null;
            switch (j) {
            case 0:
                if (isHeader) {
                    styleName = "cell_b";
                    cell.setCellValue(Double.parseDouble(data[i][j]));
                } else {
                    styleName = "cell_normal";
                    cell.setCellValue(data[i][j]);
                }
                break;
            case 1:
                if (isHeader) {
                    styleName = i == 0 ? "cell_h" : "cell_bb";
                } else {
                    styleName = "cell_indented";
                }
                cell.setCellValue(data[i][j]);
                break;
            case 2:
                styleName = isHeader ? "cell_b" : "cell_normal";
                cell.setCellValue(data[i][j]);
                break;
            case 3:
                styleName = isHeader ? "cell_b_centered" : "cell_normal_centered";
                cell.setCellValue(Integer.parseInt(data[i][j]));
                break;
            case 4: {
                calendar.setTime(fmt.parse(data[i][j]));
                calendar.set(Calendar.YEAR, year);
                cell.setCellValue(calendar);
                styleName = isHeader ? "cell_b_date" : "cell_normal_date";
                break;
            }
            case 5: {
                int r = rownum + 1;
                String fmla = "IF(AND(D" + r + ",E" + r + "),E" + r + "+D" + r + ",\"\")";
                cell.setCellFormula(fmla);
                styleName = isHeader ? "cell_bg" : "cell_g";
                break;
            }
            default:
                styleName = data[i][j] != null ? "cell_blue" : "cell_normal";
            }

            cell.setCellStyle(styles.get(styleName));
        }
    }

    //group rows for each phase, row numbers are 0-based
    sheet.groupRow(4, 6);
    sheet.groupRow(9, 13);
    sheet.groupRow(16, 18);

    //set column widths, the width is measured in units of 1/256th of a character width
    sheet.setColumnWidth(0, 256 * 6);
    sheet.setColumnWidth(1, 256 * 33);
    sheet.setColumnWidth(2, 256 * 20);
    sheet.setZoom(75); //75% scale

    // Write the output to a file
    String file = "businessplan.xls";
    if (wb instanceof XSSFWorkbook)
        file += "x";
    FileOutputStream out = new FileOutputStream(file);
    wb.write(out);
    out.close();

    wb.close();
}

From source file:sample.poi.CalendarDemo.java

License:Apache License

public static void main(String[] args) throws Exception {

    Calendar calendar = Calendar.getInstance();

    SimpleDateFormat formatFile = new SimpleDateFormat("dd-MM-yyyy-hh-mm-ss");

    HSSFWorkbook wb = new HSSFWorkbook();

    Map<String, CellStyle> styles = createStyles(wb);

    for (int month = 0; month < 12; month++) {
        calendar.set(Calendar.MONTH, month);
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        //create a sheet for each month
        Sheet sheet = wb.createSheet(months[month]);

        //turn off gridlines
        sheet.setDisplayGridlines(false);
        sheet.setPrintGridlines(false);//ww  w .j av  a2 s . co  m
        sheet.setFitToPage(true);
        sheet.setHorizontallyCenter(true);
        PrintSetup printSetup = sheet.getPrintSetup();
        printSetup.setLandscape(true);

        //the following three statements are required only for HSSF
        sheet.setAutobreaks(true);
        printSetup.setFitHeight((short) 1);
        printSetup.setFitWidth((short) 1);

        //the header row: centered text in 48pt font
        Row headerRow = sheet.createRow(0);
        headerRow.setHeightInPoints(80);
        Cell titleCell = headerRow.createCell(0);
        titleCell.setCellValue(months[month] + " " + "2013");
        titleCell.setCellStyle(styles.get("title"));
        sheet.addMergedRegion(CellRangeAddress.valueOf("$A$1:$N$1"));

        //header with month titles
        Row monthRow = sheet.createRow(1);
        for (int i = 0; i < days.length; i++) {
            //set column widths, the width is measured in units of 1/256th of a character width
            sheet.setColumnWidth(i * 2, 5 * 256); //the column is 5 characters wide
            sheet.setColumnWidth(i * 2 + 1, 13 * 256); //the column is 13 characters wide
            sheet.addMergedRegion(new CellRangeAddress(1, 1, i * 2, i * 2 + 1));
            Cell monthCell = monthRow.createCell(i * 2);
            monthCell.setCellValue(days[i]);
            monthCell.setCellStyle(styles.get("month"));
        }

        int cnt = 1, day = 1;
        int rownum = 2;
        for (int j = 0; j < 6; j++) {
            Row row = sheet.createRow(rownum++);
            row.setHeightInPoints(100);
            for (int i = 0; i < days.length; i++) {
                Cell dayCell_1 = row.createCell(i * 2);
                Cell dayCell_2 = row.createCell(i * 2 + 1);

                int day_of_week = calendar.get(Calendar.DAY_OF_WEEK);
                if (cnt >= day_of_week && calendar.get(Calendar.MONTH) == month) {
                    dayCell_1.setCellValue(day);
                    calendar.set(Calendar.DAY_OF_MONTH, ++day);

                    if (i == 0 || i == days.length - 1) {
                        dayCell_1.setCellStyle(styles.get("weekend_left"));
                        dayCell_2.setCellStyle(styles.get("weekend_right"));
                    } else {
                        dayCell_1.setCellStyle(styles.get("workday_left"));
                        dayCell_2.setCellStyle(styles.get("workday_right"));
                    }
                } else {
                    dayCell_1.setCellStyle(styles.get("grey_left"));
                    dayCell_2.setCellStyle(styles.get("grey_right"));
                }
                cnt++;
            }
            if (calendar.get(Calendar.MONTH) > month)
                break;
        }
    }

    // Write the output to a file
    String file = "calendar.xls";

    FileOutputStream out = new FileOutputStream(file);
    wb.write(out);
    out.close();
}