Example usage for org.apache.poi.hssf.usermodel HSSFCellStyle getDataFormat

List of usage examples for org.apache.poi.hssf.usermodel HSSFCellStyle getDataFormat

Introduction

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

Prototype

@Override
public short getDataFormat() 

Source Link

Document

get the index of the format

Usage

From source file:org.bbreak.excella.core.test.util.TestUtil.java

License:Open Source License

private static String getCellStyleString(Workbook workbook, HSSFCellStyle cellStyle) {
    StringBuffer sb = new StringBuffer();
    if (cellStyle != null) {
        HSSFFont font = cellStyle.getFont(workbook);
        // sb.append("FontIndex=").append( cellStyle.getFontIndex()).append( ",");
        sb.append("Font=").append(getHSSFFontString((HSSFWorkbook) workbook, font)).append(",");

        sb.append("DataFormat=").append(cellStyle.getDataFormat()).append(",");
        sb.append("DataFormatString=").append(cellStyle.getDataFormatString()).append(",");
        sb.append("Hidden=").append(cellStyle.getHidden()).append(",");
        sb.append("Locked=").append(cellStyle.getLocked()).append(",");
        sb.append("Alignment=").append(cellStyle.getAlignmentEnum()).append(",");
        sb.append("WrapText=").append(cellStyle.getWrapText()).append(",");
        sb.append("VerticalAlignment=").append(cellStyle.getVerticalAlignmentEnum()).append(",");
        sb.append("Rotation=").append(cellStyle.getRotation()).append(",");
        sb.append("Indention=").append(cellStyle.getIndention()).append(",");
        sb.append("BorderLeft=").append(cellStyle.getBorderLeftEnum()).append(",");
        sb.append("BorderRight=").append(cellStyle.getBorderRightEnum()).append(",");
        sb.append("BorderTop=").append(cellStyle.getBorderTopEnum()).append(",");
        sb.append("BorderBottom=").append(cellStyle.getBorderBottomEnum()).append(",");

        sb.append("LeftBorderColor=")
                .append(getHSSFColorString((HSSFWorkbook) workbook, cellStyle.getLeftBorderColor()))
                .append(",");
        sb.append("RightBorderColor=")
                .append(getHSSFColorString((HSSFWorkbook) workbook, cellStyle.getRightBorderColor()))
                .append(",");
        sb.append("TopBorderColor=")
                .append(getHSSFColorString((HSSFWorkbook) workbook, cellStyle.getTopBorderColor())).append(",");
        sb.append("BottomBorderColor=")
                .append(getHSSFColorString((HSSFWorkbook) workbook, cellStyle.getBottomBorderColor()))
                .append(",");

        sb.append("FillPattern=").append(cellStyle.getFillPatternEnum()).append(",");
        sb.append("FillForegroundColor=")
                .append(getHSSFColorString((HSSFWorkbook) workbook, cellStyle.getFillForegroundColor()))
                .append(",");
        sb.append("FillBackgroundColor=")
                .append(getHSSFColorString((HSSFWorkbook) workbook, cellStyle.getFillBackgroundColor()));
    }//from w  ww. j av a 2s.c o m
    return sb.toString();
}

From source file:org.bbreak.excella.reports.ReportsTestUtil.java

License:Open Source License

/**
 * HSSF????/*from   www  .ja v a  2s. co m*/
 * 
 * @param workbook 
 * @param cellStyle 
 * @return ??
 */
private static String getCellStyleString(Workbook workbook, HSSFCellStyle cellStyle) {
    StringBuffer sb = new StringBuffer();
    if (cellStyle != null) {
        HSSFFont font = cellStyle.getFont(workbook);
        // sb.append("FontIndex=").append( cellStyle.getFontIndex()).append( ",");
        sb.append("Font=").append(getHSSFFontString((HSSFWorkbook) workbook, font)).append(",");

        sb.append("DataFormat=").append(cellStyle.getDataFormat()).append(",");
        sb.append("DataFormatString=").append(cellStyle.getDataFormatString()).append(",");
        sb.append("Hidden=").append(cellStyle.getHidden()).append(",");
        sb.append("Locked=").append(cellStyle.getLocked()).append(",");
        sb.append("Alignment=").append(cellStyle.getAlignmentEnum()).append(",");
        sb.append("WrapText=").append(cellStyle.getWrapText()).append(",");
        sb.append("VerticalAlignment=").append(cellStyle.getVerticalAlignmentEnum()).append(",");
        sb.append("Rotation=").append(cellStyle.getRotation()).append(",");
        sb.append("Indention=").append(cellStyle.getIndention()).append(",");
        sb.append("BorderLeft=").append(cellStyle.getBorderLeftEnum()).append(",");
        sb.append("BorderRight=").append(cellStyle.getBorderRightEnum()).append(",");
        sb.append("BorderTop=").append(cellStyle.getBorderTopEnum()).append(",");
        sb.append("BorderBottom=").append(cellStyle.getBorderBottomEnum()).append(",");

        sb.append("LeftBorderColor=")
                .append(getHSSFColorString((HSSFWorkbook) workbook, cellStyle.getLeftBorderColor()))
                .append(",");
        sb.append("RightBorderColor=")
                .append(getHSSFColorString((HSSFWorkbook) workbook, cellStyle.getRightBorderColor()))
                .append(",");
        sb.append("TopBorderColor=")
                .append(getHSSFColorString((HSSFWorkbook) workbook, cellStyle.getTopBorderColor())).append(",");
        sb.append("BottomBorderColor=")
                .append(getHSSFColorString((HSSFWorkbook) workbook, cellStyle.getBottomBorderColor()))
                .append(",");

        sb.append("FillPattern=").append(cellStyle.getFillPatternEnum()).append(",");
        sb.append("FillForegroundColor=")
                .append(getHSSFColorString((HSSFWorkbook) workbook, cellStyle.getFillForegroundColor()))
                .append(",");
        sb.append("FillBackgroundColor=")
                .append(getHSSFColorString((HSSFWorkbook) workbook, cellStyle.getFillBackgroundColor()));
    }
    return sb.toString();
}

From source file:org.exoplatform.services.document.impl.MSExcelDocumentReader.java

License:Open Source License

public static boolean isCellDateFormatted(HSSFCell cell) {
    boolean bDate = false;
    double d = cell.getNumericCellValue();
    if (HSSFDateUtil.isValidExcelDate(d)) {
        HSSFCellStyle style = cell.getCellStyle();
        int i = style.getDataFormat();
        switch (i) {
        case 0xe: // m/d/yy
        case 0xf: // d-mmm-yy
        case 0x10: // d-mmm
        case 0x11: // mmm-yy
        case 0x12: // h:mm AM/PM
        case 0x13: // h:mm:ss AM/PM
        case 0x14: // h:mm
        case 0x15: // h:mm:ss
        case 0x16: // m/d/yy h:mm
        case 0x2d: // mm:ss
        case 0x2e: // [h]:mm:ss
        case 0x2f: // mm:ss.0

        case 0xa5: // ??
        case 0xa7: // ??
        case 0xa9: // ??

        case 0xac: // mm:dd:yy not specified in javadoc
        case 0xad: // yyyy-mm-dd not specified in javadoc
        case 0xae: // mm:dd:yyyy not specified in javadoc
        case 0xaf: // m:d:yy not specified in javadoc
            bDate = true;/*www . ja  v  a2s  . c  o  m*/
            break;
        default:
            bDate = false;
            break;
        }
    }
    return bDate;
}

From source file:org.orbeon.oxf.util.XLSUtils.java

License:Open Source License

public static void copyCell(HSSFWorkbook workbook, HSSFCell destination, HSSFCell source) {

    // Copy cell content
    destination.setCellType(source.getCellType());
    switch (source.getCellType()) {
    case HSSFCell.CELL_TYPE_BOOLEAN:
        destination.setCellValue(source.getBooleanCellValue());
        break;//from  w w  w.  j a  v  a 2  s  .  co m
    case HSSFCell.CELL_TYPE_FORMULA:
    case HSSFCell.CELL_TYPE_STRING:
        destination.setCellValue(source.getStringCellValue());
        break;
    case HSSFCell.CELL_TYPE_NUMERIC:
        destination.setCellValue(source.getNumericCellValue());
        break;
    }

    // Copy cell style
    HSSFCellStyle sourceCellStyle = source.getCellStyle();
    HSSFCellStyle destinationCellStyle = workbook.createCellStyle();
    destinationCellStyle.setAlignment(sourceCellStyle.getAlignment());
    destinationCellStyle.setBorderBottom(sourceCellStyle.getBorderBottom());
    destinationCellStyle.setBorderLeft(sourceCellStyle.getBorderLeft());
    destinationCellStyle.setBorderRight(sourceCellStyle.getBorderRight());
    destinationCellStyle.setBorderTop(sourceCellStyle.getBorderTop());
    destinationCellStyle.setBottomBorderColor(sourceCellStyle.getBottomBorderColor());
    destinationCellStyle.setDataFormat(sourceCellStyle.getDataFormat());
    destinationCellStyle.setFillBackgroundColor(sourceCellStyle.getFillForegroundColor());
    destinationCellStyle.setFillForegroundColor(sourceCellStyle.getFillForegroundColor());
    destinationCellStyle.setFillPattern(sourceCellStyle.getFillPattern());
    destinationCellStyle.setFont(workbook.getFontAt(sourceCellStyle.getFontIndex()));
    destinationCellStyle.setHidden(sourceCellStyle.getHidden());
    destinationCellStyle.setIndention(sourceCellStyle.getIndention());
    destinationCellStyle.setLeftBorderColor(sourceCellStyle.getLeftBorderColor());
    destinationCellStyle.setLocked(sourceCellStyle.getLocked());
    destinationCellStyle.setRightBorderColor(sourceCellStyle.getRightBorderColor());
    destinationCellStyle.setRotation(sourceCellStyle.getRotation());
    destinationCellStyle.setTopBorderColor(sourceCellStyle.getTopBorderColor());
    destinationCellStyle.setVerticalAlignment(sourceCellStyle.getVerticalAlignment());
    destinationCellStyle.setWrapText(sourceCellStyle.getWrapText());
    destination.setCellStyle(destinationCellStyle);
}

From source file:org.seasar.dbflute.helper.io.xls.DfTableXlsReader.java

License:Apache License

protected boolean isCellBase64Formatted(HSSFCell cell) {
    final HSSFCellStyle cs = cell.getCellStyle();
    final short dfNum = cs.getDataFormat();
    return DfDataSetConstants.BASE64_FORMAT.equals(_dataFormat.getFormat(dfNum));
}

From source file:org.seasar.dbflute.helper.io.xls.DfTableXlsReader.java

License:Apache License

protected boolean isCellDateFormatted(HSSFCell cell) {
    final HSSFCellStyle cs = cell.getCellStyle();
    final short dfNum = cs.getDataFormat();
    final String format = _dataFormat.getFormat(dfNum);
    if (format == null || format.length() == 0) {
        return false;
    }//from w  ww .j ava 2 s. co m
    if (format.indexOf('/') > 0 || format.indexOf('y') > 0 || format.indexOf('m') > 0
            || format.indexOf('d') > 0) {
        return true;
    }
    return false;
}

From source file:org.seasar.dbflute.helper.io.xls.DfXlsReader.java

License:Apache License

protected boolean isCellBase64Formatted(HSSFCell cell) {
    HSSFCellStyle cs = cell.getCellStyle();
    short dfNum = cs.getDataFormat();
    return DfDataSetConstants.BASE64_FORMAT.equals(_dataFormat.getFormat(dfNum));
}

From source file:org.seasar.dbflute.helper.io.xls.DfXlsReader.java

License:Apache License

protected boolean isCellDateFormatted(HSSFCell cell) {
    HSSFCellStyle cs = cell.getCellStyle();
    short dfNum = cs.getDataFormat();
    String format = _dataFormat.getFormat(dfNum);
    if (format == null || format.length() == 0) {
        return false;
    }//from w ww  . j  ava 2  s  . com
    if (format.indexOf('/') > 0 || format.indexOf('y') > 0 || format.indexOf('m') > 0
            || format.indexOf('d') > 0) {
        return true;
    }
    return false;
}

From source file:org.seasar.extension.dataset.impl.XlsReader.java

License:Apache License

/**
 * ?Base64???????????//from w w w. j av  a 2 s.c  om
 * 
 * @param cell
 *            
 * @return ?Base64????????
 */
public boolean isCellBase64Formatted(HSSFCell cell) {
    HSSFCellStyle cs = cell.getCellStyle();
    short dfNum = cs.getDataFormat();
    return BASE64_FORMAT.equals(dataFormat.getFormat(dfNum));
}

From source file:org.seasar.extension.dataset.impl.XlsReader.java

License:Apache License

/**
 * ?????????//from   w w  w.  jav a 2s  .c  om
 * 
 * @param cell
 *            
 * @return ??????
 */
public boolean isCellDateFormatted(HSSFCell cell) {
    HSSFCellStyle cs = cell.getCellStyle();
    short dfNum = cs.getDataFormat();
    String format = dataFormat.getFormat(dfNum);
    if (StringUtil.isEmpty(format)) {
        return false;
    }
    if (format.indexOf('/') > 0 || format.indexOf('y') > 0 || format.indexOf('m') > 0
            || format.indexOf('d') > 0) {
        return true;
    }
    return false;
}