本文整理汇总了Java中org.apache.poi.hssf.usermodel.HSSFCell.getCellType方法的典型用法代码示例。如果您正苦于以下问题:Java HSSFCell.getCellType方法的具体用法?Java HSSFCell.getCellType怎么用?Java HSSFCell.getCellType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.poi.hssf.usermodel.HSSFCell
的用法示例。
在下文中一共展示了HSSFCell.getCellType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCellValue
import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
private String getCellValue(HSSFCell cell){
if(cell == null) return "";
switch (cell.getCellType()) {
case HSSFCell.CELL_TYPE_STRING: return cell.getStringCellValue();
case HSSFCell.CELL_TYPE_BOOLEAN : return Boolean.toString(cell.getBooleanCellValue());
case HSSFCell.CELL_TYPE_NUMERIC :
if(HSSFDateUtil.isCellDateFormatted(cell))
return DateUtils.formatDateTime("yyyyMMdd", HSSFDateUtil.getJavaDate(cell.getNumericCellValue()));
else
return new BigDecimal(cell.getNumericCellValue()).toPlainString();
case HSSFCell.CELL_TYPE_FORMULA : return "";
case HSSFCell.CELL_TYPE_BLANK : return "";
default:return "";
}
}
示例2: findMatchColumn
import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
public static Integer findMatchColumn(final HSSFRow row, final String str) {
for (int colNum = row.getFirstCellNum(); colNum <= row.getLastCellNum(); colNum++) {
final HSSFCell cell = row.getCell(colNum);
if (cell == null) {
continue;
}
if (cell.getCellType() != Cell.CELL_TYPE_STRING) {
continue;
}
final HSSFRichTextString cellValue = cell.getRichStringCellValue();
if (cellValue.getString().matches(str)) {
return Integer.valueOf(colNum);
}
}
return null;
}
示例3: getIntCellValue
import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
public static int getIntCellValue(HSSFSheet sheet, int r, int c) {
HSSFRow row = sheet.getRow(r);
if (row == null) {
return 0;
}
HSSFCell cell = row.getCell(c);
try {
if (cell.getCellType() != HSSFCell.CELL_TYPE_NUMERIC) {
return 0;
}
} catch (RuntimeException e) {
System.err.println("Exception at sheet name:"
+ sheet.getSheetName() + ", row:" + (r + 1) + ", col:"
+ (c + 1));
throw e;
}
return (int) cell.getNumericCellValue();
}
示例4: getCellValue
import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
/**
* 获取EXCEL文件单元列值
*
* @param row
* @param point
* @return
*/
private static String getCellValue(HSSFRow row, int point) {
String reString = "";
try {
HSSFCell cell = row.getCell((short) point);
if (cell.getCellType() == 1)
reString = cell.getStringCellValue();
else if (cell.getCellType() == 0) {
reString = convert(cell.getNumericCellValue());
BigDecimal bd = new BigDecimal(reString);
reString = bd.toPlainString();
} else {
reString = "";
}
System.out.println(cell.getCellType() + ":" + cell.getCellFormula());
} catch (Exception localException) {
}
return checkNull(reString);
}
示例5: reader
import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
public static void reader(String filePath) {
try {
POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(filePath));
HSSFWorkbook wb = new HSSFWorkbook(fs);
HSSFSheet sheet = wb.getSheetAt(0);
HSSFRow row = sheet.getRow(3);
HSSFCell cell = row.getCell((short) 0);
int type = cell.getCellType();
String msg = getCellStringValue(cell);
System.out.println(type + ":" + msg);
} catch (IOException e) {
e.printStackTrace();
}
}
示例6: findColumn
import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
public static Integer findColumn(final HSSFRow row, final String str) {
for (int colNum = row.getFirstCellNum(); colNum <= row.getLastCellNum(); colNum++) {
final HSSFCell cell = row.getCell(colNum);
if (cell == null) {
continue;
}
if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
final HSSFRichTextString cellValue = cell.getRichStringCellValue();
if (str.equals(cellValue.getString())) {
return Integer.valueOf(colNum);
}
}
}
return null;
}
示例7: getIntCellValue
import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
public static int getIntCellValue(final HSSFSheet sheet, final int r, final int c) {
final HSSFRow row = sheet.getRow(r);
if (row == null) {
return 0;
}
final HSSFCell cell = row.getCell(c);
try {
if (cell.getCellType() != Cell.CELL_TYPE_NUMERIC) {
return 0;
}
} catch (final RuntimeException e) {
System.err.println("Exception at sheet name:" + sheet.getSheetName() + ", row:" + (r + 1) + ", col:" + (c + 1));
throw e;
}
return (int) cell.getNumericCellValue();
}
示例8: findColumn
import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
public static Integer findColumn(HSSFRow row, String str) {
for (int colNum = row.getFirstCellNum(); colNum <= row.getLastCellNum(); colNum++) {
HSSFCell cell = row.getCell(colNum);
if (cell == null) {
continue;
}
if (cell.getCellType() == HSSFCell.CELL_TYPE_STRING) {
HSSFRichTextString cellValue = cell.getRichStringCellValue();
if (str.equals(cellValue.getString())) {
return Integer.valueOf(colNum);
}
}
}
return null;
}
示例9: findMatchColumn
import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
public static Integer findMatchColumn(HSSFRow row, String str) {
for (int colNum = row.getFirstCellNum(); colNum <= row.getLastCellNum(); colNum++) {
HSSFCell cell = row.getCell(colNum);
if (cell == null) {
continue;
}
if (cell.getCellType() != HSSFCell.CELL_TYPE_STRING) {
continue;
}
HSSFRichTextString cellValue = cell.getRichStringCellValue();
if (cellValue.getString().matches(str)) {
return Integer.valueOf(colNum);
}
}
return null;
}
示例10: fromHSSFRowtoCSV
import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
private String fromHSSFRowtoCSV(HSSFRow row){
StringBuffer csvRow = new StringBuffer();
int l = row.getLastCellNum();
for (int i=0;i<l;i++){
HSSFCell 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: getCellData
import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
/**
* Get cell value based on the excel column data type
*
* @param myCell
* @return
*/
private static String getCellData(HSSFCell myCell) throws Exception {
String cellData = "";
if (myCell == null) {
cellData += CVS_SEPERATOR_CHAR;;
} else {
switch (myCell.getCellType()) {
case HSSFCell.CELL_TYPE_STRING:
case HSSFCell.CELL_TYPE_BOOLEAN:
cellData += myCell.getRichStringCellValue() + CVS_SEPERATOR_CHAR;
break;
case HSSFCell.CELL_TYPE_NUMERIC:
cellData += getNumericValue(myCell);
break;
case HSSFCell.CELL_TYPE_FORMULA:
cellData += getFormulaValue(myCell);
default:
cellData += CVS_SEPERATOR_CHAR;
;
}
}
return cellData;
}
示例12: manageInteger
import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
private Integer manageInteger(PreparedStatement ps, PreparedStatement psUpdate, int lfdCol, HSSFCell cell) throws SQLException {
Integer result = null;
if (cell == null || cell.getCellType() == HSSFCell.CELL_TYPE_BLANK) {
} else if (cell.getCellType() == HSSFCell.CELL_TYPE_STRING) {
if (cell.getStringCellValue().trim().length() > 0) {
result = new Integer(cell.getStringCellValue());
if (ps != null) ps.setInt(lfdCol, result);
if (psUpdate != null) psUpdate.setInt(lfdCol, result);
return result;
}
} else {
result = new Integer((int) cell.getNumericCellValue());
if (ps != null) ps.setInt(lfdCol, result);
if (psUpdate != null) psUpdate.setInt(lfdCol, result);
return result;
}
if (ps != null) ps.setNull(lfdCol, java.sql.Types.INTEGER);
if (psUpdate != null) psUpdate.setNull(lfdCol, java.sql.Types.INTEGER);
return result;
}
示例13: getValueFromCell
import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
/**
* <b>描述:</b> 从单元格中获取到的数据
* @param cell 单元格对应的HSSFCell对象
* @return Object 从单元格中获取到的数据
*/
private Object getValueFromCell(HSSFCell cell){
if(cell==null)return "";
switch(cell.getCellType()){
case HSSFCell.CELL_TYPE_BOOLEAN:
return cell.getBooleanCellValue();
case HSSFCell.CELL_TYPE_NUMERIC:
return cell.getNumericCellValue();
case HSSFCell.CELL_TYPE_FORMULA:
return cell.getCellFormula();
case HSSFCell.CELL_TYPE_STRING:
return cell.getRichStringCellValue().toString();
default:
return cell.getRichStringCellValue().toString();
}
}
示例14: manageBigInteger
import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
private Long manageBigInteger(PreparedStatement ps, PreparedStatement psUpdate, int lfdCol, HSSFCell cell) throws SQLException {
Long result = null;
if (cell == null || cell.getCellType() == HSSFCell.CELL_TYPE_BLANK) {
} else if (cell.getCellType() == HSSFCell.CELL_TYPE_STRING) {
if (cell.getStringCellValue().trim().length() > 0) {
result = new Long(cell.getStringCellValue());
if (ps != null) ps.setLong(lfdCol, result);
if (psUpdate != null) psUpdate.setLong(lfdCol, result);
return result;
}
} else {
result = new Long((long) cell.getNumericCellValue());
if (ps != null) ps.setLong(lfdCol, result);
if (psUpdate != null) psUpdate.setLong(lfdCol, result);
return result;
}
if (ps != null) ps.setNull(lfdCol, java.sql.Types.BIGINT);
if (psUpdate != null) psUpdate.setNull(lfdCol, java.sql.Types.BIGINT);
return result;
}
示例15: manageBoolean
import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
private Boolean manageBoolean(PreparedStatement ps, PreparedStatement psUpdate, int lfdCol, HSSFCell cell) throws SQLException {
Boolean result = null;
if (cell == null || cell.getCellType() == HSSFCell.CELL_TYPE_BLANK) {
if (ps != null) ps.setNull(lfdCol, java.sql.Types.BOOLEAN);
if (psUpdate != null) psUpdate.setNull(lfdCol, java.sql.Types.BOOLEAN);
} else if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) {
result = cell.getNumericCellValue() != 0;
if (ps != null) ps.setBoolean(lfdCol, result);
if (psUpdate != null) psUpdate.setBoolean(lfdCol, result);
} else if (cell.getCellType() == HSSFCell.CELL_TYPE_STRING) {
result = cell.getStringCellValue().equalsIgnoreCase("true");
if (ps != null) ps.setBoolean(lfdCol, result);
if (psUpdate != null) psUpdate.setBoolean(lfdCol, result);
} else {
result = cell.getBooleanCellValue();
if (ps != null) ps.setBoolean(lfdCol, result);
if (psUpdate != null) psUpdate.setBoolean(lfdCol, result);
}
//ps.setNull(lfdCol, java.sql.Types.BOOLEAN);
return result;
}