Example usage for org.apache.poi.ss.usermodel CellStyle setAlignment

List of usage examples for org.apache.poi.ss.usermodel CellStyle setAlignment

Introduction

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

Prototype

void setAlignment(HorizontalAlignment align);

Source Link

Document

set the type of horizontal alignment for the cell

Usage

From source file:org.hellojavaer.poi.excel.utils.ExcelUtils.java

License:Apache License

@SuppressWarnings("rawtypes")
private static void writeHead(boolean useTemplate, Sheet sheet, ExcelWriteSheetProcessor sheetProcessor) {
    Integer headRowIndex = sheetProcessor.getHeadRowIndex();
    if (headRowIndex == null) {
        return;//from  w w  w  .  j  a  v a 2  s.co m
    }
    Workbook wookbook = sheet.getWorkbook();
    // use theme
    CellStyle style = null;
    if (!useTemplate && sheetProcessor.getTheme() != null) {
        int theme = sheetProcessor.getTheme();
        if (theme == ExcelWriteTheme.BASE) {
            style = wookbook.createCellStyle();
            style.setFillPattern(CellStyle.SOLID_FOREGROUND);
            style.setFillForegroundColor((short) 44);
            style.setBorderBottom(CellStyle.BORDER_THIN);
            style.setBorderLeft(CellStyle.BORDER_THIN);
            style.setBorderRight(CellStyle.BORDER_THIN);
            style.setBorderTop(CellStyle.BORDER_THIN);
            // style.setBottomBorderColor((short) 44);
            style.setAlignment(CellStyle.ALIGN_CENTER);
        }
        // freeze Pane
        if (sheetProcessor.getHeadRowIndex() != null && sheetProcessor.getHeadRowIndex() == 0) {
            sheet.createFreezePane(0, 1, 0, 1);
        }
    }

    Row row = sheet.getRow(headRowIndex);
    if (row == null) {
        row = sheet.createRow(headRowIndex);
    }
    for (Map.Entry<String, Map<Integer, ExcelWriteFieldMappingAttribute>> entry : sheetProcessor
            .getFieldMapping().export().entrySet()) {
        Map<Integer, ExcelWriteFieldMappingAttribute> map = entry.getValue();
        if (map != null) {
            for (Map.Entry<Integer, ExcelWriteFieldMappingAttribute> entry2 : map.entrySet()) {
                String head = entry2.getValue().getHead();
                Integer colIndex = entry2.getKey();
                Cell cell = row.getCell(colIndex);
                if (cell == null) {
                    cell = row.createCell(colIndex);
                }
                // use theme
                if (!useTemplate && sheetProcessor.getTheme() != null) {
                    cell.setCellStyle(style);

                }
                cell.setCellValue(head);
            }
        }
    }

}

From source file:org.jaffa.qm.finder.apis.ExcelExportService.java

License:Open Source License

public static Workbook generateExcel(QueryServiceConfig master, QueryServiceConfig child, String sheetName)
        throws ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException,
        IllegalArgumentException, InvocationTargetException {

    Workbook wb = null;/* w  w w  .j av a  2 s . c  o m*/
    String legacyExport = (String) ContextManagerFactory.instance()
            .getProperty("jaffa.widgets.exportToExcel.legacy");
    if (legacyExport != null && legacyExport.equals("T")) {
        wb = new HSSFWorkbook();
    } else {
        wb = new SXSSFWorkbook(100);
    }
    try {
        // Creating worksheet
        Sheet sheet = null;
        if (sheetName != null)
            sheet = wb.createSheet(sheetName);
        else
            sheet = wb.createSheet();

        // creating a custom palette for the workbook
        CellStyle style = wb.createCellStyle();
        style = wb.createCellStyle();

        // setting the foreground color to gray
        style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
        style.setFillPattern(CellStyle.SOLID_FOREGROUND);

        // Setting the border for the cells
        style.setBorderBottom(CellStyle.BORDER_THIN);
        style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
        style.setBorderLeft(CellStyle.BORDER_THIN);
        style.setLeftBorderColor(IndexedColors.GREEN.getIndex());
        style.setBorderRight(CellStyle.BORDER_THIN);
        style.setRightBorderColor(IndexedColors.BLACK.getIndex());
        style.setBorderTop(CellStyle.BORDER_THIN);
        style.setTopBorderColor(IndexedColors.BLACK.getIndex());
        style.setAlignment(CellStyle.ALIGN_CENTER);

        // setting font weight
        Font titleFont = wb.createFont();
        titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
        style.setFont(titleFont);

        int rowNum = 0;
        Row headerRow = sheet.createRow(rowNum);
        int colIndex = 0;
        for (Object o : master.getColumnModel()) {
            String columnTitle = (String) ((DynaBean) o).get("header");
            if (columnTitle == null || columnTitle.length() == 0)
                columnTitle = (String) ((DynaBean) o).get("mapping");

            headerRow.createCell(colIndex).setCellValue(columnTitle);
            Cell cell = headerRow.getCell(colIndex);
            cell.setCellStyle(style);
            sheet.autoSizeColumn(colIndex);
            colIndex += 1;
        }

        // Generate the Excel output by creating a simple HTML table
        if (child != null) {
            for (Object o : child.getColumnModel()) {
                String columnTitle = (String) ((DynaBean) o).get("header");
                if (columnTitle == null || columnTitle.length() == 0)
                    columnTitle = (String) ((DynaBean) o).get("mapping");

                headerRow.createCell(colIndex).setCellValue(columnTitle);
                Cell cell = headerRow.getCell(colIndex);
                cell.setCellStyle(style);
                sheet.autoSizeColumn(colIndex);
                colIndex += 1;

            }
        }

        // Invoke the query and obtain an array of Graph objects
        Object[] queryOutput = invokeQueryService(master.getCriteriaClassName(), master.getCriteriaObject(),
                master.getServiceClassName(), master.getServiceClassMethodName());

        // Add the data rows
        if (queryOutput != null) {
            for (Object row : queryOutput) {
                Object[] detailQueryOutput = new Object[0];
                if (child == null) {
                    rowNum += 1;
                    Row dataRow = sheet.createRow((short) rowNum);
                    int colNum = 0;
                    // extract the columns from master object
                    for (Object o : master.getColumnModel()) {
                        String mapping = (String) ((DynaBean) o).get("mapping");
                        Object value = null;
                        if (mapping.startsWith("appFields.")) {
                            mapping = mapping.substring(10);
                            try {
                                Object[] appFields = (Object[]) PropertyUtils.getProperty(row,
                                        "applicationFields");
                                for (Object field : appFields) {
                                    String name = (String) PropertyUtils.getProperty(field, "name");
                                    if (name.equals(mapping)) {
                                        value = (String) PropertyUtils.getProperty(field, "value");
                                    }
                                }
                            } catch (Exception e) {
                                if (log.isDebugEnabled())
                                    log.debug("Property not found: " + mapping, e);
                            }
                        } else {
                            try {
                                value = PropertyUtils.getProperty(row, mapping);
                            } catch (Exception e) {
                                if (log.isDebugEnabled())
                                    log.debug("Property not found: " + mapping, e);
                            }
                        }
                        dataRow.createCell(colNum).setCellValue(format(value, (DynaBean) o));
                        colNum += 1;
                    }
                } else { //child is not null
                    // load the child rows
                    String detailCriteriaObject = child.getCriteriaObject();
                    for (int i = 0; i < child.getMasterKeyFieldNames().length; i++) {
                        String kfn = child.getMasterKeyFieldNames()[i];
                        try {
                            String keyValue = (String) PropertyUtils.getProperty(row, kfn);
                            detailCriteriaObject = detailCriteriaObject.replace("{" + i + "}", keyValue);
                        } catch (Exception e) {
                            if (log.isDebugEnabled())
                                log.debug("Key property not found: " + kfn, e);
                        }
                    }
                    detailQueryOutput = invokeQueryService(child.getCriteriaClassName(), detailCriteriaObject,
                            child.getServiceClassName(), "query");

                    // add the child columns
                    if (detailQueryOutput != null && detailQueryOutput.length > 0) {
                        for (Object detailRow : detailQueryOutput) {
                            rowNum += 1;
                            Row dataRow = sheet.createRow((short) rowNum);

                            int colNum = 0;
                            // extract the columns from master object
                            for (Object obj : master.getColumnModel()) {
                                String masterMapping = (String) ((DynaBean) obj).get("mapping");
                                Object masterValue = null;
                                try {
                                    masterValue = PropertyUtils.getProperty(row, masterMapping);
                                } catch (Exception e) {
                                    if (log.isDebugEnabled())
                                        log.debug("Property not found: " + masterMapping, e);
                                }

                                dataRow.createCell(colNum).setCellValue(format(masterValue, (DynaBean) obj));
                                colNum += 1;
                            }

                            for (Object o : child.getColumnModel()) {
                                String mapping = (String) ((DynaBean) o).get("mapping");
                                Object value = null;
                                try {
                                    value = PropertyUtils.getProperty(detailRow, mapping);
                                } catch (Exception e) {
                                    if (log.isDebugEnabled())
                                        log.debug("Property not found in child result: " + mapping, e);
                                }

                                dataRow.createCell(colNum).setCellValue(format(value, (DynaBean) o));
                                colNum += 1;
                            }
                        }
                    }
                }
            }
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
    return wb;
}

From source file:org.jaffa.ria.finder.apis.ExcelExportService.java

License:Open Source License

public static Workbook generateExcel(QueryServiceConfig master, QueryServiceConfig child, String sheetName)
        throws ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException,
        IllegalArgumentException, InvocationTargetException {

    Workbook wb = null;//from w  w w  .  j av  a 2 s  .  c  om
    String legacyExport = (String) ContextManagerFactory.instance()
            .getProperty("jaffa.widgets.exportToExcel.legacy");
    if (legacyExport != null && legacyExport.equals("T")) {
        wb = new HSSFWorkbook();
    } else {
        wb = new SXSSFWorkbook(100);
    }
    try {
        // Creating worksheet
        Sheet sheet = null;
        if (sheetName != null) {
            if (sheetName.length() > 31)
                sheetName = sheetName.substring(0, 31);
            char replaceChar = '_';
            sheetName = sheetName.replace('\u0003', replaceChar).replace(':', replaceChar)
                    .replace('/', replaceChar).replace("\\\\", Character.toString(replaceChar))
                    .replace('?', replaceChar).replace('*', replaceChar).replace(']', replaceChar)
                    .replace('[', replaceChar);
            sheet = wb.createSheet(sheetName);
        } else
            sheet = wb.createSheet();

        // creating a custom palette for the workbook
        CellStyle style = wb.createCellStyle();
        style = wb.createCellStyle();

        // setting the foreground color to gray
        style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
        style.setFillPattern(CellStyle.SOLID_FOREGROUND);

        // Setting the border for the cells
        style.setBorderBottom(CellStyle.BORDER_THIN);
        style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
        style.setBorderLeft(CellStyle.BORDER_THIN);
        style.setLeftBorderColor(IndexedColors.GREEN.getIndex());
        style.setBorderRight(CellStyle.BORDER_THIN);
        style.setRightBorderColor(IndexedColors.BLACK.getIndex());
        style.setBorderTop(CellStyle.BORDER_THIN);
        style.setTopBorderColor(IndexedColors.BLACK.getIndex());
        style.setAlignment(CellStyle.ALIGN_CENTER);

        // setting font weight
        Font titleFont = wb.createFont();
        titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
        style.setFont(titleFont);

        int rowNum = 0;
        Row headerRow = sheet.createRow(rowNum);
        int colIndex = 0;
        for (Object o : master.getColumnModel()) {
            String columnTitle = (String) ((DynaBean) o).get("header");
            if (columnTitle == null || columnTitle.length() == 0)
                columnTitle = (String) ((DynaBean) o).get("mapping");

            headerRow.createCell(colIndex).setCellValue(columnTitle);
            Cell cell = headerRow.getCell(colIndex);
            cell.setCellStyle(style);
            sheet.autoSizeColumn(colIndex);
            colIndex += 1;
        }

        // Generate the Excel output by creating a simple HTML table
        if (child != null) {
            for (Object o : child.getColumnModel()) {
                String columnTitle = (String) ((DynaBean) o).get("header");
                if (columnTitle == null || columnTitle.length() == 0)
                    columnTitle = (String) ((DynaBean) o).get("mapping");

                headerRow.createCell(colIndex).setCellValue(columnTitle);
                Cell cell = headerRow.getCell(colIndex);
                cell.setCellStyle(style);
                sheet.autoSizeColumn(colIndex);
                colIndex += 1;

            }
        }

        // Invoke the query and obtain an array of Graph objects
        Object[] queryOutput = invokeQueryService(master.getCriteriaClassName(), master.getCriteriaObject(),
                master.getServiceClassName(), master.getServiceClassMethodName());

        // Add the data rows
        if (queryOutput != null) {
            for (Object row : queryOutput) {
                Object[] detailQueryOutput = new Object[0];
                if (child == null) {
                    rowNum += 1;
                    Row dataRow = sheet.createRow((short) rowNum);
                    int colNum = 0;
                    // extract the columns from master object
                    for (Object o : master.getColumnModel()) {
                        String mapping = (String) ((DynaBean) o).get("mapping");
                        Object value = null;
                        try {
                            value = PropertyUtils.getProperty(row, mapping);
                        } catch (Exception e) {
                            if (log.isDebugEnabled())
                                log.debug("Property not found: " + mapping, e);
                        }

                        dataRow.createCell(colNum).setCellValue(format(value, (DynaBean) o));
                        colNum += 1;
                    }
                } else { //child is not null
                    // load the child rows
                    String detailCriteriaObject = child.getCriteriaObject();
                    for (int i = 0; i < child.getMasterKeyFieldNames().length; i++) {
                        String kfn = child.getMasterKeyFieldNames()[i];
                        try {
                            String keyValue = (String) PropertyUtils.getProperty(row, kfn);
                            detailCriteriaObject = detailCriteriaObject.replace("{" + i + "}", keyValue);
                        } catch (Exception e) {
                            if (log.isDebugEnabled())
                                log.debug("Key property not found: " + kfn, e);
                        }
                    }
                    detailQueryOutput = invokeQueryService(child.getCriteriaClassName(), detailCriteriaObject,
                            child.getServiceClassName(), "query");

                    // add the child columns
                    if (detailQueryOutput != null && detailQueryOutput.length > 0) {
                        for (Object detailRow : detailQueryOutput) {
                            rowNum += 1;
                            Row dataRow = sheet.createRow((short) rowNum);

                            int colNum = 0;
                            // extract the columns from master object
                            for (Object obj : master.getColumnModel()) {
                                String masterMapping = (String) ((DynaBean) obj).get("mapping");
                                Object masterValue = null;
                                try {
                                    masterValue = PropertyUtils.getProperty(row, masterMapping);
                                } catch (Exception e) {
                                    if (log.isDebugEnabled())
                                        log.debug("Property not found: " + masterMapping, e);
                                }

                                dataRow.createCell(colNum).setCellValue(format(masterValue, (DynaBean) obj));
                                colNum += 1;
                            }

                            for (Object o : child.getColumnModel()) {
                                String mapping = (String) ((DynaBean) o).get("mapping");
                                Object value = null;
                                try {
                                    value = PropertyUtils.getProperty(detailRow, mapping);
                                } catch (Exception e) {
                                    if (log.isDebugEnabled())
                                        log.debug("Property not found in child result: " + mapping, e);
                                }

                                dataRow.createCell(colNum).setCellValue(format(value, (DynaBean) o));
                                colNum += 1;
                            }
                        }
                    }
                }
            }
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
    return wb;
}

From source file:org.jboss.dashboard.displayer.table.ExportTool.java

License:Apache License

private Map<String, CellStyle> createStyles(Workbook wb) {
    Map<String, CellStyle> styles = new HashMap<String, CellStyle>();
    CellStyle style;

    Font titleFont = wb.createFont();
    titleFont.setFontHeightInPoints((short) 12);
    titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    style = wb.createCellStyle();//from w  w  w . j av a  2  s  .c om
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    style.setFont(titleFont);
    style.setWrapText(false);
    style.setBorderBottom(CellStyle.BORDER_THIN);
    style.setBottomBorderColor(IndexedColors.GREY_80_PERCENT.getIndex());
    styles.put("header", style);

    Font cellFont = wb.createFont();
    cellFont.setFontHeightInPoints((short) 10);
    cellFont.setBoldweight(Font.BOLDWEIGHT_NORMAL);

    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_RIGHT);
    style.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM);
    style.setFont(cellFont);
    style.setWrapText(false);
    style.setDataFormat(wb.createDataFormat().getFormat(BuiltinFormats.getBuiltinFormat(3)));
    styles.put("integer_number_cell", style);

    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_RIGHT);
    style.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM);
    style.setFont(cellFont);
    style.setWrapText(false);
    style.setDataFormat(wb.createDataFormat().getFormat(BuiltinFormats.getBuiltinFormat(4)));
    styles.put("decimal_number_cell", style);

    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_LEFT);
    style.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM);
    style.setFont(cellFont);
    style.setWrapText(false);
    style.setDataFormat((short) BuiltinFormats.getBuiltinFormat("text"));
    styles.put("text_cell", style);

    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM);
    style.setFont(cellFont);
    style.setWrapText(false);
    style.setDataFormat(wb.createDataFormat()
            .getFormat(DateFormatConverter.convert(LocaleManager.currentLocale(), dateFormatPattern)));
    styles.put("date_cell", style);
    return styles;
}

From source file:org.jplus.hyberbin.excel.service.BaseExcelService.java

License:Apache License

/**
 * sheet ?/*ww w.  jav a  2s.c o m*/
 * @param sheet
 * @param row
 * @param length
 * @param data
 */
public static void addTitle(Sheet sheet, int row, int length, String data) {
    Row sheetRow = sheet.createRow(row);
    for (int i = 0; i < length; i++) {
        sheetRow.createCell(i);
    }
    CellStyle style = sheet.getWorkbook().createCellStyle(); // ?
    style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 
    style.setAlignment(HSSFCellStyle.ALIGN_CENTER);// 
    CellRangeAddress cellRangeAddress = new CellRangeAddress(row, row, 0, length - 1);
    sheet.addMergedRegion(cellRangeAddress);
    Cell cell = sheetRow.getCell(0);
    cell.setCellStyle(style);
    cell.setCellValue(data);
}

From source file:org.neo4art.colour.write.WriteFileCsv.java

License:Apache License

public void savePixel(Color[] c) {
    try {// w  ww.ja v  a2  s .com
        int i = 0;
        FileInputStream inp = new FileInputStream(csv);
        HSSFWorkbook workbook = new HSSFWorkbook(inp);
        HSSFSheet worksheet = workbook.getSheet("Pixel image");
        while (i < c.length) {
            HSSFRow row = worksheet.createRow(worksheet.getLastRowNum() + 1);
            CellStyle cellStyle = workbook.createCellStyle();
            cellStyle.setAlignment(CellStyle.ALIGN_CENTER);

            HSSFCell cell1 = row.createCell(0);
            cell1.setCellStyle(cellStyle);
            HSSFCell cell2 = row.createCell(1);
            cell2.setCellStyle(cellStyle);
            HSSFCell cell3 = row.createCell(2);
            cell3.setCellStyle(cellStyle);

            cell1.setCellValue(c[i].getRed());
            cell2.setCellValue(c[i].getGreen());
            cell3.setCellValue(c[i].getBlue());
            FileOutputStream fileOut = new FileOutputStream(csv);
            workbook.write(fileOut);
            i++;
        }
        workbook.close();
    } catch (Exception e) {

    }
}

From source file:org.neo4art.colour.write.WriteFileCsv.java

License:Apache License

public void saveReport(ColourAnalysis image) {
    try {//from www  . j a v  a 2  s  . co m
        Color[] temp = new Color[3];
        FileInputStream inp = new FileInputStream(csv);
        HSSFWorkbook workbook = new HSSFWorkbook(inp);

        HSSFSheet worksheet = workbook.getSheet("Report");
        CellStyle cellStyle = workbook.createCellStyle();
        cellStyle.setAlignment(CellStyle.ALIGN_CENTER);
        HSSFRow row = worksheet.createRow((short) 7);
        HSSFRow row1 = worksheet.createRow((short) 9);
        HSSFRow row3 = worksheet.createRow((short) 11);
        HSSFRow row4 = worksheet.createRow((short) 13);

        HSSFCell cell1 = row.createCell(0);
        cell1.setCellStyle(cellStyle);
        HSSFCell cell3 = row1.createCell(0);
        cell3.setCellStyle(cellStyle);
        HSSFCell cell4 = row3.createCell(0);
        cell4.setCellStyle(cellStyle);
        HSSFCell cell5 = row4.createCell(0);
        cell5.setCellStyle(cellStyle);

        cell1.setCellValue(image.getAverageClosestColour().getName());
        cell3.setCellValue(image.getMaximumClosestColour().getName());
        cell4.setCellValue(image.getMinimumClosestColour().getName());
        cell5.setCellValue(image.getIncrement());

        temp[0] = image.getAverageColour();
        temp[1] = image.getMinimumColour();
        temp[2] = image.getMaximumColour();
        int j = 1;
        for (int i = 0; i < 3; i++) {
            Color c = temp[i];

            HSSFRow row2 = worksheet.createRow((short) j);

            HSSFCell cell1a = row2.createCell(0);
            cell1a.setCellStyle(cellStyle);
            HSSFCell cell2a = row2.createCell(1);
            cell2a.setCellStyle(cellStyle);
            HSSFCell cell3a = row2.createCell(2);
            cell3a.setCellStyle(cellStyle);

            cell1a.setCellValue(c.getRed());
            cell2a.setCellValue(c.getGreen());
            cell3a.setCellValue(c.getBlue());

            FileOutputStream fileOut = new FileOutputStream(csv);
            workbook.write(fileOut);
            workbook.close();
            j = j + 2;
        }

    } catch (Exception e) {

    }
}

From source file:org.neo4art.colour.write.WriteFileCsv.java

License:Apache License

public void createSheet() {
    try {//from w w w .  j  a  v  a 2  s  .co m
        FileOutputStream fileOut = new FileOutputStream(csv);
        HSSFWorkbook workbook = new HSSFWorkbook();
        HSSFSheet worksheet = workbook.createSheet("Pixel image");
        HSSFRow row1 = worksheet.createRow((short) 0);

        HSSFCell cellA1 = row1.createCell(0);
        HSSFCell cellA2 = row1.createCell(1);
        HSSFCell cellA3 = row1.createCell(2);

        cellA1.setCellValue("RED");
        cellA2.setCellValue("GREEN");
        cellA3.setCellValue("BLUE");

        CellStyle cellStyle = workbook.createCellStyle();
        cellStyle.setAlignment(CellStyle.ALIGN_CENTER);
        HSSFSheet worksheetReport = workbook.createSheet("Report");
        HSSFRow rowReport = worksheetReport.createRow((short) 0);
        HSSFRow rowReport1 = worksheetReport.createRow((short) 2);
        HSSFRow rowReport2 = worksheetReport.createRow((short) 4);
        HSSFRow rowReport3 = worksheetReport.createRow((short) 6);
        HSSFRow rowReport4 = worksheetReport.createRow((short) 8);
        HSSFRow rowReport5 = worksheetReport.createRow((short) 10);
        HSSFRow rowReport6 = worksheetReport.createRow((short) 12);

        worksheetReport.addMergedRegion(new CellRangeAddress(0, 0, 0, 2));
        worksheetReport.addMergedRegion(new CellRangeAddress(2, 2, 0, 2));
        worksheetReport.addMergedRegion(new CellRangeAddress(4, 4, 0, 2));
        worksheetReport.addMergedRegion(new CellRangeAddress(6, 6, 0, 2));
        worksheetReport.addMergedRegion(new CellRangeAddress(7, 7, 0, 2));
        worksheetReport.addMergedRegion(new CellRangeAddress(8, 8, 0, 2));
        worksheetReport.addMergedRegion(new CellRangeAddress(9, 9, 0, 2));
        worksheetReport.addMergedRegion(new CellRangeAddress(10, 10, 0, 2));
        worksheetReport.addMergedRegion(new CellRangeAddress(11, 11, 0, 2));
        worksheetReport.addMergedRegion(new CellRangeAddress(12, 12, 0, 2));
        worksheetReport.addMergedRegion(new CellRangeAddress(13, 13, 0, 2));

        HSSFCell cellB1 = rowReport.createCell(0);
        cellB1.setCellStyle(cellStyle);
        HSSFCell cellB2 = rowReport1.createCell(0);
        cellB2.setCellStyle(cellStyle);
        HSSFCell cellB3 = rowReport2.createCell(0);
        cellB3.setCellStyle(cellStyle);
        HSSFCell cellB4 = rowReport3.createCell(0);
        cellB4.setCellStyle(cellStyle);
        HSSFCell cellB5 = rowReport4.createCell(0);
        cellB5.setCellStyle(cellStyle);
        HSSFCell cellB6 = rowReport5.createCell(0);
        cellB6.setCellStyle(cellStyle);
        HSSFCell cellB7 = rowReport6.createCell(0);
        cellB7.setCellStyle(cellStyle);

        cellB1.setCellValue("MAX RGB");
        cellB2.setCellValue("MIN RGB");
        cellB3.setCellValue("AVG RGB");
        cellB4.setCellValue("NAME RGB AVG");
        cellB5.setCellValue("NAME RGB MAX");
        cellB6.setCellValue("NAME RGB MIN");
        cellB7.setCellValue("INCREMENT");

        workbook.write(fileOut);
        workbook.close();
        fileOut.flush();
        fileOut.close();
    } catch (Exception e) {

    }
}

From source file:org.netxilia.impexp.impl.PoiUtils.java

License:Open Source License

public static CellStyle netxiliaStyle2Poi(Styles nxStyle, Workbook workbook, CellStyle poiStyle) {
    if (nxStyle == null) {
        return poiStyle;
    }//w w  w.  ja  v a2  s .c o  m
    poiStyle.setWrapText(nxStyle.contains(DefaultStyle.nowrap.getStyle()));

    // font
    short bold = nxStyle.contains(DefaultStyle.bold.getStyle()) ? Font.BOLDWEIGHT_BOLD : Font.BOLDWEIGHT_NORMAL;
    byte underline = nxStyle.contains(DefaultStyle.underline.getStyle()) ? Font.U_SINGLE : Font.U_NONE;
    boolean italic = nxStyle.contains(DefaultStyle.italic.getStyle());
    boolean strikeout = nxStyle.contains(DefaultStyle.strikeout.getStyle());
    Font defaultFont = workbook.getFontAt(poiStyle.getFontIndex());
    Font font = workbook.findFont(bold, defaultFont.getColor(), defaultFont.getFontHeight(),
            defaultFont.getFontName(), italic, strikeout, defaultFont.getTypeOffset(), underline);
    if (font == null) {
        font = workbook.createFont();
        font.setBoldweight(bold);
        font.setItalic(italic);
        font.setUnderline(underline);
        font.setStrikeout(strikeout);
    }
    poiStyle.setFont(font);

    // borders
    if (nxStyle.contains(DefaultStyle.borderLeft.getStyle())) {
        poiStyle.setBorderLeft(CellStyle.BORDER_THIN);
    }
    if (nxStyle.contains(DefaultStyle.borderRight.getStyle())) {
        poiStyle.setBorderRight(CellStyle.BORDER_THIN);
    }
    if (nxStyle.contains(DefaultStyle.borderTop.getStyle())) {
        poiStyle.setBorderTop(CellStyle.BORDER_THIN);
    }
    if (nxStyle.contains(DefaultStyle.borderBottom.getStyle())) {
        poiStyle.setBorderBottom(CellStyle.BORDER_THIN);
    }

    // align
    if (nxStyle.contains(DefaultStyle.alignLeft.getStyle())) {
        poiStyle.setAlignment(CellStyle.ALIGN_LEFT);
    } else if (nxStyle.contains(DefaultStyle.alignRight.getStyle())) {
        poiStyle.setAlignment(CellStyle.ALIGN_RIGHT);
    } else if (nxStyle.contains(DefaultStyle.alignCenter.getStyle())) {
        poiStyle.setAlignment(CellStyle.ALIGN_CENTER);
    } else if (nxStyle.contains(DefaultStyle.alignJustify.getStyle())) {
        poiStyle.setAlignment(CellStyle.ALIGN_JUSTIFY);
    }

    return poiStyle;
}

From source file:org.openelis.bean.DataViewBean.java

License:Open Source License

private CellStyle createStyle(HSSFWorkbook wb) {
    CellStyle headerStyle;
    Font font;//from www.ja va2s  .c  om

    font = wb.createFont();
    font.setColor(IndexedColors.WHITE.getIndex());
    headerStyle = wb.createCellStyle();
    headerStyle.setAlignment(CellStyle.ALIGN_LEFT);
    headerStyle.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM);
    headerStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
    headerStyle.setFillForegroundColor(IndexedColors.GREY_80_PERCENT.getIndex());
    headerStyle.setFont(font);

    return headerStyle;
}