本文整理匯總了Java中org.apache.poi.xssf.usermodel.XSSFCell.getCellType方法的典型用法代碼示例。如果您正苦於以下問題:Java XSSFCell.getCellType方法的具體用法?Java XSSFCell.getCellType怎麽用?Java XSSFCell.getCellType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.poi.xssf.usermodel.XSSFCell
的用法示例。
在下文中一共展示了XSSFCell.getCellType方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getCellValue
import org.apache.poi.xssf.usermodel.XSSFCell; //導入方法依賴的package包/類
/**
* Gets the cell value.
*
* @param cell the cell
* @return the cell value
*/
private String getCellValue( XSSFCell cell )
{
if (cell != null)
{
switch (cell.getCellType())
{
case XSSFCell.CELL_TYPE_BLANK:
return null;
case XSSFCell.CELL_TYPE_BOOLEAN:
return String.valueOf( cell.getBooleanCellValue() );
case XSSFCell.CELL_TYPE_NUMERIC:
return String.valueOf( ( int ) cell.getNumericCellValue() );
case XSSFCell.CELL_TYPE_STRING:
return cell.getRichStringCellValue().toString();
}
}
return null;
}
示例2: get
import org.apache.poi.xssf.usermodel.XSSFCell; //導入方法依賴的package包/類
public Object get(XSSFCell cell) {
if (cell != null) {
int cellType = cell.getCellType();
switch (cellType) {
case Cell.CELL_TYPE_NUMERIC:
return cell.getNumericCellValue();
case Cell.CELL_TYPE_BOOLEAN:
return cell.getBooleanCellValue();
default:
try {
return cell.getStringCellValue();
} catch (IllegalStateException mismatch) {
return null;
}
}
} else {
return null;
}
}
示例3: getCellValue
import org.apache.poi.xssf.usermodel.XSSFCell; //導入方法依賴的package包/類
/**
* Gets the cell value.
*
* @param cell the cell
* @return the cell value
*/
private String getCellValue( XSSFCell cell )
{
if (cell != null)
{
switch (cell.getCellType())
{
case XSSFCell.CELL_TYPE_BLANK:
return null;
case XSSFCell.CELL_TYPE_BOOLEAN:
return String.valueOf( cell.getBooleanCellValue() );
case XSSFCell.CELL_TYPE_NUMERIC:
return String.valueOf( cell.getNumericCellValue() );
case XSSFCell.CELL_TYPE_STRING:
return cell.getRichStringCellValue().toString();
}
}
return null;
}
示例4: getCellValue
import org.apache.poi.xssf.usermodel.XSSFCell; //導入方法依賴的package包/類
/**
* Gets the cell value.
*
* @param cell the cell
* @return the cell value
*/
private String getCellValue( XSSFCell cell )
{
if (cell != null)
{
switch (cell.getCellType())
{
case XSSFCell.CELL_TYPE_BLANK:
return null;
case XSSFCell.CELL_TYPE_BOOLEAN:
return String.valueOf( cell.getBooleanCellValue() );
case XSSFCell.CELL_TYPE_NUMERIC:
{
String useValue = String.valueOf( cell.getNumericCellValue() );
if ( useValue.endsWith( ".0" ) )
return useValue.split( "\\." )[0];
else
return useValue;
}
case XSSFCell.CELL_TYPE_STRING:
return cell.getRichStringCellValue().toString();
}
}
return null;
}
示例5: getCellValue
import org.apache.poi.xssf.usermodel.XSSFCell; //導入方法依賴的package包/類
private String getCellValue( XSSFCell cell )
{
if (cell != null )
{
switch (cell.getCellType())
{
case XSSFCell.CELL_TYPE_BLANK:
return null;
case XSSFCell.CELL_TYPE_BOOLEAN:
return String.valueOf( cell.getBooleanCellValue() );
case XSSFCell.CELL_TYPE_NUMERIC:
return String.valueOf( cell.getNumericCellValue() );
case XSSFCell.CELL_TYPE_STRING:
return cell.getRichStringCellValue().toString();
}
}
return null;
}
示例6: updateCellValue
import org.apache.poi.xssf.usermodel.XSSFCell; //導入方法依賴的package包/類
public void updateCellValue(String cellPosition, String value) throws Exception {
String sheetNumTxt = cellPosition.indexOf("[")>-1 ? cellPosition.substring(cellPosition.indexOf("[")) : null;
if(sheetNumTxt != null) {
this.sheetNum = new Integer(sheetNumTxt.substring(0,sheetNumTxt.length()-1));
cellPosition = cellPosition.substring(cellPosition.indexOf("["));
} else {
this.sheetNum = 0;
}
worksheet = workbook.getSheetAt(this.sheetNum);
CellReference c = new CellReference(cellPosition);
XSSFCell cell = worksheet.getRow(c.getRow()).getCell(c.getCol());
if(cell == null) throw new Exception("Invalid cell reference:" + cellPosition);
if(value == null) {
cell.setCellType(XSSFCell.CELL_TYPE_BLANK);
} else if(cell.getCellType()==XSSFCell.CELL_TYPE_FORMULA) {
this.setCellFormula(cell, value);
} else {
cell.setCellValue(value);
}
}
示例7: getValue
import org.apache.poi.xssf.usermodel.XSSFCell; //導入方法依賴的package包/類
public static Object getValue(XSSFSheet sheet, int row, int col) {
try {
XSSFRow xrow = sheet.getRow(row);
XSSFCell cell = xrow.getCell(col);
switch (cell.getCellType()) {
case Cell.CELL_TYPE_NUMERIC:
return cell.getNumericCellValue();
case Cell.CELL_TYPE_STRING:
return (new DateComponentFormatter(
ComponentManager.getInstance().getComponentFormatDefaults().getSelectedDateFormat()))
.stringToValue(cell.getStringCellValue());
}
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}
示例8: validate
import org.apache.poi.xssf.usermodel.XSSFCell; //導入方法依賴的package包/類
@Override
public ValidationResult validate(XSSFCell cell) {
if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
String stringCellValue = cell.getStringCellValue();
int length;
if (stringCellValue == null) {
length = 0;
} else {
length = stringCellValue.length();
}
if (!operator.check((double) length)) {
return new ValidationResultImpl(cell.getSheet().getSheetName(), cell.getReference(), false, "Error!");
}
} else {
// TODO how to handle this situation
}
return null;
}
示例9: getStrCellVal
import org.apache.poi.xssf.usermodel.XSSFCell; //導入方法依賴的package包/類
/**
* 獲取單元格字符串值
*
* @param cell
* @return
*
*/
public static String getStrCellVal(XSSFCell cell) {
if (cell == null) {
// 如果參數對象為空,
// 則直接退出!
return null;
}
switch (cell.getCellType()) {
case XSSFCell.CELL_TYPE_STRING:
return cell.getStringCellValue();
case XSSFCell.CELL_TYPE_BOOLEAN:
return cell.getBooleanCellValue() ? "true" : "false";
default:
// 拋出異常
throw new XlsxTmplError(MessageFormat.format(
ERR_CELL_TYPE,
getSheetIndex(cell) + 1,
getSheetName(cell),
String.valueOf(cell.getRowIndex() + 1),
getColName(cell.getColumnIndex()),
String.class.getName(),
getCellTypeName(cell)
));
}
}
示例10: fromXSSFRowtoCSV
import org.apache.poi.xssf.usermodel.XSSFCell; //導入方法依賴的package包/類
private String fromXSSFRowtoCSV(XSSFRow row){
StringBuffer csvRow = new StringBuffer();
int l = row.getLastCellNum();
for (int i=0;i<l;i++){
XSSFCell cell = row.getCell((short)i);
String cellValue = "";
if (cell == null || cell.getCellType() == HSSFCell.CELL_TYPE_BLANK) {
cellValue = "";
} else if (cell.getCellType()== HSSFCell.CELL_TYPE_STRING){
cellValue = "\"" + cell.getStringCellValue() + "\"";
} else if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC){
double value = cell.getNumericCellValue();
cellValue = getNumberFormat().format(value);
cellValue = "\"" + cellValue + "\"";
}
csvRow.append(cellValue);
if (i<l){
csvRow.append(getCsvDelimiter().toCharArray()[0]);
}
}
return csvRow.toString();
}
示例11: cellValues2String
import org.apache.poi.xssf.usermodel.XSSFCell; //導入方法依賴的package包/類
/**
* Get the value of the excel-cell as String.
*
* @param workbook
* workbook (excel) for evaluating cell formulas
* @param cell
* cell (excel)
*
* @return the value of the excel-cell as String
*/
static String cellValues2String(XSSFWorkbook workbook, XSSFCell cell) {
if (cell == null) {
return null;
}
switch (cell.getCellType()) {
case XSSFCell.CELL_TYPE_NUMERIC:
if (HSSFDateUtil.isCellDateFormatted(cell)) {
return new SimpleDateFormat(JExUnitConfig.getStringProperty(JExUnitConfig.ConfigKey.DATE_PATTERN))
.format(cell.getDateCellValue());
} else {
return String.valueOf(cell.getNumericCellValue());
}
case XSSFCell.CELL_TYPE_STRING:
return cell.getStringCellValue();
case XSSFCell.CELL_TYPE_FORMULA:
return evaluateCellFormula(workbook, cell);
case XSSFCell.CELL_TYPE_BLANK:
return cell.getStringCellValue();
case XSSFCell.CELL_TYPE_BOOLEAN:
return String.valueOf(cell.getBooleanCellValue());
case XSSFCell.CELL_TYPE_ERROR:
return String.valueOf(cell.getErrorCellValue());
}
return null;
}
示例12: getValue
import org.apache.poi.xssf.usermodel.XSSFCell; //導入方法依賴的package包/類
private static String getValue(XSSFCell xssFCell) {
String str = null;
if(xssFCell == null){
return str;
}
if (xssFCell.getCellType() == XSSFCell.CELL_TYPE_BOOLEAN) {
str = String.valueOf(xssFCell.getBooleanCellValue());
} else if (xssFCell.getCellType() == XSSFCell.CELL_TYPE_NUMERIC) {
str = String.valueOf(new DecimalFormat("#").format(xssFCell.getNumericCellValue()));
} else {
str = String.valueOf(xssFCell.getStringCellValue());
}
return StringUtils.trim(str);
}
示例13: copyCell
import org.apache.poi.xssf.usermodel.XSSFCell; //導入方法依賴的package包/類
/**
* @param oldCell
* @param newCell
* @param styleMap
*/
public static void copyCell(XSSFCell oldCell, XSSFCell newCell, Map<Integer, XSSFCellStyle> styleMap) {
if (styleMap != null) {
if (oldCell.getSheet().getWorkbook() == newCell.getSheet().getWorkbook()) {
newCell.setCellStyle(oldCell.getCellStyle());
} else {
int stHashCode = oldCell.getCellStyle().hashCode();
XSSFCellStyle newCellStyle = styleMap.get(stHashCode);
if (newCellStyle == null) {
newCellStyle = newCell.getSheet().getWorkbook().createCellStyle();
newCellStyle.cloneStyleFrom(oldCell.getCellStyle());
styleMap.put(stHashCode, newCellStyle);
}
newCell.setCellStyle(newCellStyle);
}
}
switch (oldCell.getCellType()) {
case XSSFCell.CELL_TYPE_STRING:
newCell.setCellValue(oldCell.getStringCellValue());
break;
case XSSFCell.CELL_TYPE_NUMERIC:
newCell.setCellValue(oldCell.getNumericCellValue());
break;
case XSSFCell.CELL_TYPE_BLANK:
newCell.setCellType(XSSFCell.CELL_TYPE_BLANK);
break;
case XSSFCell.CELL_TYPE_BOOLEAN:
newCell.setCellValue(oldCell.getBooleanCellValue());
break;
case XSSFCell.CELL_TYPE_ERROR:
newCell.setCellErrorValue(oldCell.getErrorCellValue());
break;
case XSSFCell.CELL_TYPE_FORMULA:
newCell.setCellFormula(oldCell.getCellFormula());
break;
default:
break;
}
}
示例14: extractDataFromXls
import org.apache.poi.xssf.usermodel.XSSFCell; //導入方法依賴的package包/類
private static JSONArray extractDataFromXls(XSSFWorkbook wb) {
XSSFSheet sheet = wb.getSheetAt(0);
int rows = sheet.getPhysicalNumberOfRows();
int cols = sheet.getRow(0).getPhysicalNumberOfCells();
int startRow = 1; // Pular cabecalho.
JsonObjectCreator jsonObjCreator = new FedDepJsonObjectCreator();
JSONArray jArr = new JSONArray();
for(int row = startRow; row < rows; row++) {
XSSFRow xssfRow = sheet.getRow(row);
if(xssfRow != null) {
String[] rowData = new String[cols];
for(int col = 0; col < cols; col++) {
XSSFCell cell = xssfRow.getCell(col);
if(cell != null) {
String datum;
if (XSSFCell.CELL_TYPE_STRING == cell.getCellType()) {
datum = cell.getStringCellValue();
}
else if (XSSFCell.CELL_TYPE_NUMERIC == cell.getCellType()) {
datum = String.valueOf(cell.getNumericCellValue());
}
else {
System.out.println("A célula: [" + row + "," + col + "] não contém um String e nem um Número.");
datum = "";
}
rowData[col] = datum;
}
}
JSONObject jObj = jsonObjCreator.processLine(rowData);
jArr.add(jObj);
}
}
return jArr;
}
示例15: shiftRange
import org.apache.poi.xssf.usermodel.XSSFCell; //導入方法依賴的package包/類
private void shiftRange(int numRowsDown, int rowStart, int rowEnd, int colStart, int colEnd) throws Exception {
// loop through from bottom row up to either SHIFT the whole row, or copy necessary columns, insert new row below, insert the data from the cell and then delete all style and format from the original cell
for(int j=rowEnd;j>rowStart;j--) {
XSSFRow row = worksheet.getRow(j);
XSSFRow newRow = worksheet.getRow(j+numRowsDown);
if(row == null && newRow == null)
continue;
else if (row == null) {
worksheet.removeRow(newRow);
continue;
}
if(newRow == null) {
newRow = worksheet.createRow(j+numRowsDown);
}
// newRow = worksheet.getRow(j+numRowsDown);
//if(row ==null) continue;
for(int k=colStart;k<=colEnd;k++) {
XSSFCell cell = row.getCell(k);
if(cell != null) {
XSSFCell newCell = newRow.getCell(k)==null ? newRow.createCell(k) : newRow.getCell(k);
if(cell==null) continue;
if(cell.getCellType() == XSSFCell.CELL_TYPE_FORMULA) {
String calc = cell.getCellFormula();
newCell.setCellStyle(cell.getCellStyle());
cell.setCellType(XSSFCell.CELL_TYPE_BLANK);
this.setCellFormula(newCell, calc);
} else if(cell.getCellType()==XSSFCell.CELL_TYPE_BLANK) {
newCell.setCellType(XSSFCell.CELL_TYPE_BLANK);
} else {
newCell.copyCellFrom(cell, new CellCopyPolicy());
newCell.setCellStyle(cell.getCellStyle());
}
}
}
}
}