Example usage for org.apache.poi.ss.usermodel Font setFontName

List of usage examples for org.apache.poi.ss.usermodel Font setFontName

Introduction

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

Prototype


void setFontName(String name);

Source Link

Document

set the name for the font (i.e.

Usage

From source file:org.primefaces.extensions.showcase.util.ExcelCustomExporter.java

License:Apache License

protected void createCustomFonts() {

    Font facetFont = wb.createFont();
    Font cellFont = wb.createFont();

    if (cellFontColor != null) {
        XSSFColor cellColor = new XSSFColor(cellFontColor);
        ((XSSFFont) cellFont).setColor(cellColor);
    }//from  w ww.  ja  v  a2  s.c  o  m
    if (cellFontSize != null) {
        cellFont.setFontHeightInPoints(cellFontSize);
    }

    if (cellFontStyle.equalsIgnoreCase("BOLD")) {
        cellFont.setBold(true);
    }
    if (cellFontStyle.equalsIgnoreCase("ITALIC")) {
        cellFont.setItalic(true);
    }

    if (facetFontStyle.equalsIgnoreCase("BOLD")) {
        facetFont.setBold(true);
    }
    if (facetFontStyle.equalsIgnoreCase("ITALIC")) {
        facetFont.setItalic(true);
    }

    if (fontName != null) {
        cellFont.setFontName(fontName);
        facetFont.setFontName(fontName);
    }

    cellStyle.setFont(cellFont);

    if (facetBackground != null) {
        XSSFColor backgroundColor = new XSSFColor(facetBackground);
        ((XSSFCellStyle) facetStyle).setFillForegroundColor(backgroundColor);
        facetStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);

    }

    if (facetFontColor != null) {
        XSSFColor facetColor = new XSSFColor(facetFontColor);
        ((XSSFFont) facetFont).setColor(facetColor);

    }
    if (facetFontSize != null) {
        facetFont.setFontHeightInPoints(facetFontSize);
    }

    facetStyle.setFont(facetFont);
    facetStyle.setAlignment(HorizontalAlignment.CENTER);

}

From source file:org.sakaiproject.jsf.spreadsheet.SpreadsheetDataFileWriterXlsx.java

License:Educational Community License

private Workbook getAsWorkbook(List<List<Object>> spreadsheetData) {
    Workbook wb = new SXSSFWorkbook();
    Sheet sheet = wb.createSheet();/*from   ww w .  j  a  va 2s  .  co  m*/
    CellStyle headerCs = wb.createCellStyle();
    Iterator<List<Object>> dataIter = spreadsheetData.iterator();

    // Set the header style
    headerCs.setBorderBottom(BorderStyle.THICK);
    headerCs.setFillBackgroundColor(IndexedColors.BLUE_GREY.getIndex());

    // Set the font
    CellStyle cellStyle = null;
    String fontName = ServerConfigurationService.getString("spreadsheet.font");
    if (fontName != null) {
        Font font = wb.createFont();
        font.setFontName(fontName);
        headerCs.setFont(font);
        cellStyle = wb.createCellStyle();
        cellStyle.setFont(font);
    }

    // By convention, the first list in the list contains column headers.
    Row headerRow = sheet.createRow((short) 0);
    List<Object> headerList = dataIter.next();
    for (short i = 0; i < headerList.size(); i++) {
        Cell headerCell = createCell(headerRow, i);
        headerCell.setCellValue((String) headerList.get(i));
        headerCell.setCellStyle(headerCs);
        //TODO
        //sheet.autoSizeColumn(i);
    }

    short rowPos = 1;
    while (dataIter.hasNext()) {
        List<Object> rowData = dataIter.next();
        Row row = sheet.createRow(rowPos++);
        for (short i = 0; i < rowData.size(); i++) {
            Cell cell = createCell(row, i);
            Object data = rowData.get(i);
            if (data != null) {
                if (data instanceof Double) {
                    cell.setCellValue(((Double) data).doubleValue());
                } else {
                    cell.setCellValue(data.toString());
                }
                if (cellStyle != null) {
                    cell.setCellStyle(cellStyle);
                }
            }
        }
    }

    return wb;
}

From source file:org.sakaiproject.signup.tool.downloadEvents.WorksheetStyleClass.java

License:Educational Community License

public static Map<String, CellStyle> createStyles(Workbook wb) {
    Map<String, CellStyle> styles = new HashMap<String, CellStyle>();
    CellStyle style;//from  w ww  .  j a va  2s  .co  m
    Font titleFont = wb.createFont();
    titleFont.setFontHeightInPoints((short) 18);
    titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    titleFont.setColor(IndexedColors.DARK_BLUE.getIndex());
    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setFont(titleFont);
    styles.put("title", style);

    Font commentTitleFont = wb.createFont();
    commentTitleFont.setFontHeightInPoints((short) 12);
    commentTitleFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    commentTitleFont.setColor(IndexedColors.DARK_BLUE.getIndex());
    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_LEFT);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setFont(commentTitleFont);
    styles.put("commentTitle", style);

    Font itemFont = wb.createFont();
    itemFont.setFontHeightInPoints((short) 10);
    itemFont.setFontName("Trebuchet MS");
    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_LEFT);
    style.setFont(itemFont);
    styles.put("item_left", style);

    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_LEFT);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setFont(itemFont);
    style.setWrapText(true);
    styles.put("item_left_wrap", style);

    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_LEFT);
    style.setVerticalAlignment(CellStyle.VERTICAL_TOP);
    style.setFont(itemFont);
    style.setWrapText(true);
    styles.put("item_left_wrap_top", style);

    itemFont.setFontHeightInPoints((short) 10);
    itemFont.setFontName("Trebuchet MS");
    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setFont(itemFont);
    styles.put("tabItem_fields", style);

    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_RIGHT);
    style.setFont(itemFont);
    styles.put("item_right", style);

    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setFont(itemFont);
    style.setWrapText(true);
    styles.put("attendee_layout", style);

    Font itemBoldFont = wb.createFont();
    itemBoldFont.setFontHeightInPoints((short) 10);
    itemBoldFont.setFontName("Trebuchet MS");
    itemBoldFont.setColor(IndexedColors.DARK_BLUE.getIndex());
    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_LEFT);
    style.setVerticalAlignment(CellStyle.VERTICAL_TOP);
    itemBoldFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    style.setFont(itemBoldFont);
    styles.put("item_leftBold", style);

    Font tableFont = wb.createFont();
    tableFont.setFontHeightInPoints((short) 12);
    tableFont.setColor(IndexedColors.WHITE.getIndex());
    tableFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setFillForegroundColor(IndexedColors.DARK_BLUE.getIndex());
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    style.setFont(tableFont);
    styles.put("tabColNames", style);

    tableFont.setFontHeightInPoints((short) 10);
    tableFont.setColor(IndexedColors.WHITE.getIndex());
    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex());
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    style.setFont(tableFont);
    style.setWrapText(true);
    styles.put("header", style);

    Font linkFont = wb.createFont();
    linkFont.setFontHeightInPoints((short) 10);
    linkFont.setColor(IndexedColors.BLUE.getIndex());
    linkFont.setUnderline(Font.U_SINGLE);
    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_LEFT);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setFont(linkFont);
    styles.put("hyperLink", style);

    style = wb.createCellStyle();
    style.setBorderTop(CellStyle.BORDER_THICK);
    style.setTopBorderColor(IndexedColors.DARK_BLUE.getIndex());
    styles.put("tab_endline", style);

    return styles;
}

From source file:org.sakaiproject.tool.assessment.ui.bean.evaluation.ExportResponsesBean.java

License:Educational Community License

public Workbook getAsWorkbook(List<List<Object>> spreadsheetData) {
    // outer list is rows, inner list is columns (cells in the row)
    int columns = findColumnSize(spreadsheetData);
    Workbook wb;/*from  w  w  w  . j  a  v  a  2 s . c o  m*/
    if (columns < 255) {
        log.info("Samigo export (" + columns + " columns): Using xsl format");
        wb = new HSSFWorkbook();
    } else {
        // allows for greater than 255 columns - SAK-16560
        log.info("Samigo export (" + columns + " columns): Using xslx format");
        wb = new XSSFWorkbook();
    }

    CellStyle boldStyle = wb.createCellStyle();
    Font font = wb.createFont();
    font.setBoldweight(Font.BOLDWEIGHT_BOLD);
    String fontName = ServerConfigurationService.getString("spreadsheet.font");
    if (fontName != null) {
        font.setFontName(fontName);
    }
    boldStyle.setFont(font);
    CellStyle headerStyle = boldStyle;

    CellStyle cellStyle = null;
    if (fontName != null) {
        font = wb.createFont();
        font.setFontName(fontName);
        cellStyle = wb.createCellStyle();
        cellStyle.setFont(font);
    }

    Sheet sheet = null;

    Iterator<List<Object>> dataIter = spreadsheetData.iterator();

    short rowPos = 0;
    while (dataIter.hasNext()) {
        List<Object> rowData = dataIter.next();

        if (rowData.get(0).toString().equals(NEW_SHEET_MARKER)) {
            sheet = wb.createSheet(rowData.get(1).toString());
            rowPos = 0;
        }
        // By convention, the first list in the list contains column headers.
        // This should only happen once and usually only in a single-sheet workbook
        else if (rowData.get(0).toString().equals(HEADER_MARKER)) {
            if (sheet == null) {
                sheet = wb.createSheet("responses"); // avoid NPE
            }
            Row headerRow = sheet.createRow(rowPos++);
            for (short i = 0; i < rowData.size() - 1; i++) {
                createCell(headerRow, i, headerStyle).setCellValue(rowData.get(i + 1).toString());
            }
        } else {
            if (sheet == null) {
                sheet = wb.createSheet("responses"); // avoid NPE
            }
            Row row = sheet.createRow(rowPos++);
            short colPos = 0;
            Iterator colIter = rowData.iterator();
            while (colIter.hasNext()) {
                //for (short i = 0; i < rowData.size(); i++) {
                Cell cell = null;

                //Object data = rowData.get(i);
                Object data = colIter.next();
                if (data != null) {
                    if (data.toString().startsWith(FORMAT)) {
                        if (data.equals(FORMAT_BOLD)) {
                            cell = createCell(row, colPos++, boldStyle);
                        }
                        data = colIter.next();
                    } else {
                        cell = createCell(row, colPos++, cellStyle);
                    }
                    if (data != null) {
                        if (data instanceof Double) {
                            cell.setCellValue(((Double) data).doubleValue());
                        } else {
                            AnswerSurveyConverter converter = new AnswerSurveyConverter();
                            String datac = converter.getAsString(null, null, data.toString());
                            // stripping html for export, SAK-17021
                            cell.setCellValue(FormattedText.convertFormattedTextToPlaintext(datac));
                        }
                    }
                }
            }
        }

    }

    return wb;
}

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

License:Apache License

@Override
public String generateReport(ReportConfiguration reportconfig) throws ReportModuleException {
    config = reportconfig;// w  w  w  .  j  av  a2  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:org.spdx.spdxspreadsheet.AbstractSheet.java

License:Apache License

/**
 * create the styles in the workbook//  w ww .j  a va  2s  .com
 */
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 w  w  w. ja  va  2 s  .co m
    headerStyle.setAlignment(CellStyle.ALIGN_CENTER);
    return headerStyle;
}

From source file:org.unitime.timetable.export.XLSPrinter.java

License:Apache License

protected Font getFont(boolean bold, boolean italic, boolean underline, Color c) {
    Short color = null;//from   w w  w.j a  v a2 s.c  om
    if (c == null)
        c = Color.BLACK;
    if (c != null) {
        String colorId = Integer.toHexString(c.getRGB());
        color = iColors.get(colorId);
        if (color == null) {
            HSSFPalette palette = ((HSSFWorkbook) iWorkbook).getCustomPalette();
            HSSFColor clr = palette.findSimilarColor(c.getRed(), c.getGreen(), c.getBlue());
            color = (clr == null ? IndexedColors.BLACK.getIndex() : clr.getIndex());
            iColors.put(colorId, color);
        }
    }
    String fontId = (bold ? "b" : "") + (italic ? "i" : "") + (underline ? "u" : "")
            + (color == null ? "" : color);
    Font font = iFonts.get(fontId);
    if (font == null) {
        font = iWorkbook.createFont();
        font.setBold(bold);
        font.setItalic(italic);
        font.setUnderline(underline ? Font.U_SINGLE : Font.U_NONE);
        font.setColor(color);
        font.setFontHeightInPoints((short) 10);
        font.setFontName("Arial");
        iFonts.put(fontId, font);
    }
    return font;
}

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

public void exportStaffsByColumNames() throws UnsupportedEncodingException {
    ServletOutputStream os = null;// w w  w .j a va 2s  . com
    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:packtest.CellComments.java

License:Apache License

public static void main(String[] args) throws IOException {
    Workbook wb = new XSSFWorkbook();

    CreationHelper factory = wb.getCreationHelper();

    Sheet sheet = wb.createSheet();/*from  w ww . j a v  a2s.co m*/

    Cell cell1 = sheet.createRow(3).createCell(5);
    cell1.setCellValue("F4");

    Drawing drawing = sheet.createDrawingPatriarch();

    ClientAnchor anchor = factory.createClientAnchor();

    Comment comment1 = drawing.createCellComment(anchor);
    RichTextString str1 = factory.createRichTextString("Hello, World!");
    comment1.setString(str1);
    comment1.setAuthor("Apache POI");
    cell1.setCellComment(comment1);

    Cell cell2 = sheet.createRow(2).createCell(2);
    cell2.setCellValue("C3");

    Comment comment2 = drawing.createCellComment(anchor);
    RichTextString str2 = factory.createRichTextString("XSSF can set cell comments");
    //apply custom font to the text in the comment
    Font font = wb.createFont();
    font.setFontName("Arial");
    font.setFontHeightInPoints((short) 14);
    font.setBoldweight(Font.BOLDWEIGHT_BOLD);
    font.setColor(IndexedColors.RED.getIndex());
    str2.applyFont(font);

    comment2.setString(str2);
    comment2.setAuthor("Apache POI");
    //        comment2.setAddress(new CellAddress("C3"));

    String fname = "comments.xlsx";
    FileOutputStream out = new FileOutputStream(fname);
    wb.write(out);
    out.close();

    wb.close();
}