org.apache.poi.ss.usermodel.CellStyle.getDataFormat()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(8.8k)|赞(0)|评价(0)|浏览(544)

本文整理了Java中org.apache.poi.ss.usermodel.CellStyle.getDataFormat()方法的一些代码示例,展示了CellStyle.getDataFormat()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。CellStyle.getDataFormat()方法的具体详情如下:
包路径:org.apache.poi.ss.usermodel.CellStyle
类名称:CellStyle
方法名:getDataFormat

CellStyle.getDataFormat介绍

[英]get the index of the format
[中]获取格式的索引

代码示例

代码示例来源:origin: org.apache.poi/poi

/**
 * @param style
 * @return null if the style is null, instance from style data format values otherwise
 */
public static ExcelNumberFormat from(CellStyle style) {
  if (style == null) return null;
  return new ExcelNumberFormat(style.getDataFormat(), style.getDataFormatString());
}

代码示例来源:origin: org.apache.poi/poi

/**
 *  Check if a cell contains a date, checking only for internal
 *   excel date formats.
 *  As Excel stores a great many of its dates in "non-internal"
 *   date formats, you will not normally want to use this method.
 *  @see #isADateFormat(int,String)
 *  @see #isInternalDateFormat(int)
 */
public static boolean isCellInternalDateFormatted(Cell cell) {
  if (cell == null) return false;
  boolean bDate = false;
  double d = cell.getNumericCellValue();
  if ( DateUtil.isValidExcelDate(d) ) {
    CellStyle style = cell.getCellStyle();
    int i = style.getDataFormat();
    bDate = isInternalDateFormat(i);
  }
  return bDate;
}

代码示例来源:origin: org.apache.poi/poi

/**
 * Create and return a Format based on the format string from a  cell's
 * style. If the pattern cannot be parsed, return a default pattern.
 *
 * @param cell The Excel cell
 * @return A Format representing the excel format. May return null.
 */
public Format createFormat(Cell cell) {
  int formatIndex = cell.getCellStyle().getDataFormat();
  String formatStr = cell.getCellStyle().getDataFormatString();
  return createFormat(cell.getNumericCellValue(), formatIndex, formatStr);
}

代码示例来源:origin: pentaho/pentaho-kettle

assertEquals( format.getFormat( cellStyle.getDataFormat() ), "0.00000" );
} else {
 assertEquals( format.getFormat( cellStyle.getDataFormat() ), "##0,000.0" );

代码示例来源:origin: looly/hutool

/**
 * 获取数字类型的单元格值
 * 
 * @param cell 单元格
 * @return 单元格值,可能为Long、Double、Date
 */
private static Object getNumericValue(Cell cell) {
  final double value = cell.getNumericCellValue();
  final CellStyle style = cell.getCellStyle();
  if (null == style) {
    return value;
  }
  final short formatIndex = style.getDataFormat();
  // 判断是否为日期
  if (isDateType(cell, formatIndex)) {
    return DateUtil.date(cell.getDateCellValue());// 使用Hutool的DateTime包装
  }
  final String format = style.getDataFormatString();
  // 普通数字
  if (null != format && format.indexOf(StrUtil.C_DOT) < 0) {
    final long longPart = (long) value;
    if (longPart == value) {
      // 对于无小数部分的数字类型,转为Long
      return longPart;
    }
  }
  return value;
}

代码示例来源:origin: org.apache.poi/poi

put(properties, BORDER_TOP, style.getBorderTop());
put(properties, BOTTOM_BORDER_COLOR, style.getBottomBorderColor());
put(properties, DATA_FORMAT, style.getDataFormat());
put(properties, FILL_PATTERN, style.getFillPattern());
put(properties, FILL_FOREGROUND_COLOR, style.getFillForegroundColor());

代码示例来源:origin: looly/hutool

/**
 * 获取数字类型的单元格值
 * 
 * @param cell 单元格
 * @return 单元格值,可能为Long、Double、Date
 */
private static Object getNumericValue(Cell cell) {
  final double value = cell.getNumericCellValue();
  final CellStyle style = cell.getCellStyle();
  if (null == style) {
    return value;
  }
  final short formatIndex = style.getDataFormat();
  // 判断是否为日期
  if (isDateType(cell, formatIndex)) {
    return DateUtil.date(cell.getDateCellValue());// 使用Hutool的DateTime包装
  }
  final String format = style.getDataFormatString();
  // 普通数字
  if (null != format && format.indexOf(StrUtil.C_DOT) < 0) {
    final long longPart = (long) value;
    if (longPart == value) {
      // 对于无小数部分的数字类型,转为Long
      return longPart;
    }
  }
  return value;
}

代码示例来源:origin: openl-tablets/openl-tablets

@Override
public short getFormatIndex() {
  return xlsStyle.getDataFormat();
}

代码示例来源:origin: org.apache.poi/poi-ooxml

private void handleNonStringCell(StringBuilder text, Cell cell, DataFormatter formatter) {
  CellType type = cell.getCellType();
  if (type == CellType.FORMULA) {
    type = cell.getCachedFormulaResultType();
  }
  if (type == CellType.NUMERIC) {
    CellStyle cs = cell.getCellStyle();
    if (cs != null && cs.getDataFormatString() != null) {
      String contents = formatter.formatRawCellContents(
          cell.getNumericCellValue(), cs.getDataFormat(), cs.getDataFormatString());
      checkMaxTextSize(text, contents);
      text.append(contents);
      return;
    }
  }
  // No supported styling applies to this cell
  String contents = ((XSSFCell)cell).getRawValue();
  if (contents != null) {
    checkMaxTextSize(text, contents);
    text.append(contents);
  }
}

代码示例来源:origin: com.github.mygreen/excel-cellformatter

@Override
public short getFormatIndex() {
  final short formatIndex = getCell().getCellStyle().getDataFormat();
  return formatIndex;
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.poi

/**
 * @param style
 * @return null if the style is null, instance from style data format values otherwise
 */
public static ExcelNumberFormat from(CellStyle style) {
  if (style == null) return null;
  return new ExcelNumberFormat(style.getDataFormat(), style.getDataFormatString());
}

代码示例来源:origin: hellojavaer/poi-excel-utils

public static void writeCell(Cell cell, Object val) {
  if (cell.getCellStyle() != null && cell.getCellStyle().getDataFormat() > 0) {
    writeCell(cell, val, true, null, null);
  } else {
    writeCell(cell, val, false, null, null);
  }
}

代码示例来源:origin: stackoverflow.com

private boolean myIsADateFormat(Cell cell){
  CellStyle style = cell.getCellStyle();
  if(style == null) return false;
  int formatNo = style.getDataFormat();
  String formatString = style.getDataFormatString();
  boolean result = DateUtil.isADateFormat(formatNo, formatString);
  return result;
}

代码示例来源:origin: openl-tablets/openl-tablets

private boolean equalsStyle(CellStyle cs1, CellStyle cs2) {
  return (cs1.getAlignment() == cs2.getAlignment() && cs1.getHidden() == cs2.getHidden() && cs1.getLocked() == cs2.getLocked() && cs1.getWrapText() == cs2.getWrapText() && cs1.getBorderBottom() == cs2.getBorderBottom() && cs1.getBorderLeft() == cs2.getBorderLeft() && cs1.getBorderRight() == cs2.getBorderRight() && cs1.getBorderTop() == cs2.getBorderTop() && cs1.getBottomBorderColor() == cs2.getBottomBorderColor() && cs1.getFillBackgroundColor() == cs2.getFillBackgroundColor() && cs1.getFillForegroundColor() == cs2.getFillForegroundColor() && cs1.getFillPattern() == cs2.getFillPattern() && cs1.getIndention() == cs2.getIndention() && cs1.getLeftBorderColor() == cs2.getLeftBorderColor() && cs1.getRightBorderColor() == cs2.getRightBorderColor() && cs1.getRotation() == cs2.getRotation() && cs1.getTopBorderColor() == cs2.getTopBorderColor() && cs1.getVerticalAlignment() == cs2.getVerticalAlignment()) && cs1.getDataFormat() == cs2.getDataFormat();
}

代码示例来源:origin: xiaour/SpringBootDemo

/**
 * 根据表格样式判断是否为日期格式
 * @param cellStyle
 * @return
 */
public static boolean isCellDateFormatted(CellStyle cellStyle){
  if(cellStyle==null){
    return false;
  }
  int i = cellStyle.getDataFormat();
  String f = cellStyle.getDataFormatString();
     return org.apache.poi.ss.usermodel.DateUtil.isADateFormat(i, f);
}
/**

代码示例来源:origin: stackoverflow.com

final DataFormatter dataFormatter = new DataFormatter();

final CellStyle cellStyle = cell.getCellStyle();
final String formtatedValue = dataFormatter.formatRawCellContents(cell.getNumericCellValue(), cellStyle.getDataFormat(), cellStyle.getDataFormatString());
System.out.println(formattedValue);

代码示例来源:origin: com.haulmont.thirdparty/poi

/**
 * Create and return a Format based on the format string from a  cell's
 * style. If the pattern cannot be parsed, return a default pattern.
 *
 * @param cell The Excel cell
 * @return A Format representing the excel format. May return null.
 */
public Format createFormat(Cell cell) {
  int formatIndex = cell.getCellStyle().getDataFormat();
  String formatStr = cell.getCellStyle().getDataFormatString();
  return createFormat(cell.getNumericCellValue(), formatIndex, formatStr);
}

代码示例来源:origin: org.openl.rules/org.openl.lib.poi.dev

/**
 * Create and return a Format based on the format string from a  cell's
 * style. If the pattern cannot be parsed, return a default pattern.
 *
 * @param cell The Excel cell
 * @return A Format representing the excel format. May return null.
 */
public Format createFormat(Cell cell) {
  int formatIndex = cell.getCellStyle().getDataFormat();
  String formatStr = cell.getCellStyle().getDataFormatString();
  return createFormat(cell.getNumericCellValue(), formatIndex, formatStr);
}

代码示例来源:origin: org.hswebframework/hsweb-expands-office

public static boolean isCellDateFormatted(Cell cell) {
  if (cell == null) return false;
  boolean bDate = false;
  double d = cell.getNumericCellValue();
  if (DateUtil.isValidExcelDate(d)) {
    CellStyle style = cell.getCellStyle();
    if (style == null) return false;
    int i = style.getDataFormat();
    if (i == 58 || i == 31) return true;
    String f = style.getDataFormatString();
    f = f.replaceAll("[\"|\']", "").replaceAll("[年|月|日|时|分|秒|毫秒|微秒]", "");
    bDate = isADateFormat(i, f);
  }
  return bDate;
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.poi

/**
 * Create and return a Format based on the format string from a  cell's
 * style. If the pattern cannot be parsed, return a default pattern.
 *
 * @param cell The Excel cell
 * @return A Format representing the excel format. May return null.
 */
public Format createFormat(Cell cell) {
  int formatIndex = cell.getCellStyle().getDataFormat();
  String formatStr = cell.getCellStyle().getDataFormatString();
  return createFormat(cell.getNumericCellValue(), formatIndex, formatStr);
}

相关文章

微信公众号

最新文章

更多