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

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

Introduction

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

Prototype

short ENCODING_UTF_16

To view the source code for org.apache.poi.hssf.usermodel HSSFCell ENCODING_UTF_16.

Click Source Link

Usage

From source file:org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.Cell.java

License:Apache License

/**
 * Constructor Cell./*from  ww w  .j a  va 2s. com*/
 * Only a hack as long as the POI stuff is not maintained in the POI CVS:
 * Setting the encoding to UTF-16 for internationalization
 * (<a href="http://jakarta.apache.org/poi/javadocs/org/apache/poi/hssf/usermodel/HSSFCell.html#getEncoding()">POI API</a>).
 *
 * @param cell
 */
Cell(final HSSFCell cell, final int cellType) {
    _cell = cell;
    _celltype = cellType;
    _cell.setEncoding(HSSFCell.ENCODING_UTF_16);
}

From source file:org.extremecomponents.table.view.XlsView.java

License:Apache License

private void setCellEncoding(HSSFCell cell) {
    if (encoding.equalsIgnoreCase("UTF")) {
        cell.setEncoding(HSSFCell.ENCODING_UTF_16);
    } else if (encoding.equalsIgnoreCase("UNICODE")) {
        cell.setEncoding(HSSFCell.ENCODING_COMPRESSED_UNICODE);
    }//from ww  w .  j  a v  a 2s  .co m
}

From source file:org.opensprout.osaf.util.ExcelUtils.java

License:Open Source License

public static HSSFCell addCell(HSSFRow row, int colIndex, String value) {
    if (value == null)
        value = "";
    HSSFCell c = row.createCell((short) colIndex);
    c.setEncoding(HSSFCell.ENCODING_UTF_16);
    c.setCellValue((String) value);
    return c;/*from   ww  w . j a va 2 s  .  c o m*/
}

From source file:org.opensprout.osaf.util.ExcelUtilsTest.java

License:Open Source License

@Test
public void addCellHSSFRowIntString() {
    HSSFRow row = mock(HSSFRow.class);
    HSSFCell cell = mock(HSSFCell.class);
    int colIndex = 1;
    String value = "name";

    stub(row.createCell((short) colIndex)).toReturn(cell);

    ExcelUtils.addCell(row, colIndex, value);
    verify(cell).setEncoding(HSSFCell.ENCODING_UTF_16);
    verify(cell).setCellValue((String) value);
}

From source file:org.opensprout.osaf.util.ExcelUtilsTest.java

License:Open Source License

@Test
public void addCellHSSFRowIntStringWithNull() {
    HSSFRow row = mock(HSSFRow.class);
    HSSFCell cell = mock(HSSFCell.class);
    int colIndex = 1;
    String value = null;//w  w w.j  ava  2s. c o  m

    stub(row.createCell((short) colIndex)).toReturn(cell);

    ExcelUtils.addCell(row, colIndex, value);
    verify(cell).setEncoding(HSSFCell.ENCODING_UTF_16);
    verify(cell).setCellValue("");
}

From source file:org.openXpertya.print.export.AbstractExcelExporter.java

License:Open Source License

/**
 * Export to given stream//from   www  .ja  v a  2  s.co m
 * @param out
 * @throws Exception
 */
private void export(OutputStream out) throws Exception {
    HSSFSheet sheet = createTableSheet();
    String sheetName = null;
    //
    short colnumMax = 0;
    for (int rownum = 0, xls_rownum = 1; rownum < getRowCount(); rownum++, xls_rownum++) {
        setCurrentRow(rownum);

        boolean isPageBreak = false;
        HSSFRow row = sheet.createRow(xls_rownum);
        //   for all columns
        short colnum = 0;
        for (int col = 0; col < getColumnCount(); col++) {
            if (colnum > colnumMax)
                colnumMax = colnum;
            //
            if (isColumnPrinted(col)) {
                HSSFCell cell = row.createCell(colnum);
                cell.setEncoding(HSSFCell.ENCODING_UTF_16); // Bug-2017673 - Export Report as Excel - Bad Encoding

                // line row
                Object obj = getValueAt(rownum, col);
                int displayType = getDisplayType(rownum, col);
                if (obj == null)
                    ;
                else if (DisplayType.isDate(displayType)) {
                    Timestamp value = (Timestamp) obj;
                    cell.setCellValue(value);
                } else if (DisplayType.isNumeric(displayType)) {
                    double value = 0;
                    if (obj instanceof Number) {
                        value = ((Number) obj).doubleValue();
                    }
                    cell.setCellValue(value);
                } else if (DisplayType.YesNo == displayType) {
                    boolean value = false;
                    if (obj instanceof Boolean)
                        value = (Boolean) obj;
                    else
                        value = "Y".equals(obj);
                    cell.setCellValue(
                            new HSSFRichTextString(Msg.getMsg(getLanguage(), value == true ? "Y" : "N")));
                } else {
                    String value = fixString(obj.toString()); //   formatted
                    cell.setCellValue(new HSSFRichTextString(value));
                }
                //
                HSSFCellStyle style = getStyle(rownum, col);
                cell.setCellStyle(style);
                // Page break
                if (isPageBreak(rownum, col)) {
                    isPageBreak = true;
                    sheetName = fixString(cell.getRichStringCellValue().getString());
                }
                //
                colnum++;
            } //   printed
        } //   for all columns
        //
        // Page Break
        if (isPageBreak) {
            closeTableSheet(sheet, sheetName, colnumMax);
            sheet = createTableSheet();
            xls_rownum = 0;
            isPageBreak = false;
        }
    } //   for all rows
    closeTableSheet(sheet, sheetName, colnumMax);
    //
    m_workbook.write(out);
    out.close();
    //
    // Workbook Info
    if (CLogMgt.isLevelFine()) {
        log.fine("Sheets #" + m_sheetCount);
        log.fine("Styles used #" + m_styles.size());
    }
}