Example usage for org.apache.poi.hssf.usermodel HSSFFont FONT_ARIAL

List of usage examples for org.apache.poi.hssf.usermodel HSSFFont FONT_ARIAL

Introduction

In this page you can find the example usage for org.apache.poi.hssf.usermodel HSSFFont FONT_ARIAL.

Prototype

String FONT_ARIAL

To view the source code for org.apache.poi.hssf.usermodel HSSFFont FONT_ARIAL.

Click Source Link

Document

Arial font

Usage

From source file:com.accounting.reportMBean.ReportCommonBean.java

public void simplePostProcessXLS(Object document) {
    String startDateString = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap()
            .get("nepaliDate4");
    String endDateString = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap()
            .get("nepaliDate1");
    HSSFWorkbook wb = (HSSFWorkbook) document;
    HSSFCellStyle headerCellStyle = wb.createCellStyle();
    HSSFCellStyle headerCellStyle1 = wb.createCellStyle();
    HSSFCellStyle headerCellStyle2 = wb.createCellStyle();

    Font headerFont = wb.createFont();
    headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    headerFont.setFontName(HSSFFont.FONT_ARIAL);
    headerCellStyle.setFont(headerFont);
    headerCellStyle.setAlignment(CellStyle.ALIGN_CENTER);

    Font headerFont1 = wb.createFont();
    headerFont1.setBoldweight(Font.U_SINGLE_ACCOUNTING);
    headerFont1.setFontName(HSSFFont.FONT_ARIAL);
    headerCellStyle1.setFont(headerFont);
    headerCellStyle1.setAlignment(CellStyle.ALIGN_RIGHT);

    Font headerFont3 = wb.createFont();
    headerFont3.setBoldweight(Font.U_SINGLE);
    headerFont3.setFontName(HSSFFont.FONT_ARIAL);
    headerCellStyle2.setFont(headerFont1);
    headerCellStyle2.setAlignment(CellStyle.ALIGN_RIGHT);

    HSSFSheet sheet = wb.getSheetAt(0);//from ww w.  ja  va2 s . co  m
    int noOfColumns = sheet.getRow(0).getLastCellNum();
    for (int i = 0; i < noOfColumns; i++) {
        sheet.autoSizeColumn(i);
    }
    sheet.shiftRows(0, sheet.getLastRowNum(), 4);

    HSSFRow firstRow = sheet.createRow(1);
    firstRow.createCell(0).setCellValue(pageName);
    firstRow.getCell(0).setCellStyle(headerCellStyle);

    HSSFRow secondRow = sheet.createRow(0);
    secondRow.createCell(0).setCellValue(getLoggedInOffice().getName());
    secondRow.getCell(0).setCellStyle(headerCellStyle);

    HSSFRow thirdRow = sheet.createRow(3);
    String date = ndc.convertToNepaliDate(new Date());
    SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss a");
    String time = sdf.format(new Date());
    thirdRow.createCell(0)
            .setCellValue("Generated on:" + date + " " + time + " by:" + getLoggedInUser().getName());
    thirdRow.getCell(0).setCellStyle(headerCellStyle2);

    HSSFRow fourthRow = sheet.createRow(2);
    fourthRow.createCell(0).setCellValue("FROM: " + startDateString + " TO: " + endDateString);
    fourthRow.getCell(0).setCellStyle(headerCellStyle);

    sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 7));
    sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 7));
    sheet.addMergedRegion(new CellRangeAddress(2, 2, 0, 7));
    sheet.addMergedRegion(new CellRangeAddress(3, 3, 0, 7));
    HSSFRow lastRow;
    for (Row row : sheet) {
        if (row.getRowNum() > 4) {
            for (int i = 3; i < 8; i++) {

                String cost = row.getCell(i).getStringCellValue();
                if (cost != null && !cost.isEmpty()) {
                    row.getCell(i).setCellType(HSSFCell.CELL_TYPE_BLANK);
                    row.getCell(i).setCellType(HSSFCell.CELL_TYPE_NUMERIC);
                    row.getCell(i).setCellValue(Double.parseDouble(cost.replace(",", "")));
                }
            }
        }
    }
}

From source file:com.accounting.reportMBean.ReportCommonBean.java

public void simplePostProcessXLSXOfStock(Object document) {
    String startDateString = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap()
            .get("nepaliDate4");
    String endDateString = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap()
            .get("nepaliDate1");
    XSSFWorkbook wb = (XSSFWorkbook) document;
    XSSFCellStyle headerCellStyle = wb.createCellStyle();
    XSSFCellStyle headerCellStyle1 = wb.createCellStyle();
    XSSFCellStyle headerCellStyle2 = wb.createCellStyle();

    Font headerFont = wb.createFont();
    headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    headerFont.setFontName(HSSFFont.FONT_ARIAL);
    headerCellStyle.setFont(headerFont);
    headerCellStyle.setAlignment(CellStyle.ALIGN_CENTER);

    Font headerFont1 = wb.createFont();
    headerFont1.setBoldweight(Font.U_SINGLE_ACCOUNTING);
    headerFont1.setFontName(HSSFFont.FONT_ARIAL);
    headerCellStyle1.setFont(headerFont);
    headerCellStyle1.setAlignment(CellStyle.ALIGN_RIGHT);

    Font headerFont3 = wb.createFont();
    headerFont3.setBoldweight(Font.U_SINGLE);
    headerFont3.setFontName(HSSFFont.FONT_ARIAL);
    headerCellStyle2.setFont(headerFont1);
    headerCellStyle2.setAlignment(CellStyle.ALIGN_RIGHT);

    XSSFSheet sheet = wb.getSheetAt(0);/*from   w  ww.  j a  v  a  2 s.co  m*/
    int noOfColumns = sheet.getRow(2).getLastCellNum();
    for (int i = 0; i < noOfColumns; i++) {
        sheet.autoSizeColumn(i);
    }
    sheet.shiftRows(0, sheet.getLastRowNum(), 4);

    XSSFRow firstRow = sheet.createRow(1);
    firstRow.createCell(0).setCellValue("STOCK VALUE WITH VALUES");
    firstRow.getCell(0).setCellStyle(headerCellStyle);

    XSSFRow secondRow = sheet.createRow(0);
    secondRow.createCell(0).setCellValue(getLoggedInOffice().getName());
    secondRow.getCell(0).setCellStyle(headerCellStyle);
    //
    XSSFRow thirdRow = sheet.createRow(3);
    String date = ndc.convertToNepaliDate(new Date());
    SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss a");
    String time = sdf.format(new Date());
    thirdRow.createCell(0)
            .setCellValue("Generated on:" + date + " " + time + " by:" + getLoggedInUser().getName());
    thirdRow.getCell(0).setCellStyle(headerCellStyle2);

    XSSFRow fourthRow = sheet.createRow(2);
    fourthRow.createCell(0).setCellValue("FROM: " + startDateString + " TO: " + endDateString);
    fourthRow.getCell(0).setCellStyle(headerCellStyle);

    sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 7));
    sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 7));
    sheet.addMergedRegion(new CellRangeAddress(2, 2, 0, 7));
    sheet.addMergedRegion(new CellRangeAddress(3, 3, 0, 7));
}

From source file:com.accounting.reportMBean.ReportCommonBean.java

public void simplePostProcessXLSX(Object document) {
    String startDateString = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap()
            .get("nepaliDate4");
    String endDateString = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap()
            .get("nepaliDate1");
    XSSFWorkbook wb = (XSSFWorkbook) document;
    XSSFCellStyle headerCellStyle = wb.createCellStyle();
    XSSFCellStyle headerCellStyle1 = wb.createCellStyle();
    XSSFCellStyle headerCellStyle2 = wb.createCellStyle();

    Font headerFont = wb.createFont();
    headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    headerFont.setFontName(HSSFFont.FONT_ARIAL);
    headerCellStyle.setFont(headerFont);
    headerCellStyle.setAlignment(CellStyle.ALIGN_CENTER);

    Font headerFont1 = wb.createFont();
    headerFont1.setBoldweight(Font.U_SINGLE_ACCOUNTING);
    headerFont1.setFontName(HSSFFont.FONT_ARIAL);
    headerCellStyle1.setFont(headerFont);
    headerCellStyle1.setAlignment(CellStyle.ALIGN_RIGHT);

    Font headerFont3 = wb.createFont();
    headerFont3.setBoldweight(Font.U_SINGLE);
    headerFont3.setFontName(HSSFFont.FONT_ARIAL);
    headerCellStyle2.setFont(headerFont1);
    headerCellStyle2.setAlignment(CellStyle.ALIGN_RIGHT);

    XSSFSheet sheet = wb.getSheetAt(0);//  w  ww  .j  a  va2s .c  o  m
    int noOfColumns = sheet.getRow(2).getLastCellNum();
    for (int i = 0; i < noOfColumns; i++) {
        sheet.autoSizeColumn(i);
    }
    sheet.shiftRows(0, sheet.getLastRowNum(), 4);

    XSSFRow firstRow = sheet.createRow(1);
    firstRow.createCell(0).setCellValue(pageName);
    firstRow.getCell(0).setCellStyle(headerCellStyle);

    XSSFRow secondRow = sheet.createRow(0);
    secondRow.createCell(0).setCellValue(getLoggedInOffice().getName());
    secondRow.getCell(0).setCellStyle(headerCellStyle);
    //
    XSSFRow thirdRow = sheet.createRow(3);
    String date = ndc.convertToNepaliDate(new Date());
    SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss a");
    String time = sdf.format(new Date());
    thirdRow.createCell(0)
            .setCellValue("Generated on:" + date + " " + time + " by:" + getLoggedInUser().getName());
    thirdRow.getCell(0).setCellStyle(headerCellStyle2);

    XSSFRow fourthRow = sheet.createRow(2);
    fourthRow.createCell(0).setCellValue("FROM: " + startDateString + " TO: " + endDateString);
    fourthRow.getCell(0).setCellStyle(headerCellStyle);

    sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 7));
    sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 7));
    sheet.addMergedRegion(new CellRangeAddress(2, 2, 0, 7));
    sheet.addMergedRegion(new CellRangeAddress(3, 3, 0, 7));
}

From source file:com.accounting.reportMBean.StockLedgerMBeans.java

public void postProcessXLS(Object document) {
    String startDateString = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap()
            .get("nepaliDate4");
    String endDateReading = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap()
            .get("nepaliDate1");
    HSSFWorkbook wb = (HSSFWorkbook) document;
    HSSFCellStyle headerCellStyle = wb.createCellStyle();
    HSSFCellStyle headerCellStyle1 = wb.createCellStyle();
    HSSFCellStyle headerCellStyle2 = wb.createCellStyle();

    Font headerFont = wb.createFont();
    headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    headerFont.setFontName(HSSFFont.FONT_ARIAL);
    headerCellStyle.setFont(headerFont);
    headerCellStyle.setAlignment(CellStyle.ALIGN_CENTER);

    Font headerFont1 = wb.createFont();
    headerFont1.setBoldweight(Font.U_SINGLE_ACCOUNTING);
    headerFont1.setFontName(HSSFFont.FONT_ARIAL);
    headerCellStyle1.setFont(headerFont);
    headerCellStyle1.setAlignment(CellStyle.ALIGN_RIGHT);
    HSSFSheet sheet = wb.getSheetAt(0);/*from  w w w.j a v a2 s. c  o  m*/
    int noOfColumns = sheet.getRow(0).getLastCellNum();

    Font headerFont3 = wb.createFont();
    headerFont3.setBoldweight(Font.U_SINGLE);
    headerFont3.setFontName(HSSFFont.FONT_ARIAL);
    headerCellStyle2.setFont(headerFont1);
    headerCellStyle2.setAlignment(CellStyle.ALIGN_RIGHT);
    for (int i = 0; i < noOfColumns; i++) {
        sheet.autoSizeColumn(i);
    }
    sheet.shiftRows(0, sheet.getLastRowNum(), 4);

    HSSFRow firstRow = sheet.createRow(0);
    firstRow.createCell(0).setCellValue(reportHeader);
    firstRow.getCell(0).setCellStyle(headerCellStyle);

    HSSFRow secondRow = sheet.createRow(1);
    secondRow.createCell(0).setCellValue(getLoggedInOffice().getName());
    secondRow.getCell(0).setCellStyle(headerCellStyle);

    HSSFRow thirdRow = sheet.createRow(3);
    String generatedDate = ndc.convertToNepaliDate(new Date());
    SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss a");

    String time = sdf.format(new Date());
    thirdRow.createCell(0)
            .setCellValue("Generated on:" + generatedDate + " " + time + " by:" + getLoggedInUser().getName());
    thirdRow.getCell(0).setCellStyle(headerCellStyle2);

    HSSFRow fourthRow = sheet.createRow(2);
    fourthRow.createCell(0).setCellValue("From: " + startDateString + " To: " + endDateReading);
    fourthRow.getCell(0).setCellStyle(headerCellStyle);
    System.out.println("The cell count " + cellCount);
    sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, cellCount));
    sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, cellCount));
    sheet.addMergedRegion(new CellRangeAddress(2, 2, 0, cellCount));
    sheet.addMergedRegion(new CellRangeAddress(3, 3, 0, cellCount));
    for (Row row : sheet) {
        if (row.getRowNum() > 4) {
            for (int i = 3; i < count; i++) {
                String cost = row.getCell(i).getStringCellValue();
                if (cost != null && !cost.isEmpty()) {
                    row.getCell(i).setCellType(HSSFCell.CELL_TYPE_BLANK);
                    row.getCell(i).setCellType(HSSFCell.CELL_TYPE_NUMERIC);
                    row.getCell(i).setCellValue(Double.parseDouble(cost.replace(",", "")));
                }
            }
        }
    }
}

From source file:com.cimmyt.reports.impl.ServiceReportCustomQueryImpl.java

License:Apache License

public ServiceReportCustomQueryImpl() {
    book = new HSSFWorkbook();
    sheet = book.createSheet();/*from ww w .  j  a  va2 s.co  m*/
    plainStyle = book.createFont();
    headerStyle = book.createFont();
    plainStyle.setFontHeightInPoints((short) 11);
    plainStyle.setBoldweight((short) 11);
    plainStyle.setFontName(HSSFFont.FONT_ARIAL);

    BeanUtils.copyProperties(plainStyle, headerStyle);
    headerStyle.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);

    headerCellStyle = book.createCellStyle();
    headerCellStyle.setWrapText(true);
    headerCellStyle.setAlignment(HSSFCellStyle.ALIGN_JUSTIFY);
    headerCellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_TOP);
    headerCellStyle.setFont(headerStyle);

    plainCellStyle = book.createCellStyle();
    plainCellStyle.setWrapText(true);
    plainCellStyle.setAlignment(HSSFCellStyle.ALIGN_JUSTIFY);
    plainCellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_TOP);
    plainCellStyle.setFont(plainStyle);

}

From source file:com.cimmyt.reports.impl.ServiceReportKBioImpl.java

License:Apache License

/**
 * Method to put style to header and normally cell
 * @param objLibro//from  w w  w .  j a  va  2s . c  o  m
 * @param isHeader 
 * @return
 */
private HSSFCellStyle styleCellNormally(HSSFWorkbook objLibro, boolean isHeader) {
    HSSFFont sourceStyle = objLibro.createFont();
    sourceStyle.setFontHeightInPoints((short) 11);
    sourceStyle.setBoldweight((short) 11);
    sourceStyle.setFontName(HSSFFont.FONT_ARIAL);
    if (isHeader) {
        sourceStyle.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    }
    HSSFCellStyle styleCell = objLibro.createCellStyle();
    styleCell.setWrapText(true);
    styleCell.setAlignment(HSSFCellStyle.ALIGN_JUSTIFY);

    styleCell.setVerticalAlignment(HSSFCellStyle.VERTICAL_TOP);
    styleCell.setFont(sourceStyle);
    return styleCell;
}

From source file:com.cimmyt.reports.impl.ServiceReportKBioImpl.java

License:Apache License

/**
 * Method that pint cells in different style of foreground
 * @param objBook// w w w .  j ava2 s  .  c o  m
 * @param foregroundColor
 * @return
 */
private HSSFCellStyle getStyleCeldSolidForeground(HSSFWorkbook objBook, short foregroundColor) {
    HSSFFont sourceStyle = objBook.createFont();
    sourceStyle.setFontHeightInPoints((short) 11);
    sourceStyle.setFontName(HSSFFont.FONT_ARIAL);
    HSSFCellStyle stileCell = objBook.createCellStyle();
    stileCell.setWrapText(true);
    stileCell.setAlignment(HSSFCellStyle.ALIGN_JUSTIFY);
    stileCell.setVerticalAlignment(HSSFCellStyle.VERTICAL_TOP);
    stileCell.setFont(sourceStyle);
    stileCell.setFillForegroundColor(foregroundColor);
    stileCell.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    return stileCell;
}

From source file:com.demo.common.extreme.view.XlsView.java

License:Apache License

private Map initStyles(HSSFWorkbook wb, short fontHeight) {
    Map result = new HashMap();
    HSSFCellStyle titleStyle = wb.createCellStyle();
    HSSFCellStyle textStyle = wb.createCellStyle();
    HSSFCellStyle boldStyle = wb.createCellStyle();
    HSSFCellStyle numericStyle = wb.createCellStyle();
    HSSFCellStyle numericStyleBold = wb.createCellStyle();
    HSSFCellStyle moneyStyle = wb.createCellStyle();
    HSSFCellStyle moneyStyleBold = wb.createCellStyle();
    HSSFCellStyle percentStyle = wb.createCellStyle();
    HSSFCellStyle percentStyleBold = wb.createCellStyle();

    // Add to export totals
    HSSFCellStyle moneyStyle_Totals = wb.createCellStyle();
    HSSFCellStyle naStyle_Totals = wb.createCellStyle();
    HSSFCellStyle numericStyle_Totals = wb.createCellStyle();
    HSSFCellStyle percentStyle_Totals = wb.createCellStyle();
    HSSFCellStyle textStyle_Totals = wb.createCellStyle();

    result.put("titleStyle", titleStyle);
    result.put("textStyle", textStyle);
    result.put("boldStyle", boldStyle);
    result.put("numericStyle", numericStyle);
    result.put("numericStyleBold", numericStyleBold);
    result.put("moneyStyle", moneyStyle);
    result.put("moneyStyleBold", moneyStyleBold);
    result.put("percentStyle", percentStyle);
    result.put("percentStyleBold", percentStyleBold);

    // Add to export totals
    result.put("moneyStyle_Totals", moneyStyle_Totals);
    result.put("naStyle_Totals", naStyle_Totals);
    result.put("numericStyle_Totals", numericStyle_Totals);
    result.put("percentStyle_Totals", percentStyle_Totals);
    result.put("textStyle_Totals", textStyle_Totals);

    HSSFDataFormat format = wb.createDataFormat();

    // Global fonts
    HSSFFont font = wb.createFont();/*from  w  w  w .j  av a  2s  .c  o m*/
    font.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);
    font.setColor(HSSFColor.BLACK.index);
    font.setFontName(HSSFFont.FONT_ARIAL);
    font.setFontHeightInPoints(fontHeight);

    HSSFFont fontBold = wb.createFont();
    fontBold.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    fontBold.setColor(HSSFColor.BLACK.index);
    fontBold.setFontName(HSSFFont.FONT_ARIAL);
    fontBold.setFontHeightInPoints(fontHeight);

    // Money Style
    moneyStyle.setFont(font);
    moneyStyle.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
    moneyStyle.setDataFormat(format.getFormat(moneyFormat));

    // Money Style Bold
    moneyStyleBold.setFont(fontBold);
    moneyStyleBold.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
    moneyStyleBold.setDataFormat(format.getFormat(moneyFormat));

    // Percent Style
    percentStyle.setFont(font);
    percentStyle.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
    percentStyle.setDataFormat(format.getFormat(percentFormat));

    // Percent Style Bold
    percentStyleBold.setFont(fontBold);
    percentStyleBold.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
    percentStyleBold.setDataFormat(format.getFormat(percentFormat));

    // Standard Numeric Style
    numericStyle.setFont(font);
    numericStyle.setAlignment(HSSFCellStyle.ALIGN_RIGHT);

    // Standard Numeric Style Bold
    numericStyleBold.setFont(fontBold);
    numericStyleBold.setAlignment(HSSFCellStyle.ALIGN_RIGHT);

    // Title Style
    titleStyle.setFont(font);
    titleStyle.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);
    titleStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    titleStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
    titleStyle.setBottomBorderColor(HSSFColor.BLACK.index);
    titleStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
    titleStyle.setLeftBorderColor(HSSFColor.BLACK.index);
    titleStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
    titleStyle.setRightBorderColor(HSSFColor.BLACK.index);
    titleStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
    titleStyle.setTopBorderColor(HSSFColor.BLACK.index);
    titleStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
    titleStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);

    // Standard Text Style
    textStyle.setFont(font);
    textStyle.setWrapText(true);

    // Standard Text Style
    boldStyle.setFont(fontBold);
    boldStyle.setWrapText(true);

    // Money Style Total
    moneyStyle_Totals.setFont(fontBold);
    moneyStyle_Totals.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);
    moneyStyle_Totals.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    moneyStyle_Totals.setBorderBottom(HSSFCellStyle.BORDER_THIN);
    moneyStyle_Totals.setBottomBorderColor(HSSFColor.BLACK.index);
    moneyStyle_Totals.setBorderTop(HSSFCellStyle.BORDER_THIN);
    moneyStyle_Totals.setTopBorderColor(HSSFColor.BLACK.index);
    moneyStyle_Totals.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
    moneyStyle_Totals.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
    moneyStyle_Totals.setDataFormat(format.getFormat(moneyFormat));

    // n/a Style Total
    naStyle_Totals.setFont(fontBold);
    naStyle_Totals.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);
    naStyle_Totals.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    naStyle_Totals.setBorderBottom(HSSFCellStyle.BORDER_THIN);
    naStyle_Totals.setBottomBorderColor(HSSFColor.BLACK.index);
    naStyle_Totals.setBorderTop(HSSFCellStyle.BORDER_THIN);
    naStyle_Totals.setTopBorderColor(HSSFColor.BLACK.index);
    naStyle_Totals.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
    naStyle_Totals.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);

    // Numeric Style Total
    numericStyle_Totals.setFont(fontBold);
    numericStyle_Totals.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);
    numericStyle_Totals.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    numericStyle_Totals.setBorderBottom(HSSFCellStyle.BORDER_THIN);
    numericStyle_Totals.setBottomBorderColor(HSSFColor.BLACK.index);
    numericStyle_Totals.setBorderTop(HSSFCellStyle.BORDER_THIN);
    numericStyle_Totals.setTopBorderColor(HSSFColor.BLACK.index);
    numericStyle_Totals.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
    numericStyle_Totals.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);

    // Percent Style Total
    percentStyle_Totals.setFont(fontBold);
    percentStyle_Totals.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);
    percentStyle_Totals.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    percentStyle_Totals.setBorderBottom(HSSFCellStyle.BORDER_THIN);
    percentStyle_Totals.setBottomBorderColor(HSSFColor.BLACK.index);
    percentStyle_Totals.setBorderTop(HSSFCellStyle.BORDER_THIN);
    percentStyle_Totals.setTopBorderColor(HSSFColor.BLACK.index);
    percentStyle_Totals.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
    percentStyle_Totals.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
    percentStyle_Totals.setDataFormat(format.getFormat(percentFormat));

    // Text Style Total
    textStyle_Totals.setFont(fontBold);
    textStyle_Totals.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);
    textStyle_Totals.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    textStyle_Totals.setBorderBottom(HSSFCellStyle.BORDER_THIN);
    textStyle_Totals.setBottomBorderColor(HSSFColor.BLACK.index);
    textStyle_Totals.setBorderTop(HSSFCellStyle.BORDER_THIN);
    textStyle_Totals.setTopBorderColor(HSSFColor.BLACK.index);
    textStyle_Totals.setAlignment(HSSFCellStyle.ALIGN_LEFT);
    textStyle_Totals.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);

    return result;
}

From source file:com.nokia.s60tools.swmtanalyser.model.ExcelCreator.java

License:Open Source License

/**
  * create set of cell styles// ww w  .j a  v  a  2  s. com
  */
private Map<String, HSSFCellStyle> createStyles(HSSFWorkbook wb) {
    Map<String, HSSFCellStyle> styles = new HashMap<String, HSSFCellStyle>();

    HSSFCellStyle style;
    HSSFFont headerFont = wb.createFont();
    headerFont.setColor(HSSFColor.WHITE.index);
    headerFont.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);
    headerFont.setFontHeightInPoints((short) 18);
    style = createBorderedStyle(wb);
    style.setAlignment(HSSFCellStyle.ALIGN_LEFT);
    style.setFillForegroundColor(HSSFColor.BLUE.index);
    style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    style.setFont(headerFont);
    styles.put("header", style);

    HSSFFont font1 = wb.createFont();
    font1.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    font1.setFontHeightInPoints((short) 12);
    font1.setFontName(HSSFFont.FONT_ARIAL);
    font1.setColor(HSSFColor.WHITE.index);
    style = createBorderedStyle(wb);
    style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
    style.setFillForegroundColor(HSSFColor.BLUE.index);
    style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    style.setFont(font1);
    style.setWrapText(true);
    styles.put("header2", style);

    style = createBorderedStyle(wb);
    style.setAlignment(HSSFCellStyle.ALIGN_LEFT);
    style.setFillForegroundColor(HSSFColor.BLUE.index);
    style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    style.setFont(font1);
    style.setWrapText(true);
    styles.put("header1", style);

    HSSFFont font3 = wb.createFont();
    font3.setColor(HSSFColor.BLACK.index);
    font3.setFontHeightInPoints((short) 10);
    font3.setFontName(HSSFFont.FONT_ARIAL);
    font3.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    style = createBorderedStyle(wb);
    style.setAlignment(HSSFCellStyle.ALIGN_LEFT);
    style.setFont(font3);
    styles.put("cell_bold", style);

    HSSFFont font5 = wb.createFont();
    font5.setColor(HSSFColor.BLACK.index);
    font5.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);
    style = createBorderedStyle(wb);
    style.setAlignment(HSSFCellStyle.ALIGN_LEFT);
    style.setFont(font5);
    styles.put("cell_normal", style);

    HSSFFont font4 = wb.createFont();
    font4.setFontHeightInPoints((short) 10);
    font4.setColor(HSSFColor.WHITE.index);
    style = createBorderedStyle(wb);
    style.setFillForegroundColor(HSSFColor.BLUE.index);
    style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    style.setFont(font4);
    styles.put("cell_blue_font_white", style);

    style = createBorderedStyle(wb);
    style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
    styles.put("cell_number", style);

    HSSFFont blue_font = wb.createFont();
    blue_font.setFontHeightInPoints((short) 10);
    blue_font.setColor(HSSFColor.BLUE.index);
    style = createBorderedStyle(wb);
    style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
    style.setFont(blue_font);
    styles.put("blue_font", style);

    return styles;
}

From source file:com.onsemi.cdars.config.FtpConfigUSL24hrs.java

public void cronRun() throws FileNotFoundException, IOException {
    LOGGER.info(/*from ww  w . j a  v  a 2  s  .c  om*/
            "Upper Spec Limit (USL Shipping) executed at everyday on 8:00 am. Current time is : " + new Date());

    String username = System.getProperty("user.name");
    if (!"fg79cj".equals(username)) {
        username = "imperial";
    }
    DateFormat dateFormat = new SimpleDateFormat("ddMMMyyyy");
    Date date = new Date();
    String todayDate = dateFormat.format(date);

    String reportName = "C:\\Users\\" + username
            + "\\Documents\\CDARS\\HIMS USL for Sending to SBN Factory Report (" + todayDate + ").xls";

    FileOutputStream fileOut = new FileOutputStream(reportName);
    HSSFWorkbook workbook = new HSSFWorkbook();
    HSSFSheet sheet = workbook.createSheet("HIMS PROCESS EXCEED USL");
    CellStyle style = workbook.createCellStyle();
    Font font = workbook.createFont();
    font.setFontHeightInPoints((short) 10);
    font.setFontName(HSSFFont.FONT_ARIAL);
    font.setBoldweight(HSSFFont.COLOR_NORMAL);
    font.setBold(true);
    font.setColor(HSSFColor.DARK_BLUE.index);
    style.setFont(font);
    sheet.createFreezePane(0, 1); // Freeze 1st Row

    HSSFRow rowhead = sheet.createRow((short) 0);
    rowhead.setRowStyle(style);

    HSSFCell cell1_0 = rowhead.createCell(0);
    cell1_0.setCellStyle(style);
    cell1_0.setCellValue("HARDWARE TYPE");

    HSSFCell cell1_1 = rowhead.createCell(1);
    cell1_1.setCellStyle(style);
    cell1_1.setCellValue("HARDWARE ID");

    HSSFCell cell1_2 = rowhead.createCell(2);
    cell1_2.setCellStyle(style);
    cell1_2.setCellValue("MATERIAL PASS NO");

    HSSFCell cell1_3 = rowhead.createCell(3);
    cell1_3.setCellStyle(style);
    cell1_3.setCellValue("DURATION");

    HSSFCell cell1_4 = rowhead.createCell(4);
    cell1_4.setCellStyle(style);
    cell1_4.setCellValue("CURRENT STATUS");

    //            WhUSLDAO whUslDAO = new WhUSLDAO();
    //            List<WhUSL> whUslList = whUslDAO.getWhUSLLog();
    String materialPassNo = "";
    String hardwareId = "";
    String hardwareType = "";
    String duration = "";
    String status = "";
    String text = "";

    WhStatusLogDAO statusD = new WhStatusLogDAO();
    List<WhStatusLog> whUslList = statusD.getTLReqToApproveAndApproveToMpCreatedList();

    boolean checksize1 = false;
    boolean checksize2 = false;
    for (int i = 0; i < whUslList.size(); i++) {
        checksize1 = true;
        hardwareType = whUslList.get(i).getEquipmentType();
        hardwareId = whUslList.get(i).getEquipmentId();
        materialPassNo = whUslList.get(i).getMpNo();
        String hourReqApp = whUslList.get(i).getRequestToApprove24();
        String hourReqAppIfNull = whUslList.get(i).getRequestToApproveTemp24();
        String hourAppMp = whUslList.get(i).getApproveToMPCreated24();
        String hourAppMpIfNull = whUslList.get(i).getApproveToMPCreatedTemp24();

        boolean flag = false;

        if (hourReqAppIfNull != null) {
            if (Integer.parseInt(hourReqAppIfNull) >= 24 && hourReqApp == null) {
                duration = whUslList.get(i).getRequestToApproveTemp();
                status = "Pending Approval";
                flag = true;
            }
        }

        if (hourAppMpIfNull != null) {
            if (Integer.parseInt(hourAppMpIfNull) >= 24 && hourAppMp == null && hourReqApp != null) {
                duration = whUslList.get(i).getApproveToMPCreatedTemp();
                status = "Pending Material Pass Number";
                flag = true;
            }
        }

        if (flag == true) {
            HSSFRow contents = sheet.createRow(sheet.getLastRowNum() + 1);
            //                
            HSSFCell cell2_0 = contents.createCell(0);
            cell2_0.setCellValue(hardwareType);

            HSSFCell cell2_1 = contents.createCell(1);
            cell2_1.setCellValue(hardwareId);

            HSSFCell cell2_2 = contents.createCell(2);
            cell2_2.setCellValue(materialPassNo);

            HSSFCell cell2_3 = contents.createCell(3);
            cell2_3.setCellValue(duration);

            HSSFCell cell2_4 = contents.createCell(4);
            cell2_4.setCellValue(status);
        }
    }

    WhStatusLogDAO statusD2 = new WhStatusLogDAO();
    List<WhStatusLog> whUslList2 = statusD2.getTLMpCreatedToFinalInventoryDateList();

    for (int i = 0; i < whUslList2.size(); i++) {
        checksize2 = true;
        hardwareType = whUslList2.get(i).getEquipmentType();
        hardwareId = whUslList2.get(i).getEquipmentId();
        materialPassNo = whUslList2.get(i).getMpNo();
        String hourMpTt = whUslList2.get(i).getMpCreatedToTtScan24();
        String hourMpTtIfNull = whUslList2.get(i).getMpCreatedToTtScanTemp24();
        String hourTtBs = whUslList2.get(i).getTtScanToBsScan24();
        String hourTtBsIfNull = whUslList2.get(i).getTtScanToBsScanTemp24();
        String hourBsShip = whUslList2.get(i).getBsScanToShip24();
        String hourBsShipIfNull = whUslList2.get(i).getBsScanToShipTemp24();
        String hourShipInv = whUslList2.get(i).getShipToInventory24();
        String hourShipInvIfNull = whUslList2.get(i).getShipToInventoryTemp24();

        boolean flag = false;

        if (hourMpTtIfNull != null) {
            if (Integer.parseInt(hourMpTtIfNull) >= 24 && hourMpTt == null) {
                duration = whUslList2.get(i).getMpCreatedToTtScanTemp();
                status = "Pending Trip Ticket Scanning";
                flag = true;
            }
        }

        if (hourTtBsIfNull != null) {
            if (Integer.parseInt(hourTtBsIfNull) >= 24 && hourTtBs == null && hourMpTt != null) {
                duration = whUslList2.get(i).getTtScanToBsScanTemp();
                status = "Pending Barcode Sticker Scanning";
                flag = true;
            }
        }

        if (hourBsShipIfNull != null) {
            if (Integer.parseInt(hourBsShipIfNull) >= 24 && hourBsShip == null && hourTtBs != null
                    && hourMpTt != null) {
                duration = whUslList2.get(i).getBsScanToShipTemp();
                status = "Pending Shipping Packing List";
                flag = true;
            }
        }

        if (hourShipInvIfNull != null) {
            if (Integer.parseInt(hourShipInvIfNull) >= 24 && hourShipInv == null && hourBsShip != null
                    && hourTtBs != null && hourMpTt != null) {
                duration = whUslList2.get(i).getShipToInventoryTemp();
                status = "Pending Inventory in Seremban Factory";
                flag = true;
            }
        }

        if (flag == true) {
            HSSFRow contents = sheet.createRow(sheet.getLastRowNum() + 1);
            //                
            HSSFCell cell2_0 = contents.createCell(0);
            cell2_0.setCellValue(hardwareType);

            HSSFCell cell2_1 = contents.createCell(1);
            cell2_1.setCellValue(hardwareId);

            HSSFCell cell2_2 = contents.createCell(2);
            cell2_2.setCellValue(materialPassNo);

            HSSFCell cell2_3 = contents.createCell(3);
            cell2_3.setCellValue(duration);

            HSSFCell cell2_4 = contents.createCell(4);
            cell2_4.setCellValue(status);
        }

    }

    if (checksize1 == true || checksize2 == true) {
        workbook.write(fileOut);
        workbook.close();

        //send email
        LOGGER.info("send email to person in charge");
        EmailSender emailSender = new EmailSender();
        com.onsemi.cdars.model.User user = new com.onsemi.cdars.model.User();
        user.setFullname("All");

        List<String> a = new ArrayList<String>();

        String emailApprover = "";
        String emaildistList1 = "";
        String emaildistList2 = "";
        String emaildistList3 = "";
        String emaildistList4 = "";

        emailApprover = "fg79cj@onsemi.com";
        a.add(emailApprover);

        EmailConfigDAO econfD = new EmailConfigDAO();
        int countDistList1 = econfD.getCountTask("Dist List 1");
        if (countDistList1 == 1) {
            econfD = new EmailConfigDAO();
            EmailConfig distList1 = econfD.getEmailConfigByTask("Dist List 1");
            emaildistList1 = distList1.getEmail();
            a.add(emaildistList1);
        }
        econfD = new EmailConfigDAO();
        int countDistList2 = econfD.getCountTask("Dist List 2");
        if (countDistList2 == 1) {
            econfD = new EmailConfigDAO();
            EmailConfig distList2 = econfD.getEmailConfigByTask("Dist List 2");
            emaildistList2 = distList2.getEmail();
            a.add(emaildistList2);
        }
        econfD = new EmailConfigDAO();
        int countDistList3 = econfD.getCountTask("Dist List 3");
        if (countDistList3 == 1) {
            econfD = new EmailConfigDAO();
            EmailConfig distList3 = econfD.getEmailConfigByTask("Dist List 3");
            emaildistList3 = distList3.getEmail();
            a.add(emaildistList3);
        }
        econfD = new EmailConfigDAO();
        int countDistList4 = econfD.getCountTask("Dist List 4");
        if (countDistList4 == 1) {
            econfD = new EmailConfigDAO();
            EmailConfig distList4 = econfD.getEmailConfigByTask("Dist List 4");
            emaildistList4 = distList4.getEmail();
            a.add(emaildistList4);
        }
        String[] myArray = new String[a.size()];
        String[] emailTo = a.toArray(myArray);
        //            String[] to = {"fg79cj@onsemi.com"};
        emailSender.htmlEmailWithAttachment(servletContext, user, //user name requestor
                emailTo,
                new File("C:\\Users\\"
                        + username + "\\Documents\\CDARS\\HIMS USL for Sending to SBN Factory Report ("
                        + todayDate + ").xls"),
                "List of Hardware Exceed USL (24 hours) for Sending to SBN Factory", //subject
                "Report for Hardware Process from HIMS(Hadware Sending to SBN Factory) that exceed Upper Specs Limit (24 hours) has been made. <br />"
                        + "Hence, attached is the report file for your view and perusal. <br /><br />"
                        + "<br /><br /> " + "<style>table, th, td {border: 1px solid black;} </style>"
                        + "<table style=\"width:100%\">" //tbl
                        + "<tr>" + "<th>HARDWARE TYPE</th> " + "<th>HARDWARE ID</th> "
                        + "<th>MATERIAL PASS NO.</th>" + "<th>DURATION</th>" + "<th>CURRENT STATUS</th>"
                        + "</tr>" + table() + "</table>" + "<br />Thank you." //msg
        );
    }

    //        }
}