本文整理汇总了Java中org.apache.poi.ss.usermodel.DateUtil.isADateFormat方法的典型用法代码示例。如果您正苦于以下问题:Java DateUtil.isADateFormat方法的具体用法?Java DateUtil.isADateFormat怎么用?Java DateUtil.isADateFormat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.poi.ss.usermodel.DateUtil
的用法示例。
在下文中一共展示了DateUtil.isADateFormat方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: formatRawCellContents
import org.apache.poi.ss.usermodel.DateUtil; //导入方法依赖的package包/类
/**
* 判断是否是日期,若是返回日期字符串,否则返回数字字符串
*
* @param value
* @param formatIndex
* @param formatString
* @return
*/
private String formatRawCellContents(double value, int formatIndex, String formatString) {
// Is it a date?
if (DateUtil.isADateFormat(formatIndex, formatString)) {
if (DateUtil.isValidExcelDate(value)) {
Date d = DateUtil.getJavaDate(value);
SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
return f.format(d);
}
}
String _value = NumberToTextConverter.toText(value);
if (_value.indexOf('E') > -1) {
//若是科学计数法,则转换为非科学计数法
return new BigDecimal(value).toString();
}
return _value;
}
示例2: determineOutputTypes
import org.apache.poi.ss.usermodel.DateUtil; //导入方法依赖的package包/类
/**
* Helper method to determine the output types based on the explicit type given as attribute in "cell" element
* and the type through "style" definition.
* @param type Value of attribute type {@link ExcelUtil#TYPE} on cell.
* @param style Value of attribute style {@link ExcelUtil#STYLE} on cell.
*/
private void determineOutputTypes(String type, String style) {
// Determine the type from attribute
valueTypeFromAttribute = MinorType.FLOAT8;
if (type != null) {
if (TYPE_MAP.containsKey(type)) {
valueTypeFromAttribute = TYPE_MAP.get(type);
}
}
valueTypeFromStyle = MinorType.FLOAT8;
if (style != null) {
if (styleToTypeCache.containsKey(style)) {
valueTypeFromStyle = styleToTypeCache.get(style);
return;
}
int styleId = Integer.valueOf(style);
CTXf styleDef = styles.getCellXfAt(styleId);
if (styleDef != null) {
long numFmtId = styleDef.getNumFmtId();
String format = styles.getNumberFormatAt((short) numFmtId);
if (DateUtil.isADateFormat((int) numFmtId, format)) {
valueTypeFromStyle = MinorType.TIMESTAMP;
}
}
}
styleToTypeCache.put(style, valueTypeFromStyle);
}
示例3: startElement
import org.apache.poi.ss.usermodel.DateUtil; //导入方法依赖的package包/类
@Override
public void startElement( String uri, String localName, String name,
Attributes attributes ) throws SAXException {
if ( null != name ) {
switch ( name ) {
case "row":
rownum = Integer.parseInt( attributes.getValue( "r" ) ) - 1;
currentrowdata.clear();
break;
case "c": // c is a new cell
String celltypestr = attributes.getValue( "t" );
celltype = ( formats.containsKey( celltypestr )
? formats.get( celltypestr ) : Cell.CELL_TYPE_BLANK );
// dates don't always have a type attribute
if ( Cell.CELL_TYPE_NUMERIC == celltype || null == celltypestr ) {
celltype = Cell.CELL_TYPE_NUMERIC;
// check if it's a date
String styleidstr = attributes.getValue( "s" );
int styleid = ( null == styleidstr ? 0
: Integer.parseInt( styleidstr ) );
XSSFCellStyle style = styles.getStyleAt( styleid );
int formatIndex = style.getDataFormat();
String formatString = style.getDataFormatString();
isdate = DateUtil.isADateFormat( formatIndex, formatString );
}
String colname = attributes.getValue( "r" );
colnum = getColNum( colname.substring( 0,
colname.lastIndexOf( Integer.toString( rownum + 1 ) ) ) );
break;
case "v": // new value for a cell
setReading( true );
resetContents();
break;
}
}
}
示例4: isCellDateFormatted
import org.apache.poi.ss.usermodel.DateUtil; //导入方法依赖的package包/类
/**
* DateUtilがLocalizeされたフォーマット(年,月,日等を含むフォーマット)に対応していないため、
* フォーマットの""で囲まれた文字列を除去するようにして対応。
* DateUtilが対応されたらそっちを使用する。
* Bug 47071として報告済み
*
* @param cell 対象セル
*/
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 fs = style.getDataFormatString();
if ( fs != null) {
// And '"any"' into ''
while ( fs.contains( "\"")) {
int beginIdx = fs.indexOf( "\"");
if ( beginIdx == -1) {
break;
}
int endIdx = fs.indexOf( "\"", beginIdx + 1);
if ( endIdx == -1) {
break;
}
fs = fs.replaceFirst( Pattern.quote( fs.substring( beginIdx, endIdx + 1)), "");
}
}
bDate = DateUtil.isADateFormat( i, fs);
}
return bDate;
}
示例5: formatRawCellContents
import org.apache.poi.ss.usermodel.DateUtil; //导入方法依赖的package包/类
@Override
public String formatRawCellContents(double value, int formatIndex, String formatString)
{
if (DateUtil.isADateFormat(formatIndex, formatString))
{
return super.formatRawCellContents(value, formatIndex, DATE_TIME_FORMAT);
}
else
{
return new Double(value).toString();
// return super.formatRawCellContents(value, formatIndex, formatString);
}
}
示例6: isDateCell
import org.apache.poi.ss.usermodel.DateUtil; //导入方法依赖的package包/类
private boolean isDateCell( String cellStyle ) {
if ( cellStyle != null ) {
int styleIdx = Integer.parseInt( cellStyle );
CTXf cellXf = styles.getCellXfAt( styleIdx );
if ( cellXf != null ) {
// need id for builtin types, format if custom
int formatId = (int) cellXf.getNumFmtId();
String format = styles.getNumberFormatAt( formatId );
return DateUtil.isADateFormat( formatId, format );
}
}
return false;
}
示例7: checkForDateFormat
import org.apache.poi.ss.usermodel.DateUtil; //导入方法依赖的package包/类
private boolean checkForDateFormat(int numberFormatId, String formatCode) {
return DateUtil.isADateFormat(numberFormatId, formatCode);
}
示例8: isMatchingCellType
import org.apache.poi.ss.usermodel.DateUtil; //导入方法依赖的package包/类
@Override
public boolean isMatchingCellType(StreamingCell cell) {
return DateUtil.isADateFormat(cell.getNumericFormatIndex(), cell.getNumericFormat());
}
示例9: isDateFormat
import org.apache.poi.ss.usermodel.DateUtil; //导入方法依赖的package包/类
boolean isDateFormat(CellValueRecordInterface cell) {
final int formatIndex = getFormatIndex(cell);
return DateUtil.isADateFormat(formatIndex, getFormatString(formatIndex));
}
示例10: isDateFormat
import org.apache.poi.ss.usermodel.DateUtil; //导入方法依赖的package包/类
boolean isDateFormat(PoiCellStyle cellStyle) {
org.apache.poi.ss.usermodel.CellStyle style = cellStyle.poiCellStyle;
int i = style.getDataFormat();
String f = style.getDataFormatString();
return DateUtil.isADateFormat(i, f);
}
示例11: isCellDateFormatted
import org.apache.poi.ss.usermodel.DateUtil; //导入方法依赖的package包/类
private boolean isCellDateFormatted( Cell cell ) {
if (cell == null) return false;
if ( ! DateUtil.isValidExcelDate(cell.getNumericCellValue()) ) return false;
CellStyle style = cell.getCellStyle();
if( style == null ) return false;
int formatIndex = style.getDataFormat();
String format = style.getDataFormatString();
// Apache poi's missing logic
format = format.replaceAll( "([^\\\\])\".*?[^\\\\]\"", "$1" );
return DateUtil.isADateFormat( formatIndex, format) ;
}