Example usage for org.apache.poi.hssf.record ExtendedFormatRecord CENTER

List of usage examples for org.apache.poi.hssf.record ExtendedFormatRecord CENTER

Introduction

In this page you can find the example usage for org.apache.poi.hssf.record ExtendedFormatRecord CENTER.

Prototype

short CENTER

To view the source code for org.apache.poi.hssf.record ExtendedFormatRecord CENTER.

Click Source Link

Usage

From source file:com.sevenorcas.openstyle.app.service.spreadsheet.BaseSS.java

/**
 * Set the passed in cell to invalid/*  w  w w .  ja  va  2s .c o  m*/
 * @param cell
 * @return
 */
protected void styleInvalid(SpreadsheetCell cell) {

    cell.setCallback(new SpreadsheetCellCallBackI() {
        public HSSFRichTextString getCellValue(HSSFWorkbook wb, SpreadSheet sheet, HSSFCell cell,
                String value) {

            if (styleInvalid == null) {
                HSSFFont font = fonts.get("red");
                if (font == null) {
                    String[] s = RED.split(",");
                    HSSFColor c = sheet.setColor(wb, Integer.parseInt(s[0]), Integer.parseInt(s[1]),
                            Integer.parseInt(s[2]));
                    font = wb.createFont();
                    if (c != null) {
                        font.setColor(c.getIndex());
                    }
                    fonts.put("red", font);
                }

                HSSFCellStyle style = wb.createCellStyle();
                style.setFont(font);
                style.setAlignment((short) ExtendedFormatRecord.CENTER);
                styleInvalid = style;
            }

            cell.setCellStyle(styleInvalid);
            HSSFRichTextString richString = new HSSFRichTextString(value);
            return richString;
        }
    });
}

From source file:com.sevenorcas.openstyle.app.service.spreadsheet.BaseSS.java

/**
 * Set the passed in cell to red/*from  w w w . j av  a2  s . co m*/
 * @param cell
 * @return
 */
protected void styleRed(SpreadsheetCell cell) {
    cell.setCallbackStyle(new SpreadsheetCellStyleCallBackI() {
        public HSSFCellStyle getCellStyle(HSSFWorkbook wb, SpreadSheet sheet, HSSFCell cell) {

            HSSFFont font = fonts.get("red");
            if (font == null) {
                String[] s = RED.split(",");
                HSSFColor c = sheet.setColor(wb, Integer.parseInt(s[0]), Integer.parseInt(s[1]),
                        Integer.parseInt(s[2]));
                font = wb.createFont();
                if (c != null) {
                    font.setColor(c.getIndex());
                }
                fonts.put("red", font);
            }
            if (styleQuantityRed == null) {
                HSSFCellStyle style = wb.createCellStyle();
                style.setFont(font);
                style.setAlignment((short) ExtendedFormatRecord.CENTER);
                styleQuantityRed = style;
            }
            return styleQuantityRed;
        }
    });
}

From source file:com.sevenorcas.openstyle.app.service.spreadsheet.BaseSS.java

/**
 * Sheet title //from  w ww  .  ja  va  2  s. c om
 * @param sheet
 * @param startCol
 * @param title
 * @param Number of columns to span
 */
protected void outputTitle(SpreadSheet sheet, int startCol, String title, int columnCount) throws Exception {

    sheet.addRowFormat(FORMAT_BOLD);
    sheet.setCol(startCol);
    sheet.addColumnFormat(ALIGN_CENTER);

    SpreadsheetCell cell = sheet.addCell(title, STYLE_TITLE);

    cell.setCallback(new SpreadsheetCellCallBackI() {
        public HSSFRichTextString getCellValue(HSSFWorkbook wb, SpreadSheet sheet, HSSFCell cell,
                String value) {
            HSSFFont font = wb.createFont();
            font.setFontHeightInPoints((short) 16);
            HSSFCellStyle style = wb.createCellStyle();
            style.setFont(font);
            style.setAlignment((short) ExtendedFormatRecord.CENTER);
            cell.setCellStyle(style);

            HSSFRichTextString richString = new HSSFRichTextString(value);
            return richString;
        }
    });

    mergeColumns(sheet, cell, columnCount);
    sheet.incrementRow();
}