本文整理了Java中org.apache.poi.ss.usermodel.CellStyle.getDataFormatString()
方法的一些代码示例,展示了CellStyle.getDataFormatString()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。CellStyle.getDataFormatString()
方法的具体详情如下:
包路径:org.apache.poi.ss.usermodel.CellStyle
类名称:CellStyle
方法名:getDataFormatString
[英]Get the format string
[中]获取格式字符串
代码示例来源: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-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: 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: 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: 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
private ValueAndFormat getCellValue(Cell cell) {
if (cell != null) {
final String format = cell.getCellStyle().getDataFormatString();
CellType type = cell.getCellType();
if (type == CellType.FORMULA) {
type = cell.getCachedFormulaResultType();
}
switch (type) {
case NUMERIC:
return new ValueAndFormat(Double.valueOf(cell.getNumericCellValue()), format, decimalTextFormat);
case STRING:
case BOOLEAN:
return new ValueAndFormat(cell.getStringCellValue(), format);
default:
break;
}
}
return new ValueAndFormat("", "");
}
/**
代码示例来源:origin: openl-tablets/openl-tablets
@Override
public String getFormatString() {
return xlsStyle.getDataFormatString();
}
代码示例来源: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: 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: 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: org.openl.rules/org.openl.lib.poi.dev
private void handleNonStringCell(StringBuffer text, Cell cell, DataFormatter formatter) {
int type = cell.getCellType();
if (type == Cell.CELL_TYPE_FORMULA) {
type = cell.getCachedFormulaResultType();
}
if (type == Cell.CELL_TYPE_NUMERIC) {
CellStyle cs = cell.getCellStyle();
if (cs.getDataFormatString() != null) {
text.append(formatter.formatRawCellContents(
cell.getNumericCellValue(), cs.getDataFormat(), cs.getDataFormatString()
));
return;
}
}
// No supported styling applies to this cell
XSSFCell xcell = (XSSFCell)cell;
text.append( xcell.getRawValue() );
}
代码示例来源: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: hs-web/hsweb-expands
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: 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.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);
}
代码示例来源:origin: org.openl.rules/org.openl.lib.poi.dev
/**
* Check if a cell contains a date
* Since dates are stored internally in Excel as double values
* we infer it is a date if it is formatted as such.
* @see #isADateFormat(int, String)
* @see #isInternalDateFormat(int)
*/
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();
String f = style.getDataFormatString();
bDate = isADateFormat(i, f);
}
return bDate;
}
/**
代码示例来源:origin: com.haulmont.thirdparty/poi
/**
* Check if a cell contains a date
* Since dates are stored internally in Excel as double values
* we infer it is a date if it is formatted as such.
* @see #isADateFormat(int, String)
* @see #isInternalDateFormat(int)
*/
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();
String f = style.getDataFormatString();
bDate = isADateFormat(i, f);
}
return bDate;
}
/**
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.poi
private ValueAndFormat getCellValue(Cell cell) {
if (cell != null) {
final String format = cell.getCellStyle().getDataFormatString();
CellType type = cell.getCellType();
if (type == CellType.FORMULA) {
type = cell.getCachedFormulaResultType();
}
switch (type) {
case NUMERIC:
return new ValueAndFormat(Double.valueOf(cell.getNumericCellValue()), format, decimalTextFormat);
case STRING:
case BOOLEAN:
return new ValueAndFormat(cell.getStringCellValue(), format);
default:
break;
}
}
return new ValueAndFormat("", "");
}
/**
内容来源于网络,如有侵权,请联系作者删除!