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

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

Introduction

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

Prototype

short COLOR_RED

To view the source code for org.apache.poi.ss.usermodel Font COLOR_RED.

Click Source Link

Document

Dark Red color

Usage

From source file:cn.afterturn.easypoi.excel.imports.ExcelImportService.java

License:Apache License

private void createErrorCellStyle(Workbook workbook) {
    errorCellStyle = workbook.createCellStyle();
    Font font = workbook.createFont();
    font.setColor(Font.COLOR_RED);
    errorCellStyle.setFont(font);/*  ww w.ja va  2s.c om*/
}

From source file:co.com.codesoftware.logica.excel.ExcelLogica.java

/**
 * Funcion con la cual creo una fuente/*from  w w  w  . j a va 2  s .c o m*/
 */
public void crearfuente() {
    this.titulo = libro.createFont();
    this.titulo.setColor(Font.COLOR_RED);
    this.titulo.setBoldweight(Font.BOLDWEIGHT_BOLD);
    this.titulo.setItalic(true);
}

From source file:com.ah.ui.actions.admin.LicenseMgrAction.java

License:Open Source License

private void exportEntitleKeyInfo() {
    try {/*from w  w  w.j  ava 2  s.  co  m*/
        // create a new file
        FileOutputStream out = new FileOutputStream(ORDERKEYINFO_EXPORT_FILE_PATH);
        // create a new workbook
        HSSFWorkbook wb = new HSSFWorkbook();
        // create a new sheet
        HSSFSheet s = wb.createSheet("Sheet1");
        // declare a row object reference
        HSSFRow r = null;
        // declare a cell object reference
        HSSFCell c = null;
        // row index
        int rowNum = 0;
        // cell count
        int cellcount = 0;
        if (NmsUtil.isHMForOEM()) {
            cellcount = 7;
        } else if (getIsInHomeDomain()) {
            cellcount = 8;
        } else if (NmsUtil.isHostedHMApplication()) {
            cellcount = 9;
        }
        if (cellcount == 0) {
            return;
        } else {
            for (int i = 0; i < cellcount; i++) {
                s.setColumnWidth(i, getColumnWidthByIndex(i) * 256);
            }
        }
        // create cell style
        HSSFCellStyle cs = wb.createCellStyle();
        // create font object
        HSSFFont f = wb.createFont();

        //set font to 12 point type
        f.setFontHeightInPoints((short) 12);
        f.setFontName("Calibri");

        //set cell stlye
        cs.setFont(f);
        cs.setAlignment(CellStyle.ALIGN_CENTER);
        cs.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM);

        // create cell style
        HSSFCellStyle cs1 = wb.createCellStyle();
        // create font object
        HSSFFont f1 = wb.createFont();

        //set font to 12 point type
        f1.setFontHeightInPoints((short) 12);
        f1.setFontName("Calibri");
        f1.setBoldweight(Font.BOLDWEIGHT_BOLD);

        //set cell stlye
        cs1.setFont(f1);
        cs1.setAlignment(CellStyle.ALIGN_RIGHT);
        cs1.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM);

        // create cell style
        HSSFCellStyle cs2 = wb.createCellStyle();
        cs2.setFont(f1);
        cs2.setAlignment(CellStyle.ALIGN_CENTER);
        cs2.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM);

        // create cell style
        HSSFCellStyle cs3 = wb.createCellStyle();
        cs3.setFont(f);
        cs3.setAlignment(CellStyle.ALIGN_RIGHT);
        cs3.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM);

        // create cell style
        HSSFCellStyle cs4 = wb.createCellStyle();
        cs4.setFont(f1);
        cs4.setAlignment(CellStyle.ALIGN_LEFT);
        cs4.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM);

        // create cell style
        HSSFCellStyle cs5 = wb.createCellStyle();
        // create font object
        HSSFFont f2 = wb.createFont();

        //set font to 12 point type
        f2.setFontHeightInPoints((short) 12);
        f2.setFontName("Calibri");
        f2.setBoldweight(Font.BOLDWEIGHT_BOLD);
        f2.setColor(Font.COLOR_RED);
        cs5.setFont(f2);
        cs5.setAlignment(CellStyle.ALIGN_LEFT);
        cs5.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM);

        // create cell style
        HSSFCellStyle cs6 = wb.createCellStyle();
        cs6.setFont(f);
        cs6.setAlignment(CellStyle.ALIGN_LEFT);
        cs6.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM);

        // create a row
        // row 1
        s.addMergedRegion(new CellRangeAddress(0, 0, 0, cellcount - 1));
        r = s.createRow(rowNum++);
        c = r.createCell(0);
        c.setCellValue(MgrUtil.getUserMessage("admin.license.orderkey.export.title"));
        c.setCellStyle(cs);

        // row 2
        String sysInfo = "";
        if (getIsInHomeDomain()) {
            sysInfo = "System ID: " + getSystemId();
            // HiveManager Online user
        } else if (NmsUtil.isHostedHMApplication()) {
            sysInfo = "VHM ID: " + getDomain().getVhmID();
        }
        s.addMergedRegion(new CellRangeAddress(1, 1, 0, cellcount - 1));
        r = s.createRow(rowNum++);
        c = r.createCell(0);
        c.setCellValue(sysInfo);
        c.setCellStyle(cs);

        // row 3
        s.addMergedRegion(new CellRangeAddress(2, 2, 0, cellcount - 1));
        r = s.createRow(rowNum++);
        c = r.createCell(0);
        List<?> userInfo = QueryUtil.executeQuery(
                "SELECT email, company FROM " + UserRegInfoForLs.class.getSimpleName(), null,
                new FilterParams("owner.domainName", getDomain().getDomainName()));
        if (!userInfo.isEmpty()) {
            Object[] userInfos = (Object[]) userInfo.get(0);
            c.setCellValue(MgrUtil.getUserMessage("admin.license.orderkey.export.email.company",
                    new String[] { (String) userInfos[0], (String) userInfos[1] }));
        }
        c.setCellStyle(cs);

        // row 4
        r = s.createRow(rowNum++);

        // row 5
        r = s.createRow(rowNum++);

        // row 6 cell 1
        c = r.createCell(0);
        c.setCellValue(MgrUtil.getUserMessage("admin.license.orderkey.export.device.licensed"));
        c.setCellStyle(cs1);

        // row 6 cell 2
        c = r.createCell(1);
        c.setCellValue(licenseInfo.getHiveAps());
        c.setCellStyle(cs2);

        // device management info
        Map<String, Integer> apcount = HiveAPInfoFromeDatabase
                .getManagedDeviceTypeAndNumber(getDomain().getDomainName());
        int vpnCount = 0;
        int totalCount = 0;
        if (null != apcount) {
            Object[] typeNames = apcount.keySet().toArray();
            Arrays.sort(typeNames);
            for (Object typeName : typeNames) {

                // VPN Gateway VA does not belong to device
                if (MgrUtil.getEnumString("enum.hiveAp.model.10").equals(typeName)) {
                    vpnCount = apcount.get(typeName);
                } else {
                    r = s.createRow(rowNum++);
                    c = r.createCell(0);
                    c.setCellValue((String) typeName);
                    c.setCellStyle(cs3);

                    c = r.createCell(1);
                    c.setCellValue(apcount.get(typeName));
                    c.setCellStyle(cs);
                    totalCount += apcount.get(typeName);
                }
            }

        }

        // managed device total number cell1
        r = s.createRow(rowNum++);
        c = r.createCell(0);
        c.setCellValue(MgrUtil.getUserMessage("admin.license.orderkey.export.device.total"));
        c.setCellStyle(cs1);

        // managed device total number cell2
        c = r.createCell(1);
        c.setCellValue(totalCount);
        c.setCellStyle(cs2);

        // blank row
        r = s.createRow(rowNum++);

        // licensed VPN Gateway VA cell1
        r = s.createRow(rowNum++);
        c = r.createCell(0);
        c.setCellValue(MgrUtil.getUserMessage("admin.license.orderkey.export.cvg.licensed"));
        c.setCellStyle(cs1);

        // licensed VPN Gateway VA cell2
        c = r.createCell(1);
        c.setCellValue(licenseInfo.getCvgNumber());
        c.setCellStyle(cs2);

        // managed VPN Gateway VA cell1
        r = s.createRow(rowNum++);
        c = r.createCell(0);
        c.setCellValue(MgrUtil.getUserMessage("admin.license.orderkey.export.cvg.total"));
        c.setCellStyle(cs1);

        // managed VPN Gateway VA cell 2
        c = r.createCell(1);
        c.setCellValue(vpnCount);
        c.setCellStyle(cs2);

        // entitlement key information
        preparePage();
        if (null != page && !page.isEmpty()) {
            r = s.createRow(rowNum++);
            List<OrderHistoryInfo> normalKey = new ArrayList<>();
            List<OrderHistoryInfo> invalidKey = new ArrayList<>();
            List<OrderHistoryInfo> expiredKey = new ArrayList<>();

            for (Object obj : page) {
                OrderHistoryInfo orderInfo = (OrderHistoryInfo) obj;
                if (orderInfo.getStatusFlag() == OrderHistoryInfo.ENTITLE_KEY_STATUS_NORMAL
                        && orderInfo.getCvgStatusFlag() == OrderHistoryInfo.ENTITLE_KEY_STATUS_NORMAL) {
                    normalKey.add(orderInfo);
                } else if (orderInfo.getStatusFlag() == OrderHistoryInfo.ENTITLE_KEY_STATUS_DISABLE
                        || orderInfo.getCvgStatusFlag() == OrderHistoryInfo.ENTITLE_KEY_STATUS_DISABLE) {
                    invalidKey.add(orderInfo);
                } else {
                    expiredKey.add(orderInfo);
                }
            }

            if (!normalKey.isEmpty()) {

                // normal entitle key title
                r = s.createRow(rowNum++);
                setEntitlementKeyCellValue(cellcount, cs4, null, r, null, MgrUtil.getUserMessage("order.key"));

                // normal entitle key info
                for (OrderHistoryInfo keyInfo : normalKey) {
                    r = s.createRow(rowNum++);
                    setEntitlementKeyCellValue(cellcount, cs6, cs3, r, keyInfo, null);
                }
            }

            if (!invalidKey.isEmpty()) {

                if (!normalKey.isEmpty()) {
                    r = s.createRow(rowNum++);
                    r = s.createRow(rowNum++);
                }

                // invalid entitle key title
                r = s.createRow(rowNum++);
                setEntitlementKeyCellValue(cellcount, cs5, null, r, null,
                        MgrUtil.getUserMessage("admin.license.orderkey.export.invalidkey.title"));

                // invalid entitle key info
                for (OrderHistoryInfo keyInfo : invalidKey) {
                    r = s.createRow(rowNum++);
                    setEntitlementKeyCellValue(cellcount, cs6, cs3, r, keyInfo, null);
                }
            }

            if (!expiredKey.isEmpty()) {

                if (!normalKey.isEmpty() || !invalidKey.isEmpty()) {
                    r = s.createRow(rowNum++);
                    r = s.createRow(rowNum++);
                }

                // expired entitle key title
                r = s.createRow(rowNum++);
                setEntitlementKeyCellValue(cellcount, cs5, null, r, null,
                        MgrUtil.getUserMessage("admin.license.orderkey.export.expiredkey.title"));

                // expired entitle key info
                for (OrderHistoryInfo keyInfo : expiredKey) {
                    r = s.createRow(rowNum++);
                    setEntitlementKeyCellValue(cellcount, cs6, cs3, r, keyInfo, null);
                }
            }
        }

        // write the workbook to the output stream
        // close our file (don't blow out our file handles)
        wb.write(out);
        out.close();
        generateAuditLog(HmAuditLog.STATUS_SUCCESS,
                MgrUtil.getUserMessage("hm.audit.log.export.entitlement.key"));
    } catch (Exception ex) {
        generateAuditLog(HmAuditLog.STATUS_FAILURE,
                MgrUtil.getUserMessage("hm.audit.log.export.entitlement.key"));
        log.error("exportEntitleKeyInfo()", ex.getMessage());
    }
}

From source file:com.heimaide.server.common.utils.excel.ExportExcel.java

License:Open Source License

/**
 * ?/*  w w  w  .  j  a va  2s .  co  m*/
 * 
 * @param wb
 *            
 * @return ?
 */
private Map<String, CellStyle> createStyles(Workbook wb) {
    Map<String, CellStyle> styles = new HashMap<String, CellStyle>();

    CellStyle style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    Font titleFont = wb.createFont();
    titleFont.setFontName("Arial");
    titleFont.setFontHeightInPoints((short) 16);
    titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    style.setFont(titleFont);
    styles.put("title", style);
    style.setBorderTop(CellStyle.BORDER_THIN);
    style.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
    style.setBorderLeft(CellStyle.BORDER_THIN);
    style.setLeftBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
    style.setBorderBottom(CellStyle.BORDER_THIN);
    style.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());

    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_RIGHT);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    Font titleFont1 = wb.createFont();
    titleFont1.setFontName("Arial");
    titleFont1.setFontHeightInPoints((short) 10);
    titleFont1.setBoldweight(Font.BOLDWEIGHT_BOLD);
    titleFont1.setColor(Font.COLOR_RED);
    style.setFont(titleFont1);
    styles.put("title1", style);
    style.setBorderRight(CellStyle.BORDER_THIN);
    style.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
    style.setBorderTop(CellStyle.BORDER_THIN);
    style.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
    style.setBorderBottom(CellStyle.BORDER_THIN);
    style.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());

    style = wb.createCellStyle();
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setBorderRight(CellStyle.BORDER_THIN);
    style.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
    style.setBorderLeft(CellStyle.BORDER_THIN);
    style.setLeftBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
    style.setBorderTop(CellStyle.BORDER_THIN);
    style.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
    style.setBorderBottom(CellStyle.BORDER_THIN);
    style.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
    Font dataFont = wb.createFont();
    dataFont.setFontName("Arial");
    dataFont.setFontHeightInPoints((short) 10);
    style.setFont(dataFont);
    styles.put("data", style);

    style = wb.createCellStyle();
    style.cloneStyleFrom(styles.get("data"));
    style.setAlignment(CellStyle.ALIGN_LEFT);
    styles.put("data1", style);

    style = wb.createCellStyle();
    style.cloneStyleFrom(styles.get("data"));
    style.setAlignment(CellStyle.ALIGN_CENTER);
    styles.put("data2", style);

    style = wb.createCellStyle();
    style.cloneStyleFrom(styles.get("data"));
    style.setAlignment(CellStyle.ALIGN_RIGHT);
    styles.put("data3", style);

    style = wb.createCellStyle();
    style.cloneStyleFrom(styles.get("data"));
    // style.setWrapText(true);
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex());
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    Font headerFont = wb.createFont();
    headerFont.setFontName("Arial");
    headerFont.setFontHeightInPoints((short) 10);
    headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    headerFont.setColor(IndexedColors.WHITE.getIndex());
    style.setFont(headerFont);
    styles.put("header", style);

    return styles;
}

From source file:com.primovision.lutransport.core.util.TollCompanyTagUploadUtil.java

public static ByteArrayOutputStream createTollUploadErrorResponse(InputStream is, List<String> errors)
        throws IOException {
    POIFSFileSystem fs = new POIFSFileSystem(is);
    HSSFWorkbook wb = new HSSFWorkbook(fs);

    HSSFFont font = wb.createFont();/*from   w w w .ja  v a 2s  .  c  o  m*/
    font.setColor(Font.COLOR_RED);
    font.setBoldweight(Font.BOLDWEIGHT_BOLD);

    CellStyle cellStyle = wb.createCellStyle();
    cellStyle.setFont(font);

    HSSFSheet sheet = wb.getSheetAt(0);

    Row row = sheet.getRow(0);
    int lastCell = row.getLastCellNum();
    Cell cell = createExcelCell(sheet, row, lastCell, 256 * 100);
    cell.setCellStyle(cellStyle);
    cell.setCellValue("ERRORS");

    for (String anError : errors) {
        String lineNoStr = StringUtils.substringBefore(anError, ":");
        lineNoStr = StringUtils.substringAfter(lineNoStr, "Line ");
        Integer lineNo = new Integer(lineNoStr) - 1;

        row = sheet.getRow(lineNo);
        cell = createExcelCell(sheet, row, lastCell, 256 * 100);
        cell.setCellStyle(cellStyle);
        cell.setCellValue(anError);
    }

    return createOutputStream(wb);
}

From source file:com.primovision.lutransport.core.util.TollCompanyTagUploadUtil.java

public static ByteArrayOutputStream createTollUploadExceptionResponse(Exception e) {
    HSSFWorkbook wb = new HSSFWorkbook();

    HSSFFont font = wb.createFont();//  ww w .j a  v a2  s.  co m
    font.setColor(Font.COLOR_RED);
    font.setBoldweight(Font.BOLDWEIGHT_BOLD);

    CellStyle cellStyle = wb.createCellStyle();
    cellStyle.setFont(font);

    Sheet sheet = wb.createSheet();

    Row row = sheet.createRow(0);
    Cell cell = createExcelCell(sheet, row, 0, 256 * 100);
    cell.setCellStyle(cellStyle);
    cell.setCellValue("An error occurred while uploading!!!");

    return createOutputStream(wb);
}

From source file:de.viaboxx.nlstools.formats.MBExcelPersistencer.java

License:Apache License

private void initStyles(HSSFWorkbook wb) {
    // cache styles used to write text into cells
    HSSFCellStyle style = wb.createCellStyle();
    HSSFFont font = wb.createFont();/*from  w w  w  . ja  v a 2s.c o  m*/
    font.setBold(true);
    style.setFont(font);
    styles.put(STYLE_BOLD, style);

    style = wb.createCellStyle();
    font = wb.createFont();
    font.setItalic(true);
    style.setFont(font);
    styles.put(STYLE_ITALIC, style);

    style = wb.createCellStyle();
    font = wb.createFont();
    font.setItalic(true);
    font.setColor(Font.COLOR_RED);
    style.setFont(font);
    styles.put(STYLE_REVIEW, style);

    style = wb.createCellStyle();
    style.setFillPattern(FillPatternType.FINE_DOTS);
    style.setFillBackgroundColor(HSSFColor.HSSFColorPredefined.BLUE_GREY.getIndex());
    style.setFillForegroundColor(HSSFColor.HSSFColorPredefined.BLUE_GREY.getIndex());
    styles.put(STYLE_MISSING, style);

    style = wb.createCellStyle();
    style.setFillPattern(FillPatternType.FINE_DOTS);
    style.setFillBackgroundColor(HSSFColor.HSSFColorPredefined.BLUE_GREY.getIndex());
    style.setFillForegroundColor(HSSFColor.HSSFColorPredefined.BLUE_GREY.getIndex());
    style.setFont(font);
    styles.put(STYLE_MISSING_REVIEW, style);

    style = wb.createCellStyle();
    HSSFCreationHelper createHelper = wb.getCreationHelper();
    style.setDataFormat(createHelper.createDataFormat().getFormat("yyyy-dd-mm hh:mm"));
    styles.put(STYLE_DATETIME, style);
}

From source file:de.viaboxx.nlstools.formats.MBExcelPersistencer.java

License:Apache License

private boolean readSheet(MBBundle bundle) {
    if (sheet.getLastRowNum() == 0)
        return false;

    HSSFRow row = sheet.getRow(0);//  ww w.  ja va2 s.com
    if (row.getLastCellNum() < 1 || row.getCell(1) == null)
        return false;
    bundle.setBaseName(getStringValue(row.getCell(1)));

    row = sheet.getRow(1);
    if (row != null) {
        if (row.getCell(1) != null) {
            bundle.setInterfaceName(getStringValue(row.getCell(1)));
        }

        if (row.getCell(3) != null) {
            bundle.setSqldomain(getStringValue(row.getCell(3)));
        }
    }
    int firstCol = 2;

    rowNum = 3;
    row = sheet.getRow(rowNum++); // read locales

    String aliasOrDescriptionHeader = getStringValue(row.getCell(1)); // backward compatibility
    boolean aliasColumnAvailable = false;
    if (aliasOrDescriptionHeader != null && "Aliases".equals(aliasOrDescriptionHeader.trim())) {
        firstCol++;
        aliasColumnAvailable = true;
    }
    int colNum = firstCol;

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

    HSSFCell cell = row.getCell(colNum++);
    while (colNum <= row.getLastCellNum()) {
        if (cell != null) {
            locales.add(getStringValue(cell));
        }
        if (row.getLastCellNum() >= colNum) {
            cell = row.getCell(colNum++);
        } else {
            cell = null;
        }
    }

    row = sheet.getRow(rowNum++);
    while (row != null) {
        if (row.getCell(0) != null) {
            MBEntry entry = new MBEntry();
            bundle.getEntries().add(entry);
            entry.setKey(getStringValue(row.getCell(0)));
            if (aliasColumnAvailable) { // backward compatibility
                String aliasesCommaSeparated = getStringValue(row.getCell(1));
                if (aliasesCommaSeparated != null) {
                    StringTokenizer tokens = new StringTokenizer(aliasesCommaSeparated, ", ");
                    List<String> aliases = new ArrayList<String>();
                    while (tokens.hasMoreTokens()) {
                        aliases.add(tokens.nextToken());
                    }
                    entry.setAliases(aliases);
                }
            }
            if (row.getCell(firstCol - 1) != null) {
                entry.setDescription(getStringValue(row.getCell(firstCol - 1)));
            }
            colNum = firstCol;
            for (String each : locales) {
                cell = row.getCell(colNum++);
                if (cell != null) {
                    final String svalue = getStringValue(cell);
                    if (StringUtils.isNotEmpty(svalue) ||
                    // detect STYLE_MISSING
                            cell.getCellStyle()
                                    .getFillBackgroundColor() == HSSFColor.HSSFColorPredefined.BLUE_GREY
                                            .getIndex()
                            || cell.getCellStyle()
                                    .getFillForegroundColor() == HSSFColor.HSSFColorPredefined.BLUE_GREY
                                            .getIndex()
                            || cell.getCellStyle().getFont(wb).getColor() == Font.COLOR_RED) {
                        MBText text = new MBText();
                        text.setLocale(each);
                        text.setValue(svalue);
                        text.setReview(cell.getCellStyle().getFont(wb).getColor() == Font.COLOR_RED);
                        entry.getTexts().add(text);
                    }
                }
            }
        }
        row = sheet.getRow(rowNum++);
    }
    return true;
}

From source file:gregchen.Simulation.java

License:Open Source License

 private void initializeExcelFile()
{
   //short rownum;
   //Create a Data folder if it does not already exist
   File theDir = new File("Data");
   //if the directory does not exist, create it
   if(!theDir.exists())
   {/* w  w w  . j  a  va 2 s  .c  o m*/
      theDir.mkdir();
   }
   // create a new file
      
   if(fileCount == 0)
   {
      File file = null;
      do
      {
         fileCount++;
         file = new File("Data/Data " + fileCount + ".xls");
      }while(file.exists());
   }
      
   try {
      excelOut = new FileOutputStream("Data/Data " + fileCount + ".xls");
   } catch (FileNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
   }
      
   fileCount++;
      
   // create a new workbook
   wb = new HSSFWorkbook();
   // create a new sheet
   s = wb.createSheet();
   // declare a row object reference
   Row r = null;
   // declare a cell object reference
   Cell c = null;
   // create 3 cell styles
   CellStyle cs = wb.createCellStyle();
   CellStyle cs2 = wb.createCellStyle();
   CellStyle cs3 = wb.createCellStyle();
   DataFormat df = wb.createDataFormat();
   // create 2 fonts objects
   Font f = wb.createFont();
   Font f2 = wb.createFont();

   //set font 1 to 12 point type
   f.setFontHeightInPoints((short) 12);
   //make it blue
   f.setColor( (short)0xc );
   // make it bold
   //arial is the default font
   f.setBoldweight(Font.BOLDWEIGHT_BOLD);

   //set font 2 to 10 point type
   f2.setFontHeightInPoints((short) 10);
   //make it red
   f2.setColor( (short)Font.COLOR_RED );
   //make it bold
   f2.setBoldweight(Font.BOLDWEIGHT_BOLD);

   f2.setStrikeout( true );

   //set cell stlye
   cs.setFont(f);
   //set the cell format 
   cs.setDataFormat(df.getFormat("#,##0.0"));

   //set a thin border
   cs2.setBorderBottom(cs2.BORDER_THIN);
   //fill w fg fill color
   cs2.setFillPattern((short) CellStyle.SOLID_FOREGROUND);
   //set the cell format to text see DataFormat for a full list
   cs2.setDataFormat(HSSFDataFormat.getBuiltinFormat("text"));

   // set the font
   cs2.setFont(f2);

   // set the sheet name in Unicode
   wb.setSheetName(0, "Greg Chen");
   // in case of plain ascii
   // wb.setSheetName(0, "HSSF Test");
   // Make header cells
      
   r = s.createRow(0);
   c = r.createCell(7);
   c.setCellStyle(cs3);
      
   c.setCellValue("Initial number: " + initialNumber + " Number per release: " + numPerRelease
         + " Number Releases: " + numReleases + " Release Interval: " + releaseInterval
         + " Female lethal gene: " + fsRIDL);
      
   currentRow = 2;
   for (short cellnum = (short) 0; cellnum < 7; cellnum ++)
    {
        // create a numeric cell
        c = r.createCell(cellnum);
        // do some goofy math to demonstrate decimals
        String heading = null;
        switch(cellnum)
        {
        case 0:
           heading = "Day"; break;
        case 1:
           heading = "Total Population"; break;
        case 2:
           heading = "Male Population"; break;
        case 3:
           heading = "Female Population"; break;
        case 4:
           heading = "FF"; break;
        case 5:
           heading = "Ff"; break;
        case 6:
           heading = "ff"; break;
        }
           
        c.setCellValue(heading);

          
         // set this cell to the first cell style we defined
         c.setCellStyle(cs);
         // set the cell's string value to "Test"

        // make this column a bit wider
         if(cellnum > 0)
         {
            s.setColumnWidth((short) (cellnum), (short) ((300) / ((double) 1 / 20)));
         }
        r.setHeight((short) 800);
    }
   /*
   int rownum;
   for (rownum = (short) 0; rownum < 30; rownum++)
   {
       // create a row
       r = s.createRow(rownum);
      
       r.setHeight((short) 0x249);


       //
         
   }

   //draw a thick black border on the row at the bottom using BLANKS
   // advance 2 rows
   rownum++;
   rownum++;

   r = s.createRow(rownum);

   // define the third style to be the default
   // except with a thick black border at the bottom
   cs3.setBorderBottom(cs3.BORDER_THICK);

   */
      
   // write the workbook to the output stream
   // close our file (don't blow out our file handles)
          
}

From source file:org.geoserver.wfs.response.ExcelCellStyles.java

License:Open Source License

public ExcelCellStyles(Workbook wb) {
    CreationHelper helper = wb.getCreationHelper();
    DataFormat fmt = helper.createDataFormat();

    dateStyle = wb.createCellStyle();//from  www  .j  a  va 2s.  c  om
    dateStyle.setDataFormat(fmt.getFormat("yyyy-mm-dd hh:mm:ss"));

    headerStyle = wb.createCellStyle();
    Font headerFont = wb.createFont();
    headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    headerStyle.setFont(headerFont);

    warningStyle = wb.createCellStyle();
    Font warningFont = wb.createFont();
    warningFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    warningFont.setColor(Font.COLOR_RED);
    warningStyle.setFont(warningFont);
}