当前位置: 首页>>代码示例>>Java>>正文


Java XSSFCellStyle.getDataFormatString方法代码示例

本文整理汇总了Java中org.apache.poi.xssf.usermodel.XSSFCellStyle.getDataFormatString方法的典型用法代码示例。如果您正苦于以下问题:Java XSSFCellStyle.getDataFormatString方法的具体用法?Java XSSFCellStyle.getDataFormatString怎么用?Java XSSFCellStyle.getDataFormatString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.poi.xssf.usermodel.XSSFCellStyle的用法示例。


在下文中一共展示了XSSFCellStyle.getDataFormatString方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handleNumber

import org.apache.poi.xssf.usermodel.XSSFCellStyle; //导入方法依赖的package包/类
@Override
public void handleNumber(XSSFCellStyle style, String number) {
    rawValues.add(number);
    if (style != null) {
        short formatIndex = style.getDataFormat();
        String formatString = style.getDataFormatString();
        if (formatString == null) {
            formatString = BuiltinFormats.getBuiltinFormat(formatIndex);
        }
        if (formatString != null) {
            formattedValues.add(formatter.formatRawCellContents(Double.parseDouble(number), formatIndex, formatString));
            if (formatString.contentEquals("D/M/YYYY")) {
                rawValues.add(formatter.formatRawCellContents(Double.parseDouble(number), formatIndex, formatString));
            }
        }
    }else{
       formattedValues.add(number);
    }
}
 
开发者ID:iMDT,项目名称:xlsx-io,代码行数:20,代码来源:DefaultDataHandlerImpl.java

示例2: setFormatString

import org.apache.poi.xssf.usermodel.XSSFCellStyle; //导入方法依赖的package包/类
/**
 * Read the numeric format string out of the styles table for this cell. Stores the result in the Cell.
 *
 * @param startElement
 * @param cell
 */
void setFormatString(StartElement startElement, StreamingCell cell) {
    Attribute cellStyle = startElement.getAttributeByName(new QName("s"));
    String cellStyleString = (cellStyle != null) ? cellStyle.getValue() : null;
    XSSFCellStyle style = null;

    if (cellStyleString != null) {
        style = stylesTable.getStyleAt(Integer.parseInt(cellStyleString));
    } else if (stylesTable.getNumCellStyles() > 0) {
        style = stylesTable.getStyleAt(0);
    }

    if (style != null) {
        cell.setNumericFormatIndex(style.getDataFormat());
        String formatString = style.getDataFormatString();

        if (formatString != null) {
            cell.setNumericFormat(formatString);
        } else {
            cell.setNumericFormat(BuiltinFormats.getBuiltinFormat(cell.getNumericFormatIndex()));
        }
    } else {
        cell.setNumericFormatIndex(null);
        cell.setNumericFormat(null);
    }
}
 
开发者ID:Talend,项目名称:data-prep,代码行数:32,代码来源:StreamingSheetReader.java

示例3: setFormatString

import org.apache.poi.xssf.usermodel.XSSFCellStyle; //导入方法依赖的package包/类
/**
 * Read the numeric format string out of the styles table for this cell. Stores
 * the result in the Cell.
 *
 * @param startElement
 * @param cell
 */
void setFormatString(StartElement startElement, StreamingCell cell) {
  Attribute cellStyle = startElement.getAttributeByName(new QName("s"));
  String cellStyleString = (cellStyle != null) ? cellStyle.getValue() : null;
  XSSFCellStyle style = null;

  if(cellStyleString != null) {
    style = stylesTable.getStyleAt(Integer.parseInt(cellStyleString));
  } else if(stylesTable.getNumCellStyles() > 0) {
    style = stylesTable.getStyleAt(0);
  }

  if(style != null) {
    cell.setNumericFormatIndex(style.getDataFormat());
    String formatString = style.getDataFormatString();

    if(formatString != null) {
      cell.setNumericFormat(formatString);
    } else {
      cell.setNumericFormat(BuiltinFormats.getBuiltinFormat(cell.getNumericFormatIndex()));
    }
  } else {
    cell.setNumericFormatIndex(null);
    cell.setNumericFormat(null);
  }
}
 
开发者ID:monitorjbl,项目名称:excel-streaming-reader,代码行数:33,代码来源:StreamingSheetReader.java

示例4: setNextDataType

import org.apache.poi.xssf.usermodel.XSSFCellStyle; //导入方法依赖的package包/类
/**
 * 处理数据类型
 *
 * @param attributes attributes
 */
public void setNextDataType(Attributes attributes) {
	mNextDataType = CellValueType.STRING;
	mFormatIndex = -1;
	mFormatString = null;
	String cellType = attributes.getValue("t");
	String cellStyleStr = attributes.getValue("s");

	if ("b".equals(cellType)) {
		mNextDataType = CellValueType.BOOL;
	} else if ("e".equals(cellType)) {
		mNextDataType = CellValueType.ERROR;
	} else if ("inlineStr".equals(cellType)) {
		mNextDataType = CellValueType.INLINESTR;
	} else if ("s".equals(cellType)) {
		mNextDataType = CellValueType.STRING;
	} else if ("str".equals(cellType)) {
		mNextDataType = CellValueType.FORMULA;
	}
	//TODO: 日期类型的判断

	if (cellStyleStr != null) {
		int styleIndex = Integer.parseInt(cellStyleStr);
		XSSFCellStyle style = mStylesTable.getStyleAt(styleIndex);
		mFormatIndex = style.getDataFormat();
		mFormatString = style.getDataFormatString();

		if (mFormatString == null) {
			mNextDataType = CellValueType.NULL;
			mFormatString = BuiltinFormats.getBuiltinFormat(mFormatIndex);
		}
	}
}
 
开发者ID:wuwz,项目名称:ExcelKit,代码行数:38,代码来源:XlsxReader.java

示例5: startElement

import org.apache.poi.xssf.usermodel.XSSFCellStyle; //导入方法依赖的package包/类
public void startElement(String uri, String localName, String name, Attributes attributes) throws SAXException {
	if (name.equals("c")) {
		String r = attributes.getValue("r");
		int firstDigit = -1;
		for (int c = 0; c < r.length(); ++c) {
			if (Character.isDigit(r.charAt(c))) {
				firstDigit = c;
				break;
			}
		}
		curColumn = nameToColumn(r.substring(0, firstDigit));
		columns.put(curColumn, null);

		String cellType = attributes.getValue("t");
		this.nextDataType = XssfDataType.NUMBER;
		this.formatIndex = -1;
		this.formatString = null;
		String cellStyleStr = attributes.getValue("s");
		if ("b".equals(cellType))
			nextDataType = XssfDataType.BOOL;
		else if ("e".equals(cellType))
			nextDataType = XssfDataType.ERROR;
		else if ("inlineStr".equals(cellType))
			nextDataType = XssfDataType.INLINESTR;
		else if ("s".equals(cellType))
			nextDataType = XssfDataType.SSTINDEX;
		else if ("str".equals(cellType))
			nextDataType = XssfDataType.FORMULA;
		else if (cellStyleStr != null) {
			int styleIndex = Integer.parseInt(cellStyleStr);
			XSSFCellStyle style = stylesTable.getStyleAt(styleIndex);
			this.formatIndex = style.getDataFormat();
			this.formatString = style.getDataFormatString();
			if (this.formatString == null) {
				this.formatString = BuiltinFormats.getBuiltinFormat(this.formatIndex);
			}
		}
	}
	lastContents = "";
}
 
开发者ID:bsteker,项目名称:bdf2,代码行数:41,代码来源:XSSFParser.java

示例6: startElement

import org.apache.poi.xssf.usermodel.XSSFCellStyle; //导入方法依赖的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;
		}
	}
}
 
开发者ID:Ostrich-Emulators,项目名称:semtool,代码行数:40,代码来源:LoadingSheetXmlHandler.java

示例7: endElement

import org.apache.poi.xssf.usermodel.XSSFCellStyle; //导入方法依赖的package包/类
@Override
public void endElement(String uri, String localName, String qName)
    throws SAXException
{
    try
    {
        if ((localName != null) && localName.equals(VALUE_TAGNAME) && (uri != null) && uri.equals(SPREADSHEETML_NAMESPACE))
        {
            Integer rowNumber    = getRowNumber(_cellName);
            Integer columnNumber = getColumnNumber(_cellName);

            Map<Integer, Object> row = _sheet.get(rowNumber);
            if (row == null)
            {
                row = new HashMap<Integer, Object>();
                _sheet.put(rowNumber, row);
            }

            if ("str".equals(_cellType))
                row.put(columnNumber, _value.toString());
            else if ("n".equals(_cellType))
            {
                XSSFCellStyle style           = _stylesTable.getStyleAt(Integer.parseInt(_cellStyle));
                String        excelDateFormat = style.getDataFormatString();

                if (isExcelDataTime(excelDateFormat))
                    row.put(columnNumber, excelDateTimeToString(_value.toString(), excelDateFormat));
                else
                    row.put(columnNumber, _value.toString());
            }
            else if ("s".equals(_cellType))
            {
                int index = Integer.parseInt(_value.toString());
                CTRst stringRef = _sharedStringsTable.getEntryAt(index);
                row.put(columnNumber, stringRef.getT());
            }
            else if (_cellType == null)
                row.put(columnNumber, _value.toString());

            _value.setLength(0);
        }
    }
    catch (Throwable throwable)
    {
        logger.log(Level.WARNING, "Problem processing end tag", throwable);
    }
}
 
开发者ID:arjuna-technologies,项目名称:Apache-POI_DataBroker_PlugIn,代码行数:48,代码来源:XSSFStreamSheetToCSVDataProcessor.java

示例8: startElement

import org.apache.poi.xssf.usermodel.XSSFCellStyle; //导入方法依赖的package包/类
public void startElement(String uri, String localName, String qName,
		Attributes attributes) throws SAXException {
	if (qName.equals("c")) {
		String vCellType = attributes.getValue("t");
		String cellS = attributes.getValue("s");
		if ("b".equals(vCellType))
			cellDataType = cDataType.BOOL;
		else if ("e".equals(vCellType))
			cellDataType = cDataType.FORMULA;
		else if ("s".equals(vCellType))
			cellDataType = cDataType.SSTINDEX;
		else if("str".equals(vCellType))
			cellDataType =  cDataType.STATIC;
        else if (cellS != null) {
              //number with formatting or date
            int styleIndex = Integer.parseInt(cellS);
            XSSFCellStyle style = st.getStyleAt(styleIndex);
            short formatIndex = style.getDataFormat();
            String formatString = style.getDataFormatString();

            if (formatString == null)
                   formatString = BuiltinFormats.getBuiltinFormat(formatIndex);

			if (org.apache.poi.ss.usermodel.DateUtil.isADateFormat(
					formatIndex, formatString) ) {
            	cellDataType =  cDataType.DATETIME;
            }else{
            	cellDataType = cDataType.NUMBER;
            }
        }
		else
			cellDataType = cDataType.NUMBER;

              String r = attributes.getValue("r");

              currentColumn = getColumnNumber( r );
              //expand the number of columns if needed in existing rows
              if( currentColumn+1 > columnCount){
              	callback.columnExpansion(currentColumn+1);
              	
              	//clean up current row
              	int newvals = (currentColumn+1) - columnCount;
              	for( int ii=0; ii<newvals;ii++){
              		values.add(ExcelODAConstants.EMPTY_STRING);
              	}               	
              	
          		columnCount = currentColumn+1;
              }

	}

	//empty cells are not in the xml so we have
	//create them in the row
	if (qName.equals("row")) {
		for( int i=0;i<columnCount; i++){
			values.add(i, ExcelODAConstants.EMPTY_STRING);
		}
	}
	lastContents = ExcelODAConstants.EMPTY_STRING;
}
 
开发者ID:eclipse,项目名称:birt,代码行数:61,代码来源:XlsxFileReader.java

示例9: startElement

import org.apache.poi.xssf.usermodel.XSSFCellStyle; //导入方法依赖的package包/类
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
    if ("row".equals(qName)) {
        // element is a row

        // excel row numbers are 1-based
        int rowNumber = Integer.parseInt(attributes.getValue("r"));
        rowNumber = rowNumber - 1;

        if (_configuration.isSkipEmptyLines()) {
            _rowNumber++;
        } else {
            while (_rowNumber + 1 < rowNumber) {
                // empty lines are not skipped, so dispatch empty lines
                _rowNumber++;
                List<String> emptyValues = Collections.emptyList();
                List<Style> emptyStyles = Collections.emptyList();
                _callback.row(_rowNumber, emptyValues, emptyStyles);
            }
            _rowNumber = rowNumber;
        }
    } else if ("c".equals(qName)) {
        // element is a cell

        _inCell = true;

        final String r = attributes.getValue("r");
        int firstDigit = -1;
        for (int c = 0; c < r.length(); ++c) {
            if (Character.isDigit(r.charAt(c))) {
                firstDigit = c;
                break;
            }
        }
        _columnNumber = nameToColumn(r.substring(0, firstDigit));

        // Set up defaults.
        _dataType = XssfDataType.NUMBER;
        _formatIndex = -1;
        _formatString = null;

        final String cellType = attributes.getValue("t");
        if ("b".equals(cellType)) {
            _dataType = XssfDataType.BOOL;
        } else if ("e".equals(cellType)) {
            _dataType = XssfDataType.ERROR;
        } else if ("inlineStr".equals(cellType)) {
            _dataType = XssfDataType.INLINESTR;
        } else if ("s".equals(cellType)) {
            _dataType = XssfDataType.SSTINDEX;
        } else if ("str".equals(cellType)) {
            _dataType = XssfDataType.FORMULA;
        }

        String cellStyleStr = attributes.getValue("s");
        if (cellStyleStr != null) {
            // It's a number, but almost certainly one
            // with a special style or format
            int styleIndex = Integer.parseInt(cellStyleStr);
            XSSFCellStyle style = _stylesTable.getStyleAt(styleIndex);

            configureStyle(style);

            if (_dataType == XssfDataType.NUMBER) {
                this._formatIndex = style.getDataFormat();
                this._formatString = style.getDataFormatString();
                if (this._formatString == null) {
                    this._formatString = BuiltinFormats.getBuiltinFormat(this._formatIndex);
                }
            }
        }
    } else if (_inCell && "f".equals(qName)) {
        // skip the actual formula line
        _inFormula = true;
    }
}
 
开发者ID:apache,项目名称:metamodel,代码行数:77,代码来源:XlsxSheetToRowsHandler.java

示例10: startElement

import org.apache.poi.xssf.usermodel.XSSFCellStyle; //导入方法依赖的package包/类
public void startElement(String uri, String localName, String name,
                         Attributes attributes) throws SAXException {

    if ("inlineStr".equals(name) || "v".equals(name)) {
        vIsOpen = true;
        // Clear contents cache
        value.setLength(0);
    }
    // c => cell
    else if ("c".equals(name)) {
        // Get the cell reference
        String r = attributes.getValue("r");
        int firstDigit = -1;
        for (int c = 0; c < r.length(); ++c) {
            if (Character.isDigit(r.charAt(c))) {
                firstDigit = c;
                break;
            }
        }
        thisColumn = nameToColumn(r.substring(0, firstDigit));

        // Set up defaults.
        this.nextDataType = xssfDataType.NUMBER;
        this.formatIndex = -1;
        this.formatString = null;
        String cellType = attributes.getValue("t");
        String cellStyleStr = attributes.getValue("s");
        if ("b".equals(cellType))
            nextDataType = xssfDataType.BOOL;
        else if ("e".equals(cellType))
            nextDataType = xssfDataType.ERROR;
        else if ("inlineStr".equals(cellType))
            nextDataType = xssfDataType.INLINESTR;
        else if ("s".equals(cellType))
            nextDataType = xssfDataType.SSTINDEX;
        else if ("str".equals(cellType))
            nextDataType = xssfDataType.FORMULA;
        else if (cellStyleStr != null) {
            // It's a number, but almost certainly one
            //  with a special style or format 
            int styleIndex = Integer.parseInt(cellStyleStr);
            XSSFCellStyle style = stylesTable.getStyleAt(styleIndex);
            this.formatIndex = style.getDataFormat();
            this.formatString = style.getDataFormatString();
            if (this.formatString == null)
                this.formatString = BuiltinFormats.getBuiltinFormat(this.formatIndex);
        }
    }

}
 
开发者ID:nagirrab,项目名称:xls2csv,代码行数:51,代码来源:XlsxToCsv.java


注:本文中的org.apache.poi.xssf.usermodel.XSSFCellStyle.getDataFormatString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。