Example usage for org.apache.poi.hssf.usermodel HSSFCell setCellValue

List of usage examples for org.apache.poi.hssf.usermodel HSSFCell setCellValue

Introduction

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

Prototype

@SuppressWarnings("fallthrough")
public void setCellValue(boolean value) 

Source Link

Document

set a boolean value for the cell

Usage

From source file:edu.wisc.ssec.mcidasv.control.cyclone.StormDisplayState.java

License:Open Source License

/**
 * _more_/* ww w.  j a v  a  2  s.  c o m*/
 * 
 * @param wb
 *            _more_
 * @param track
 *            _more_
 * @param sheetNames
 *            _more_
 */
protected void write(HSSFWorkbook wb, StormTrack track, Hashtable sheetNames) {
    int cnt = 0;
    String dateString = track.getStartTime().formattedString("yyyy-MM-dd hhmm", DateUtil.TIMEZONE_GMT);
    String sheetName = track.getWay() + " - " + dateString;
    if (sheetName.length() > 30) {
        sheetName = sheetName.substring(0, 29);
    }
    // The sheet name length is limited
    while (sheetNames.get(sheetName) != null) {
        sheetName = (cnt++) + " " + sheetName;
        if (sheetName.length() > 30) {
            sheetName = sheetName.substring(0, 29);
        }
    }
    sheetNames.put(sheetName, sheetName);
    HSSFSheet sheet = wb.createSheet(sheetName);

    int rowCnt = 0;
    List<StormParam> params = track.getParams();
    HSSFCell cell;
    HSSFRow row;

    for (StormTrackPoint stp : track.getTrackPoints()) {
        if (rowCnt == 0) {
            row = sheet.createRow((short) rowCnt++);
            row.createCell(0).setCellValue(new HSSFRichTextString("Time"));
            row.createCell(1).setCellValue(new HSSFRichTextString("Latitude"));
            row.createCell(2).setCellValue(new HSSFRichTextString("Longitude"));
            for (int colIdx = 0; colIdx < params.size(); colIdx++) {
                row.createCell((colIdx + 3))
                        .setCellValue(new HSSFRichTextString(params.get(colIdx).toString()));
            }
        }
        row = sheet.createRow((short) rowCnt++);
        row.createCell(0).setCellValue(new HSSFRichTextString(stp.getTime().toString()));
        row.createCell(1).setCellValue(stp.getLocation().getLatitude().getValue());
        row.createCell(2).setCellValue(stp.getLocation().getLongitude().getValue());
        for (int colIdx = 0; colIdx < params.size(); colIdx++) {
            Real r = stp.getAttribute(params.get(colIdx));
            cell = row.createCell((colIdx + 3));
            cell.setCellValue(r.getValue());
        }
    }
}

From source file:egovframework.rte.fdl.excel.EgovExcelSXSSFServiceTest.java

License:Apache License

/**
 * [Flow #-4]   ?  :  ? ? ?(Header, Footer)? 
 *///w w  w .j  a v a2s .co m
@Test
public void testModifyDocAttribute() throws Exception {

    try {
        log.debug("testModifyDocAttribute start....");

        StringBuffer sb = new StringBuffer();
        sb.append(fileLocation).append("/").append("testModifyDocAttribute.xls");

        if (EgovFileUtil.isExistsFile(sb.toString())) {
            EgovFileUtil.delete(new File(sb.toString()));

            log.debug("Delete file...." + sb.toString());
        }

        HSSFWorkbook wbTmp = new HSSFWorkbook();
        wbTmp.createSheet();

        //  ? ?
        excelService.createWorkbook(wbTmp, sb.toString());

        //  ? 
        HSSFWorkbook wb = excelService.loadWorkbook(sb.toString());
        log.debug("testModifyCellContents after loadWorkbook....");

        HSSFSheet sheet = wb.createSheet("doc test sheet");

        HSSFRow row = sheet.createRow(1);
        HSSFCell cell = row.createCell(1);
        cell.setCellValue(new HSSFRichTextString("Header/Footer Test"));

        // Header
        HSSFHeader header = sheet.getHeader();
        header.setCenter("Center Header");
        header.setLeft("Left Header");
        header.setRight(HSSFHeader.font("Stencil-Normal", "Italic") + HSSFHeader.fontSize((short) 16)
                + "Right Stencil-Normal Italic font and size 16");

        // Footer
        HSSFFooter footer = sheet.getFooter();
        footer.setCenter(HSSFHeader.font("Fixedsys", "Normal") + HSSFHeader.fontSize((short) 12) + "- 1 -");
        log.debug("Style is ... " + HSSFHeader.font("Fixedsys", "Normal") + HSSFHeader.fontSize((short) 12)
                + "- 1 -");
        footer.setLeft("Left Footer");
        footer.setRight("Right Footer");

        //  ? 
        FileOutputStream out = new FileOutputStream(sb.toString());
        wb.write(out);
        out.close();

        assertTrue(EgovFileUtil.isExistsFile(sb.toString()));

        //////////////////////////////////////////////////////////////////////////
        // ?
        HSSFWorkbook wbT = excelService.loadWorkbook(sb.toString());
        HSSFSheet sheetT = wbT.getSheet("doc test sheet");

        HSSFHeader headerT = sheetT.getHeader();
        assertEquals("Center Header", headerT.getCenter());
        assertEquals("Left Header", headerT.getLeft());
        assertEquals(HSSFHeader.font("Stencil-Normal", "Italic") + HSSFHeader.fontSize((short) 16)
                + "Right Stencil-Normal Italic font and size 16", headerT.getRight());

        HSSFFooter footerT = sheetT.getFooter();
        assertEquals("Right Footer", footerT.getRight());
        assertEquals("Left Footer", footerT.getLeft());
        assertEquals(HSSFHeader.font("Fixedsys", "Normal") + HSSFHeader.fontSize((short) 12) + "- 1 -",
                footerT.getCenter());

    } catch (Exception e) {
        log.error(e.toString());
        throw new Exception(e);
    } finally {
        log.debug("testModifyDocAttribute end....");
    }
}

From source file:egovframework.rte.fdl.excel.EgovExcelSXSSFServiceTest.java

License:Apache License

/**
 * [Flow #-5]    :  ?? ?  ? ?  /*from  w ww .ja  v  a 2s .  co  m*/
 */
@Test
public void testGetCellContents() throws Exception {

    try {
        log.debug("testGetCellContents start....");

        StringBuffer sb = new StringBuffer();
        sb.append(fileLocation).append("/").append("testGetCellContents.xls");

        if (EgovFileUtil.isExistsFile(sb.toString())) {
            EgovFileUtil.delete(new File(sb.toString()));

            log.debug("Delete file...." + sb.toString());
        }

        HSSFWorkbook wbTmp = new HSSFWorkbook();
        wbTmp.createSheet();

        //  ? ?
        excelService.createWorkbook(wbTmp, sb.toString());

        //  ? 
        HSSFWorkbook wb = excelService.loadWorkbook(sb.toString());
        log.debug("testGetCellContents after loadWorkbook....");

        HSSFSheet sheet = wb.createSheet("cell test sheet");

        HSSFCellStyle cs = wb.createCellStyle();
        cs = wb.createCellStyle();
        cs.setWrapText(true);

        for (int i = 0; i < 100; i++) {
            HSSFRow row = sheet.createRow(i);
            for (int j = 0; j < 5; j++) {
                HSSFCell cell = row.createCell(j);
                cell.setCellValue(new HSSFRichTextString("row " + i + ", cell " + j));
                cell.setCellStyle(cs);
            }
        }

        //  ? 
        FileOutputStream out = new FileOutputStream(sb.toString());
        wb.write(out);
        out.close();

        //////////////////////////////////////////////////////////////////////////
        // ?
        HSSFWorkbook wbT = excelService.loadWorkbook(sb.toString());
        HSSFSheet sheetT = wbT.getSheet("cell test sheet");

        for (int i = 0; i < 100; i++) {
            HSSFRow row1 = sheetT.getRow(i);
            for (int j = 0; j < 5; j++) {
                HSSFCell cell1 = row1.getCell(j);
                log.debug("row " + i + ", cell " + j + " : " + cell1.getRichStringCellValue());
                assertEquals("row " + i + ", cell " + j, cell1.getRichStringCellValue().toString());
            }
        }

    } catch (Exception e) {
        log.error(e.toString());
        throw new Exception(e);
    } finally {
        log.debug("testGetCellContents end....");
    }
}

From source file:egovframework.rte.fdl.excel.EgovExcelSXSSFServiceTest.java

License:Apache License

/**
 * [Flow #-6]  ?  :  ? ?(?, ? )? //from ww  w . j  a v a 2  s . c o m
 */
@Test
public void testModifyCellAttribute() throws Exception {

    try {
        log.debug("testModifyCellAttribute start....");

        StringBuffer sb = new StringBuffer();
        sb.append(fileLocation).append("/").append("testModifyCellAttribute.xls");

        if (EgovFileUtil.isExistsFile(sb.toString())) {
            EgovFileUtil.delete(new File(sb.toString()));

            log.debug("Delete file...." + sb.toString());
        }

        HSSFWorkbook wbTmp = new HSSFWorkbook();
        wbTmp.createSheet();

        //  ? ?
        excelService.createWorkbook(wbTmp, sb.toString());

        //  ? 
        HSSFWorkbook wb = excelService.loadWorkbook(sb.toString());
        log.debug("testModifyCellAttribute after loadWorkbook....");

        HSSFSheet sheet = wb.createSheet("cell test sheet2");
        //           sheet.setColumnWidth((short) 3, (short) 200);   // column Width

        HSSFCellStyle cs = wb.createCellStyle();
        HSSFFont font = wb.createFont();
        font.setFontHeight((short) 16);
        font.setBoldweight((short) 3);
        font.setFontName("fixedsys");

        cs.setFont(font);
        cs.setAlignment(HSSFCellStyle.ALIGN_RIGHT); // cell 
        cs.setWrapText(true);

        for (int i = 0; i < 100; i++) {
            HSSFRow row = sheet.createRow(i);
            //              row.setHeight((short)300); // row? height 

            for (int j = 0; j < 5; j++) {
                HSSFCell cell = row.createCell(j);
                cell.setCellValue(new HSSFRichTextString("row " + i + ", cell " + j));
                cell.setCellStyle(cs);
            }
        }

        //  ? 
        FileOutputStream out = new FileOutputStream(sb.toString());
        wb.write(out);
        out.close();

        //////////////////////////////////////////////////////////////////////////
        // ?
        HSSFWorkbook wbT = excelService.loadWorkbook(sb.toString());
        HSSFSheet sheetT = wbT.getSheet("cell test sheet2");
        log.debug("getNumCellStyles : " + wbT.getNumCellStyles());

        HSSFCellStyle cs1 = wbT.getCellStyleAt((short) (wbT.getNumCellStyles() - 1));

        HSSFFont fontT = cs1.getFont(wbT);
        log.debug("font getFontHeight : " + fontT.getFontHeight());
        log.debug("font getBoldweight : " + fontT.getBoldweight());
        log.debug("font getFontName : " + fontT.getFontName());
        log.debug("getAlignment : " + cs1.getAlignment());
        log.debug("getWrapText : " + cs1.getWrapText());

        for (int i = 0; i < 100; i++) {
            HSSFRow row1 = sheetT.getRow(i);
            for (int j = 0; j < 5; j++) {
                HSSFCell cell1 = row1.getCell(j);
                log.debug("row " + i + ", cell " + j + " : " + cell1.getRichStringCellValue());
                assertEquals(16, fontT.getFontHeight());
                assertEquals(3, fontT.getBoldweight());
                assertEquals(HSSFCellStyle.ALIGN_RIGHT, cs1.getAlignment());
                assertTrue(cs1.getWrapText());
            }
        }

    } catch (Exception e) {
        log.error(e.toString());
        throw new Exception(e);
    } finally {
        log.debug("testModifyCellAttribute end....");
    }
}

From source file:eionet.gdem.conversion.excel.writer.ExcelConversionHandler.java

License:Mozilla Public License

@Override
public void addCell(String type, String str_value, String style_name) {
    HSSFSheet _sheet = wb.getSheetAt(currentSheet);
    HSSFRow _row = _sheet.getRow(currentRow);
    HSSFCell _cell = _row.createCell((currentCell));

    Double number_value = null;//  ww w  .j  a va2  s  . c om
    Boolean boolean_value = null;
    boolean isNumber = false;
    boolean isBoolean = false;
    if (type == null) {
        type = (String) getDefaultParams("data_type");
    }
    if (type != null) {
        if (type.equals("float") || type.equals("number")) {
            if (str_value != null) {
                try {
                    number_value = new Double(str_value);
                    isNumber = true;
                } catch (Exception e) {
                    // the value is not number, it will be inserted as a string
                    // System.out.println(e.toString());
                }
            } else {
                isNumber = true;
            }
        } else if (type.equals("boolean")) {
            if (str_value != null) {
                try {
                    boolean_value = new Boolean(str_value);
                    isBoolean = true;
                } catch (Exception e) {
                    // the value is not boolean, it will be inserted as a string
                    // System.out.println(e.toString());
                }
            } else {
                isBoolean = true;
            }
        } else if (type.equals("date")) {
            if (str_value != null) {
                try {
                    // cellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("yyyymmdd"));

                    /*
                     *
                     * The way how to handle user defined formats not supported right now HSSFDataFormat format =
                     * wb.createDataFormat(); HSSFCellStyle style = wb.createCellStyle();
                     * style.setDataFormat(format.getFormat("yyyymmdd")); _cell.setCellStyle(style);
                     */
                    // cellStyle.setDataFormat(new HSSFDataFormat("yyyymmdd"));
                    /*
                     * try{ l_value=Long.parseLong(value); System.out.println(String.valueOf(l_value)); isLong=true; }
                     * catch(Exception e){ System.out.println(e.toString()); }
                     */
                    /*
                     * if (isLong){ Date d = new Date(); _cell.setCellStyle(cellStyle); //_cell.setCellValue(d);
                     * _cell.setCellValue(value); //System.out.println(d.toString()); isDate=true; } else
                     * _cell.setCellValue(value);
                     */
                    // System.out.println("hh");

                } catch (Exception e) {
                    System.out.println(e.toString());
                }
            }
        }
    }
    if (isNumber) {
        if (number_value != null) {
            _cell.setCellValue(number_value.doubleValue());
        }
        _cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
    } else if (isBoolean) {
        if (boolean_value != null) {
            _cell.setCellValue(boolean_value.booleanValue());
        }
        _cell.setCellType(HSSFCell.CELL_TYPE_BOOLEAN);
    } else {
        _cell.setCellType(HSSFCell.CELL_TYPE_STRING);
        // _cell.setEncoding(HSSFCell.ENCODING_UTF_16 );//
        _cell.setCellValue(str_value);
    }

    short idx = -1;
    if (style_name != null) {
        idx = getStyleIdxByName(style_name, ExcelStyleIF.STYLE_FAMILY_TABLE_CELL);
    }

    if (idx < 0) {
        Short short_idx = (Short) getDefaultParams("style");
        if (short_idx != null) {
            idx = short_idx.shortValue();
        }
    }

    if (idx > -1) {
        _cell.setCellStyle(wb.getCellStyleAt(idx));
    }
    // calculates the col with according to the first row
    if (currentRow == 0 && idx > -1) {
        short colStyleWidth = 0;
        HSSFCellStyle style = wb.getCellStyleAt(idx);
        int f_i = style.getFontIndex();
        HSSFFont font = wb.getFontAt((short) f_i);
        // character size
        short size = font.getFontHeightInPoints();
        if (columns.size() > currentCell) {
            RowColumnDefinition column = columns.get(currentCell);
            String column_style_name = column.getStyleName() == null ? "" : column.getStyleName();
            ExcelStyleIF definedStyle = getStyleByName(column_style_name, ExcelStyleIF.STYLE_FAMILY_TABLE_CELL);
            if (definedStyle != null) {
                colStyleWidth = definedStyle.getColumnWidth();
            }
        }
        short width = (short) (_sheet.getDefaultColumnWidth() * size * 25);
        if (colStyleWidth > 0) {
            width = colStyleWidth;
        } else if (str_value.length() > 0) {
            width = (short) (str_value.length() * size * 50);
        }
        _sheet.setColumnWidth(currentCell, width);
    }
    currentCell = _cell.getColumnIndex() + 1;
    // System.out.println("Cell" + currentCell+ "-" + value);
}

From source file:es.jamisoft.comun.io.excel.ExcelGenerator.java

License:Apache License

/**
 * Este mtodo se encargara de rellenar las celdas con las columnas identificadas.
 *
 * @param data Coleccin con la que se desea crear  el fichero Excel.
 * @param wb Objeto Excel./*  ww  w  .  j  a v  a2s  .co m*/
 * @param columns Mapa con las cabeceras que se mostrarn en el fichero Excel.
 * @param getterMethods Elementos identificados con los que se rellenarn las celdas.
 * @param pageNumber Nmero de pagina que se generar.
 * @throws Exception
 */
private void procesPage(List<?> data, HSSFWorkbook wb, List<Header> columns, Map<String, Method> getterMethods,
        int pageNumber) throws Exception {
    HSSFSheet sheet = wb.createSheet("Sheet " + pageNumber);

    createHeader(sheet, columns);

    for (int i = 1; i <= data.size(); i++) {

        // Create a row and put some cells in it. Rows are 0 based.
        HSSFRow row = sheet.createRow(i);
        Object item = data.get(i - 1);

        // Iterar sobre los elementos y en funcion de los mapeos generar la
        // cell
        for (int j = 0; j < columns.size(); j++) {
            HSSFCell cell = row.createCell(j);
            Method getter = getterMethods.get(columns.get(j).getIdColumn());
            HSSFRichTextString v = new HSSFRichTextString(String.valueOf(getter.invoke(item, (Object[]) null)));

            cell.setCellValue(v);
            cell.setCellStyle(ep.getBodyStyle());
        }

        // Adjust column with the content
        if (ep.isAdjust()) {
            for (int k = 0; k < columns.size(); k++) {
                sheet.autoSizeColumn((short) k);
            }
        }
    }
}

From source file:es.jamisoft.comun.io.excel.ExcelGenerator.java

License:Apache License

/**
 * Este mtodo se encargar de colocar la cabecera a la pgina.
 *
 * @param sheet Pgina de Excel a la que se le tiene que crear la cabecera.
 * @param columns Mapa con las cabeceras que se mostrarn en el fichero Excel.
 *//*w ww  .ja v a  2s. c om*/
private void createHeader(HSSFSheet sheet, List<Header> columns) {
    HSSFRow header = sheet.createRow(0);

    for (int i = 0; i < columns.size(); i++) {
        HSSFCell c = header.createCell(i);
        HSSFRichTextString t = new HSSFRichTextString(columns.get(i).getTitle());

        c.setCellValue(t);
        c.setCellStyle(ep.getHeaderStyle());
    }
}

From source file:esd.common.PoiCreateExcel.java

License:Open Source License

/**
 * ???/*from w w  w  .  ja  v a  2  s  .  c  o  m*/
 * 
 * @param FilePath
 * @param jobList
 * @return
 */
public static boolean createJobExcel(String FilePath, List<Job> jobList) {
    // Excel Workbook,excel
    HSSFWorkbook wb = new HSSFWorkbook();
    // Excelsheet,exceltab
    HSSFSheet sheet = wb.createSheet("sheet1");
    // excel?
    sheet.setColumnWidth(0, 4000);
    sheet.setColumnWidth(1, 3500);

    // Excel?
    HSSFRow headRow = sheet.createRow(0);
    HSSFCell headell = headRow.createCell(0);
    // ???
    headell = headRow.createCell(0);
    headell.setCellValue("????");
    headell = headRow.createCell(1);
    headell.setCellValue("?");
    headell = headRow.createCell(2);
    headell.setCellValue("");
    headell = headRow.createCell(3);
    headell.setCellValue("");
    headell = headRow.createCell(4);
    headell.setCellValue("???");
    headell = headRow.createCell(5);
    headell.setCellValue("");

    headell = headRow.createCell(6);
    headell.setCellValue("?");
    headell = headRow.createCell(7);
    headell.setCellValue("???");
    headell = headRow.createCell(8);
    headell.setCellValue("?");
    headell = headRow.createCell(9);
    headell.setCellValue("?");
    headell = headRow.createCell(10);
    headell.setCellValue("??");

    headell = headRow.createCell(11);
    headell.setCellValue("?");
    headell = headRow.createCell(12);
    headell.setCellValue("?");
    headell = headRow.createCell(13);
    headell.setCellValue("??");
    headell = headRow.createCell(14);
    headell.setCellValue("");

    headell = headRow.createCell(15);
    headell.setCellValue("? ");
    headell = headRow.createCell(16);
    headell.setCellValue("?");
    headell = headRow.createCell(17);
    headell.setCellValue("");
    headell = headRow.createCell(18);
    headell.setCellValue("????");
    headell = headRow.createCell(19);
    headell.setCellValue("????");

    headell = headRow.createCell(20);
    headell.setCellValue("?/?");
    headell = headRow.createCell(21);
    headell.setCellValue("");
    headell = headRow.createCell(22);
    headell.setCellValue("?");
    headell = headRow.createCell(23);
    headell.setCellValue("??");
    headell = headRow.createCell(24);
    headell.setCellValue("??");

    for (int i = 1; i <= jobList.size(); i++) {
        Job job = jobList.get(i - 1);
        // Excel?
        HSSFRow row = sheet.createRow(i);
        HSSFCell cell = row.createCell(0);
        // ???
        cell = row.createCell(0);
        cell.setCellValue(job.getName());
        cell = row.createCell(1);
        cell.setCellValue(job.getHireNumber());
        cell = row.createCell(2);
        cell.setCellValue(job.getSalary());
        cell = row.createCell(3);
        cell.setCellValue(job.getEducation());
        cell = row.createCell(4);
        cell.setCellValue(job.getExperience());
        cell = row.createCell(5);
        cell.setCellValue(job.getGender());

        cell = row.createCell(6);
        cell.setCellValue(job.getAge());
        cell = row.createCell(7);
        cell.setCellValue(job.getDescription());
        cell = row.createCell(8);
        cell.setCellValue(job.getProvideBenefit());
        cell = row.createCell(9);
        cell.setCellValue(job.getContactPerson());
        cell = row.createCell(10);
        cell.setCellValue(job.getContactTel());

        cell = row.createCell(11);
        cell.setCellValue(job.getContactEmail());
        if (job.getViewCount() != null) {
            cell = row.createCell(12);
            cell.setCellValue(job.getViewCount());
        }
        cell = row.createCell(13);
        cell.setCellValue(job.getNature());
        cell = row.createCell(14);
        cell.setCellValue(job.getEffectiveDays());
        cell = row.createCell(15);
        // cell.setCellValue(job.getIsActiveEffectiveTime());

        if (job.getEffectiveTime() != null) {
            SimpleDateFormat dateFm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // ??
            String effectiveTimeString = dateFm.format(job.getEffectiveTime());
            cell = row.createCell(16);
            cell.setCellValue(effectiveTimeString);
        }

        if (job.getWorkPlace() != null) {
            if (job.getWorkPlace().getCode() != null && !"".equals(job.getWorkPlace().getCode())) {
                cell = row.createCell(17);
                cell.setCellValue(job.getWorkPlace().getName());
            }
        }

        if (job.isBed() == true) {
            cell = row.createCell(18);
            cell.setCellValue("");
        } else if (job.isBed() == false) {
            cell = row.createCell(18);
            cell.setCellValue("?");
        }

        if (job.isLunch() == true) {
            cell = row.createCell(19);
            cell.setCellValue("");
        } else if (job.isLunch() == false) {
            cell = row.createCell(19);
            cell.setCellValue("?");
        }

        cell = row.createCell(20);
        cell.setCellValue(job.getCheckStatus());
        cell = row.createCell(21);
        cell.setCellValue(job.getMark());

        if (job.getCompany() != null) {

            cell = row.createCell(22);
            cell.setCellValue(job.getCompany().getName());
        }
        if (job.getArea() != null) {
            if (job.getArea().getCode() != null && !"".equals(job.getArea().getCode())) {
                cell = row.createCell(23);
                cell.setCellValue(job.getArea().getName());
            }
        }

        if (job.getJobCategory() != null) {
            if (job.getJobCategory().getCode() != null && !"".equals(job.getJobCategory().getCode())) {
                cell = row.createCell(24);
                cell.setCellValue(job.getJobCategory().getName());
            }
        }
    }
    try {
        FileOutputStream os = new FileOutputStream(FilePath);
        wb.write(os);
        os.flush();
        os.close();
        jobList.clear();
        jobList = null;
        os = null;
        wb = null;
        System.gc();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return true;
}

From source file:esd.common.PoiCreateExcel.java

License:Open Source License

/**
 * ???// w w w.  j  a v a 2  s  . c  o  m
 * 
 * @param FilePath
 * @param companyList
 * @return
 */
public static boolean createComapnyExcel(String FilePath, List<Company> companyList) {
    // Excel Workbook,excel
    HSSFWorkbook wb = new HSSFWorkbook();
    // Excelsheet,exceltab
    HSSFSheet sheet = wb.createSheet("sheet1");
    // excel?
    sheet.setColumnWidth(0, 4000);
    sheet.setColumnWidth(1, 3500);

    // Excel?
    HSSFRow headRow = sheet.createRow(0);
    HSSFCell headell = headRow.createCell(0);
    // ???
    headell = headRow.createCell(0);
    headell.setCellValue("???");
    headell = headRow.createCell(1);
    headell.setCellValue("");
    headell = headRow.createCell(2);
    headell.setCellValue("?");
    headell = headRow.createCell(3);
    headell.setCellValue("??");
    headell = headRow.createCell(4);
    headell.setCellValue("?");
    headell = headRow.createCell(5);
    headell.setCellValue("");

    headell = headRow.createCell(6);
    headell.setCellValue("?");
    headell = headRow.createCell(7);
    headell.setCellValue("??");
    headell = headRow.createCell(8);
    headell.setCellValue("?");
    headell = headRow.createCell(9);
    headell.setCellValue("?");
    headell = headRow.createCell(10);
    headell.setCellValue("??");

    headell = headRow.createCell(11);
    headell.setCellValue("?");
    headell = headRow.createCell(12);
    headell.setCellValue("???");
    headell = headRow.createCell(13);
    headell.setCellValue("ID");
    headell = headRow.createCell(14);
    headell.setCellValue("?");
    headell = headRow.createCell(15);
    headell.setCellValue("?");

    headell = headRow.createCell(16);
    headell.setCellValue("?");
    headell = headRow.createCell(17);
    headell.setCellValue(" ?");
    headell = headRow.createCell(18);
    headell.setCellValue("");
    headell = headRow.createCell(19);
    headell.setCellValue("?");
    // headell = headRow.createCell(20);
    // headell.setCellValue("?");

    for (int i = 1; i <= companyList.size(); i++) {
        Company company = companyList.get(i - 1);
        // Excel?
        HSSFRow row = sheet.createRow(i);
        HSSFCell cell = row.createCell(0);
        // ???
        // ???
        cell = row.createCell(0);
        cell.setCellValue(company.getName());
        // 
        cell = row.createCell(1);
        cell.setCellValue(company.getCorporateRepresentative());
        // ?
        cell = row.createCell(2);
        cell.setCellValue(company.getContactPerson());
        // ??
        cell = row.createCell(3);
        cell.setCellValue(company.getTelephone());
        // ?
        cell = row.createCell(4);
        cell.setCellValue(company.getContactDept());
        // 
        cell = row.createCell(5);
        cell.setCellValue(company.getFax());
        // ?
        cell = row.createCell(6);
        cell.setCellValue(company.getEmail());
        // ??
        cell = row.createCell(7);
        cell.setCellValue(company.getAddress());
        // ?
        cell = row.createCell(8);
        cell.setCellValue(company.getIntroduction());
        // ?
        cell = row.createCell(9);
        cell.setCellValue(company.getOrganizationCode());
        // ??
        cell = row.createCell(10);
        cell.setCellValue(company.getCommercialCode());
        // ?
        cell = row.createCell(11);
        cell.setCellValue(company.getTaxCode());
        // ???
        cell = row.createCell(12);
        cell.setCellValue(company.getSocialSecurityCode());
        // ID
        cell = row.createCell(13);
        cell.setCellValue(company.getWebSiteId());
        // ?
        cell = row.createCell(14);
        cell.setCellValue(company.getLaoWangCode());
        // ?
        cell = row.createCell(15);
        cell.setCellValue(company.getScale());
        // ?
        cell = row.createCell(16);
        cell.setCellValue(company.getNature());
        // ?
        cell = row.createCell(17);
        cell.setCellValue(company.getEconomyType());
        // 
        cell = row.createCell(18);
        cell.setCellValue(company.getRemark());
        // ?
        if (company.getViewCount() != null) {
            cell = row.createCell(19);
            cell.setCellValue(company.getViewCount());
        }
        // cell = row.createCell(20);
        // cell.setCellValue(company.getCheckStatus());

    }
    try {
        FileOutputStream os = new FileOutputStream(FilePath);
        wb.write(os);
        os.flush();
        os.close();
        companyList.clear();
        companyList = null;
        os = null;
        wb = null;
        System.gc();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return true;
}

From source file:esd.common.PoiCreateExcel.java

License:Open Source License

/**
 * ?//from  ww  w. j  ava2s.c o  m
 * 
 * @param FilePath
 * @param resumeList
 * @return
 */
public static boolean createResumeExcel(String FilePath, List<Resume> resumeList) {
    // Excel Workbook,excel
    HSSFWorkbook wb = new HSSFWorkbook();
    // Excelsheet,exceltab
    HSSFSheet sheet = wb.createSheet("sheet1");
    // excel?
    sheet.setColumnWidth(0, 4000);
    sheet.setColumnWidth(1, 3500);

    // Excel?
    HSSFRow headRow = sheet.createRow(0);
    HSSFCell headell = headRow.createCell(0);
    // ???
    headell = headRow.createCell(0);
    headell.setCellValue("??");
    headell = headRow.createCell(1);
    headell.setCellValue("??");
    headell = headRow.createCell(2);
    headell.setCellValue("");
    headell = headRow.createCell(3);
    headell.setCellValue("");
    headell = headRow.createCell(4);
    headell.setCellValue("??");
    headell = headRow.createCell(5);
    headell.setCellValue("?");

    headell = headRow.createCell(6);
    headell.setCellValue("");
    headell = headRow.createCell(7);
    headell.setCellValue("?");
    headell = headRow.createCell(8);
    headell.setCellValue("??");
    headell = headRow.createCell(9);
    headell.setCellValue("?");
    headell = headRow.createCell(10);
    headell.setCellValue("??");

    headell = headRow.createCell(11);
    headell.setCellValue("?");
    headell = headRow.createCell(12);
    headell.setCellValue("?");
    headell = headRow.createCell(13);
    headell.setCellValue("?");
    headell = headRow.createCell(14);
    headell.setCellValue("QQ??");
    headell = headRow.createCell(15);
    headell.setCellValue("");

    headell = headRow.createCell(16);
    headell.setCellValue("??");
    headell = headRow.createCell(17);
    headell.setCellValue(" ");
    headell = headRow.createCell(18);
    headell.setCellValue("?");
    headell = headRow.createCell(19);
    headell.setCellValue("");
    headell = headRow.createCell(20);
    headell.setCellValue("?");

    headell = headRow.createCell(21);
    headell.setCellValue("?");
    headell = headRow.createCell(22);
    headell.setCellValue("");
    headell = headRow.createCell(23);
    headell.setCellValue(" cm");
    headell = headRow.createCell(24);
    headell.setCellValue("? kg");
    headell = headRow.createCell(25);
    headell.setCellValue("");

    headell = headRow.createCell(26);
    headell.setCellValue("");
    headell = headRow.createCell(27);
    headell.setCellValue("");
    headell = headRow.createCell(28);
    headell.setCellValue("?");
    headell = headRow.createCell(29);
    headell.setCellValue("?");
    headell = headRow.createCell(30);
    headell.setCellValue("? ?");

    headell = headRow.createCell(31);
    headell.setCellValue("");
    headell = headRow.createCell(32);
    headell.setCellValue("");
    headell = headRow.createCell(33);
    headell.setCellValue("?");
    headell = headRow.createCell(34);
    headell.setCellValue("?");
    headell = headRow.createCell(35);
    headell.setCellValue("/?");

    headell = headRow.createCell(36);
    headell.setCellValue("");
    headell = headRow.createCell(37);
    headell.setCellValue("");
    headell = headRow.createCell(38);
    headell.setCellValue("??");
    headell = headRow.createCell(39);
    headell.setCellValue("");
    headell = headRow.createCell(40);
    headell.setCellValue("");

    headell = headRow.createCell(41);
    headell.setCellValue("???");
    headell = headRow.createCell(42);
    headell.setCellValue("????");
    headell = headRow.createCell(43);
    headell.setCellValue("???");
    headell = headRow.createCell(44);
    headell.setCellValue("???");
    headell = headRow.createCell(45);
    headell.setCellValue("");

    headell = headRow.createCell(46);
    headell.setCellValue("???");
    headell = headRow.createCell(47);
    headell.setCellValue("??");
    headell = headRow.createCell(48);
    headell.setCellValue("??");
    headell = headRow.createCell(49);
    headell.setCellValue("");

    headell = headRow.createCell(50);
    headell.setCellValue("?");
    headell = headRow.createCell(51);
    headell.setCellValue("?");
    for (int i = 1; i <= resumeList.size(); i++) {
        Resume resume = resumeList.get(i - 1);
        // Excel?
        HSSFRow row = sheet.createRow(i);
        HSSFCell cell = row.createCell(0);
        // ???
        cell = row.createCell(0);
        cell.setCellValue(resume.getTitle());
        cell = row.createCell(1);
        cell.setCellValue(resume.getName());
        cell = row.createCell(2);
        cell.setCellValue(resume.getGender());
        cell = row.createCell(3);
        cell.setCellValue(resume.getBirth());
        cell = row.createCell(4);
        cell.setCellValue(resume.getIdentityCard());
        cell = row.createCell(5);
        cell.setCellValue(resume.getRace());

        cell = row.createCell(6);
        cell.setCellValue(resume.getMarriage());
        if (resume.getHukou() != null) {
            if (resume.getHukou().getCode() != null && !"".equals(resume.getHukou().getCode())) {
                cell = row.createCell(7);
                cell.setCellValue(resume.getHukou().getName());
            }
        }

        cell = row.createCell(8);
        cell.setCellValue(resume.getHukouAddress());
        cell = row.createCell(9);
        cell.setCellValue(resume.getHukouStatus());
        cell = row.createCell(10);
        cell.setCellValue(resume.getAddress());

        cell = row.createCell(11);
        cell.setCellValue(resume.getZipcode());
        cell = row.createCell(12);
        cell.setCellValue(resume.getPhone());
        cell = row.createCell(13);
        cell.setCellValue(resume.getEmail());
        cell = row.createCell(14);
        cell.setCellValue(resume.getQq());
        cell = row.createCell(15);
        cell.setCellValue(resume.getDisabilityCategory());

        cell = row.createCell(16);
        cell.setCellValue(resume.getDisabilityCard());
        cell = row.createCell(17);
        cell.setCellValue(resume.getDisabilityLevel());
        cell = row.createCell(18);
        cell.setCellValue(resume.getDisabilityPart());
        cell = row.createCell(19);
        cell.setCellValue(resume.getWorkAbility());
        cell = row.createCell(20);
        cell.setCellValue(resume.getHomeTown());

        cell = row.createCell(21);
        cell.setCellValue(resume.getPoliticalStatus());
        cell = row.createCell(22);
        cell.setCellValue(resume.getAge());
        cell = row.createCell(23);
        cell.setCellValue(resume.getHeight());
        cell = row.createCell(24);
        cell.setCellValue(resume.getWeight());
        cell = row.createCell(25);
        cell.setCellValue(resume.getProcessState());

        cell = row.createCell(26);
        cell.setCellValue(resume.getEducation());
        cell = row.createCell(27);
        cell.setCellValue(resume.getMajor());
        cell = row.createCell(28);
        cell.setCellValue(resume.getSchool());
        cell = row.createCell(29);
        cell.setCellValue(resume.getZhiCheng());
        cell = row.createCell(30);
        cell.setCellValue(resume.getShiYeHao());

        cell = row.createCell(31);
        cell.setCellValue(resume.getExperts());
        cell = row.createCell(32);
        cell.setCellValue(resume.getTraining());
        cell = row.createCell(33);
        cell.setCellValue(resume.getExperience());
        cell = row.createCell(34);
        cell.setCellValue(resume.getWorkExperience());
        cell = row.createCell(35);

        cell.setCellValue(resume.getSelfEvaluation());
        cell = row.createCell(36);
        cell.setCellValue(resume.getAttachment());
        cell = row.createCell(37);
        cell.setCellValue(resume.getJobNature());
        if (resume.getDesireJob() != null) {
            if (resume.getDesireJob().getCode() != null && !"".equals(resume.getDesireJob().getCode())) {
                cell = row.createCell(38);
                log.info(resume.getDesireJob().getName() + "********8");
                cell.setCellValue(resume.getDesireJob().getName());
            }
        }

        if (resume.getDesireAddress() != null) {
            if (resume.getDesireAddress().getCode() != null
                    && !"".equals(resume.getDesireAddress().getCode())) {
                cell = row.createCell(39);
                cell.setCellValue(resume.getDesireAddress().getName());
            }
        }

        cell = row.createCell(40);
        cell.setCellValue(resume.getDesireSalary());

        if (resume.isProvideFoodAndRoom() == true) {
            cell = row.createCell(41);
            cell.setCellValue("");
        } else if (resume.isProvideFoodAndRoom() == false) {
            cell = row.createCell(41);
            cell.setCellValue("?");
        }

        if (resume.isProvideRoom() == true) {
            cell = row.createCell(42);
            cell.setCellValue("");
        } else if (resume.isProvideRoom() == false) {
            cell = row.createCell(42);
            cell.setCellValue("?");
        }

        if (resume.isProvideFood() == true) {
            cell = row.createCell(43);
            cell.setCellValue("");
        } else if (resume.isProvideFood() == false) {
            cell = row.createCell(43);
            cell.setCellValue("?");
        }
        if (resume.isProvideInsurance() == true) {
            cell = row.createCell(44);
            cell.setCellValue("");
        } else if (resume.isProvideInsurance() == false) {
            cell = row.createCell(44);
            cell.setCellValue("?");
        }
        cell = row.createCell(45);
        cell.setCellValue(resume.getProvideOther());
        if (resume.isWorkShift() == true) {
            cell = row.createCell(46);
            cell.setCellValue("");
        } else if (resume.isWorkShift() == false) {
            cell = row.createCell(46);
            cell.setCellValue("?");
        }
        cell = row.createCell(47);
        cell.setCellValue(resume.getState());

        if (resume.getIsDefault() == true) {
            cell = row.createCell(48);
            cell.setCellValue("");
        } else if (resume.getIsDefault() == false) {
            cell = row.createCell(48);
            cell.setCellValue("?");
        }

        cell = row.createCell(49);
        cell.setCellValue(resume.getCheckStatus());

        if (resume.getViewCount() != null) {
            cell = row.createCell(50);
            cell.setCellValue(resume.getViewCount());
        }
        cell = row.createCell(51);
        cell.setCellValue(resume.getCareerTest());

    }
    try {
        FileOutputStream os = new FileOutputStream(FilePath);
        wb.write(os);
        os.flush();
        os.close();
        resumeList.clear();
        resumeList = null;
        os = null;
        wb = null;
        System.gc();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return true;
}