Skip to content

Instantly share code, notes, and snippets.

@logbasex
Last active July 1, 2020 02:14
Show Gist options
  • Save logbasex/2151cfba4a5201acd2a40d25144a5f11 to your computer and use it in GitHub Desktop.
Save logbasex/2151cfba4a5201acd2a40d25144a5f11 to your computer and use it in GitHub Desktop.

Revisions

  1. logbasex revised this gist Jul 1, 2020. No changes.
  2. logbasex revised this gist Jul 1, 2020. 1 changed file with 45 additions and 45 deletions.
    90 changes: 45 additions & 45 deletions apache-poi-example.java
    Original file line number Diff line number Diff line change
    @@ -1,50 +1,50 @@
    XSSFRow pre = sheet.createRow(0);
    XSSFRow pre = sheet.createRow(0);

    XSSFCell titleCell = pre.createCell(0);
    titleCell.setCellType(CellType.STRING);
    titleCell.setCellValue("Sent Email Detailed Statistics");
    XSSFFont font = workbook.createFont();
    font.setFontHeightInPoints((short) 25);
    XSSFCellStyle titleStyle = workbook.createCellStyle();
    XSSFColor grey = new XSSFColor(new java.awt.Color(255,195,1));
    titleStyle.setFillBackgroundColor(grey);
    //titleStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    titleStyle.setFont(font);
    titleStyle.setAlignment(HorizontalAlignment.CENTER);
    titleStyle.setWrapText(true);
    titleCell.setCellStyle(titleStyle);
    XSSFCell desCell = pre.createCell(2);
    desCell.setCellType(CellType.STRING);
    desCell.setCellValue("Details statistics for each email which is already sent.");
    XSSFFont desFont = workbook.createFont();
    desFont.setItalic(true);
    XSSFCellStyle desStyle = workbook.createCellStyle();
    desStyle.setFont(desFont);
    titleStyle.setWrapText(true);
    desCell.setCellStyle(desStyle);
    XSSFCell titleCell = pre.createCell(0);
    titleCell.setCellType(CellType.STRING);
    titleCell.setCellValue("Sent Email Detailed Statistics");
    XSSFFont font = workbook.createFont();
    font.setFontHeightInPoints((short) 25);
    XSSFCellStyle titleStyle = workbook.createCellStyle();
    XSSFColor grey = new XSSFColor(new java.awt.Color(255,195,1));
    titleStyle.setFillBackgroundColor(grey);
    //titleStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    titleStyle.setFont(font);
    titleStyle.setAlignment(HorizontalAlignment.CENTER);
    titleStyle.setWrapText(true);
    titleCell.setCellStyle(titleStyle);

    XSSFCell desCell = pre.createCell(2);
    desCell.setCellType(CellType.STRING);
    desCell.setCellValue("Details statistics for each email which is already sent.");
    XSSFFont desFont = workbook.createFont();
    desFont.setItalic(true);
    XSSFCellStyle desStyle = workbook.createCellStyle();
    desStyle.setFont(desFont);
    titleStyle.setWrapText(true);
    desCell.setCellStyle(desStyle);

    //merge cell
    int firstRow = 0;
    int lastRow = 0;
    int firstCol = 0;
    int lastCol = 1;
    sheet.addMergedRegion(new CellRangeAddress(firstRow, lastRow, firstCol, lastCol));
    int firstRow = 0;
    int lastRow = 0;
    int firstCol = 0;
    int lastCol = 1;
    sheet.addMergedRegion(new CellRangeAddress(firstRow, lastRow, firstCol, lastCol));

    //auto size columns include merged cell.
    sheet.autoSizeColumn(0, true);
    sheet.autoSizeColumn(1, true);
    sheet.autoSizeColumn(3, true);
    sheet.autoSizeColumn(4, true);
    XSSFRow headerRow = sheet.createRow(1);
    int i = 0;
    for (String headerCell : header) {
    XSSFCell cell = headerRow.createCell(i);
    cell.setCellType(CellType.STRING);
    cell.setCellValue(headerCell);
    sheet.autoSizeColumn(i, true);
    cell.setCellStyle(style);
    i++;
    }
    sheet.autoSizeColumn(0, true);
    sheet.autoSizeColumn(1, true);
    sheet.autoSizeColumn(3, true);
    sheet.autoSizeColumn(4, true);

    XSSFRow headerRow = sheet.createRow(1);

    int i = 0;
    for (String headerCell : header) {
    XSSFCell cell = headerRow.createCell(i);
    cell.setCellType(CellType.STRING);
    cell.setCellValue(headerCell);
    sheet.autoSizeColumn(i, true);
    cell.setCellStyle(style);
    i++;
    }
  3. logbasex created this gist Jul 1, 2020.
    50 changes: 50 additions & 0 deletions apache-poi-example.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,50 @@
    XSSFRow pre = sheet.createRow(0);

    XSSFCell titleCell = pre.createCell(0);
    titleCell.setCellType(CellType.STRING);
    titleCell.setCellValue("Sent Email Detailed Statistics");
    XSSFFont font = workbook.createFont();
    font.setFontHeightInPoints((short) 25);
    XSSFCellStyle titleStyle = workbook.createCellStyle();
    XSSFColor grey = new XSSFColor(new java.awt.Color(255,195,1));
    titleStyle.setFillBackgroundColor(grey);
    //titleStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    titleStyle.setFont(font);
    titleStyle.setAlignment(HorizontalAlignment.CENTER);
    titleStyle.setWrapText(true);
    titleCell.setCellStyle(titleStyle);

    XSSFCell desCell = pre.createCell(2);
    desCell.setCellType(CellType.STRING);
    desCell.setCellValue("Details statistics for each email which is already sent.");
    XSSFFont desFont = workbook.createFont();
    desFont.setItalic(true);
    XSSFCellStyle desStyle = workbook.createCellStyle();
    desStyle.setFont(desFont);
    titleStyle.setWrapText(true);
    desCell.setCellStyle(desStyle);

    //merge cell
    int firstRow = 0;
    int lastRow = 0;
    int firstCol = 0;
    int lastCol = 1;
    sheet.addMergedRegion(new CellRangeAddress(firstRow, lastRow, firstCol, lastCol));

    //auto size columns include merged cell.
    sheet.autoSizeColumn(0, true);
    sheet.autoSizeColumn(1, true);
    sheet.autoSizeColumn(3, true);
    sheet.autoSizeColumn(4, true);

    XSSFRow headerRow = sheet.createRow(1);

    int i = 0;
    for (String headerCell : header) {
    XSSFCell cell = headerRow.createCell(i);
    cell.setCellType(CellType.STRING);
    cell.setCellValue(headerCell);
    sheet.autoSizeColumn(i, true);
    cell.setCellStyle(style);
    i++;
    }