本文整理汇总了Java中org.apache.poi.ss.usermodel.Cell.getStringCellValue方法的典型用法代码示例。如果您正苦于以下问题:Java Cell.getStringCellValue方法的具体用法?Java Cell.getStringCellValue怎么用?Java Cell.getStringCellValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.poi.ss.usermodel.Cell
的用法示例。
在下文中一共展示了Cell.getStringCellValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCharValue
import org.apache.poi.ss.usermodel.Cell; //导入方法依赖的package包/类
private char getCharValue(Cell cell) {
int vType = getCellType(cell);
switch (vType) {
case Cell.CELL_TYPE_BLANK:
return 0;
case Cell.CELL_TYPE_NUMERIC:
return (char) cell.getNumericCellValue();
case Cell.CELL_TYPE_STRING:
String vStr = cell.getStringCellValue();
if (vStr.length() == 1)
return vStr.charAt(0);
else
throw new IllegalArgumentException("Can't get char from String whose length > 1");
default:
throw new IllegalArgumentException("Can't get char from type " + vType);
}
}
示例2: getHeaderMap
import org.apache.poi.ss.usermodel.Cell; //导入方法依赖的package包/类
/**
* 获取excel列表头
*
* @param titleRow excel行
* @param clz 类型
* @return ExcelHeader集合
* @throws InstantiationException 异常
* @throws IllegalAccessException 异常
*/
public static Map<Integer, ExcelHeader> getHeaderMap(Row titleRow, Class<?> clz)
throws InstantiationException, IllegalAccessException {
List<ExcelHeader> headers = getHeaderList(clz);
Map<Integer, ExcelHeader> maps = new HashMap<>();
for (Cell c : titleRow) {
String title = c.getStringCellValue();
for (ExcelHeader eh : headers) {
if (eh.getTitle().equals(title.trim())) {
maps.put(c.getColumnIndex(), eh);
break;
}
}
}
return maps;
}
示例3: setSheetData
import org.apache.poi.ss.usermodel.Cell; //导入方法依赖的package包/类
private void setSheetData(SheetData data, String group) {
data.setCurrentGroup(group);
// start from 1
data.setCurrentIndex(1);
// get sheet
Sheet vSheet = getWorkBook().getSheet(group);
Assert.notNull(vSheet, "Can't get sheet with name: " + group);
data.setSheet(vSheet);
// get row number
int vRowCount = vSheet.getLastRowNum() + 1;
data.setRowCount(vRowCount);
// get first row
Row vRow = vSheet.getRow(0);
Assert.notNull(vRow, "Invalid format: first row must be title");
// get column number
int vColumnCount = vRow.getLastCellNum();
String[] vTitles = new String[vColumnCount];
// read titles
for (int i = 0; i < vColumnCount; ++i) {
Cell vCell = vRow.getCell(i);
vTitles[i] = vCell.getStringCellValue();
}
data.setTitles(vTitles);
}
示例4: mergeRows
import org.apache.poi.ss.usermodel.Cell; //导入方法依赖的package包/类
/**
* 合并行
*/
//TODO 暂时支持两行表头
private void mergeRows(Sheet sheet, CellStyle cellStyle, ExcelMeta excelMeta) {
Row row = null;
Cell cell = null;
String[] lastRowVals = new String[excelMeta.getTitleColumnNum()];
for (int r = 0; r < excelMeta.getTitleRowNum(); r++) {
for (int c = 0; c < excelMeta.getTitleColumnNum(); c++) {
row = sheet.getRow(r);
cell = row.getCell(c);
if (r == 0) {
lastRowVals[c] = cell.getStringCellValue();
} else {
if (StringUtils.equals(lastRowVals[c], cell.getStringCellValue())) {
cell.setCellValue("");
sheet.addMergedRegion(new CellRangeAddress(0, r, c, c));
Cell nowCell = sheet.getRow(0).getCell(c);
nowCell.setCellStyle(cellStyle);
}
}
}
}
}
示例5: isBlankRow
import org.apache.poi.ss.usermodel.Cell; //导入方法依赖的package包/类
/**
* 判断空行
*/
private static boolean isBlankRow(Row row) {
if (row == null) {
return true;
}
boolean result = true;
Iterator<Cell> cells = row.cellIterator();
String value = "";
while (cells.hasNext()) {
Cell cell = cells.next();
int cellType = cell.getCellType();
switch (cellType) {
case Cell.CELL_TYPE_NUMERIC:
value = String.valueOf(cell.getNumericCellValue());
break;
case Cell.CELL_TYPE_STRING:
value = cell.getStringCellValue();
break;
case Cell.CELL_TYPE_BOOLEAN:
value = String.valueOf(cell.getBooleanCellValue());
break;
case Cell.CELL_TYPE_FORMULA:
value = String.valueOf(cell.getCellFormula());
break;
}
if (StringUtils.isNotBlank(value)) {
result = false;
break;
}
}
return result;
}
示例6: parse
import org.apache.poi.ss.usermodel.Cell; //导入方法依赖的package包/类
public Map<String, BoundaryPoint> parse(InputStream is) throws IOException {
Map<String, BoundaryPoint> boundaryPoints = new HashMap<>();
HSSFWorkbook workbook = new HSSFWorkbook(is);
HSSFSheet sheet = workbook.getSheetAt(0);
Iterator<Row> rowIterator = sheet.iterator();
rowIterator.next();
rowIterator.next();
while (rowIterator.hasNext()) {
Row row = rowIterator.next();
Cell boundaryPointNameCell = row.getCell(13);
Cell borderFromCell = row.getCell(14);
Cell borderToCell = row.getCell(15);
String boundaryPointName = boundaryPointNameCell.getStringCellValue();
if (boundaryPointName.equals("-")) {
continue;
}
Country borderFrom = toCountry(borderFromCell.getStringCellValue());
Country borderTo = toCountry(borderToCell.getStringCellValue());
boundaryPoints.put(boundaryPointName, new BoundaryPoint(boundaryPointName, borderFrom, borderTo));
}
return boundaryPoints;
}
示例7: getStringValue
import org.apache.poi.ss.usermodel.Cell; //导入方法依赖的package包/类
private String getStringValue(Cell cell) {
int vType = getCellType(cell);
switch (vType) {
case Cell.CELL_TYPE_STRING:
return cell.getStringCellValue();
case Cell.CELL_TYPE_BOOLEAN:
return String.valueOf(cell.getBooleanCellValue());
case Cell.CELL_TYPE_NUMERIC:
double vValue = cell.getNumericCellValue();
if (doubleIsInt(vValue))
return String.valueOf((int) vValue);
return String.valueOf(vValue);
case Cell.CELL_TYPE_BLANK:
return "";
default:
throw new IllegalArgumentException("Can't get String from type " + vType);
}
}
示例8: getCellValue
import org.apache.poi.ss.usermodel.Cell; //导入方法依赖的package包/类
/**
* 获取单元格内容
*
* @param c 单元格
* @return 单元格内容
*/
public static String getCellValue(Cell c) {
String o;
switch (c.getCellTypeEnum()) {
case BLANK:
o = "";
break;
case BOOLEAN:
o = String.valueOf(c.getBooleanCellValue());
break;
case FORMULA:
o = calculationFormula(c);
break;
case NUMERIC:
o = String.valueOf(c.getNumericCellValue());
o = matchDoneBigDecimal(o);
o = RegularUtils.converNumByReg(o);
break;
case STRING:
o = c.getStringCellValue();
break;
default:
o = null;
break;
}
return o;
}
示例9: appendItemCn
import org.apache.poi.ss.usermodel.Cell; //导入方法依赖的package包/类
public static void appendItemCn(BufferedWriter out, Cell cell1, Cell cell2) throws IOException {
if (cell1 == null || cell2 == null) {
return;
}
String name = cell2.getStringCellValue().replaceAll("( )+", "_").toLowerCase();
String value = cell1.getStringCellValue();
if(StringUtils.isEmpty(name) && StringUtils.isEmpty(value)){
return;
}
out.append(String.format("<string name=\"%s\">%s</string>", name, value));
out.newLine();
}
示例10: generate
import org.apache.poi.ss.usermodel.Cell; //导入方法依赖的package包/类
@Override
public List<String> generate(Sheet sheet) {
List<String> lines = new ArrayList<>();
for (Row row : sheet) {
Cell firstCell = row.getCell(0);
if (firstCell != null) {
String userId = firstCell.getStringCellValue();
if (".".equals(userId.substring(1, 2))) {
for (Cell cell : row) {
if (cell.getColumnIndex() == 0) {
continue;
}
if ("X".equals(cell.getStringCellValue())) {
switch (cell.getColumnIndex()) {
case 1:
lines.add(getInsertStatement(userId, 2237));
break;
case 2:
lines.add(getInsertStatement(userId, 4352));
break;
case 3:
lines.add(getInsertStatement(userId, 3657));
break;
case 4:
lines.add(getInsertStatement(userId, 5565));
break;
}
}
}
}
}
}
return lines;
}
示例11: addInsertStatementsForRow
import org.apache.poi.ss.usermodel.Cell; //导入方法依赖的package包/类
private void addInsertStatementsForRow(List<String> lines, Row row) {
Cell firstCell = row.getCell(0);
if (firstCell != null) {
String userId = firstCell.getStringCellValue();
if (isValidUserId(userId)) {
addInsertStatementsForRow(lines, row, userId);
}
}
}
开发者ID:jeffgbutler,项目名称:practical-functional-java,代码行数:10,代码来源:AwfulScriptGeneratorRefactoredStep1.java
示例12: getBoolean
import org.apache.poi.ss.usermodel.Cell; //导入方法依赖的package包/类
public static Boolean getBoolean(Cell cell) {
if (isNullCell(cell)) {
return null;
}
if (Cell.CELL_TYPE_BOOLEAN == cell.getCellType()) {
return cell.getBooleanCellValue();
}
if (Cell.CELL_TYPE_STRING == cell.getCellType()) {
String value = cell.getStringCellValue();
return "1".equals(value) || "是".equals(value);
}
throw new RuntimeException("can not convertWithConstructor cell value to Boolean!");
}
示例13: getCellValue
import org.apache.poi.ss.usermodel.Cell; //导入方法依赖的package包/类
private String getCellValue(final Cell cell, int count) {
String cellValue = null;
CellType ct = cell.getCellTypeEnum();
switch (ct) {
case STRING:
cellValue = cell.getStringCellValue();
break;
case NUMERIC:
cellValue = String.valueOf(cell.getNumericCellValue());
break;
case BOOLEAN:
cellValue = String.valueOf(cell.getBooleanCellValue());
break;
case BLANK:
if (count > -1) {
cellValue = "BLANK" + String.valueOf(count);
}
break;
case FORMULA:
CellType cacheCellType = cell.getCachedFormulaResultTypeEnum(); {
switch (cacheCellType) {
case STRING:
cellValue = cell.getStringCellValue();
break;
case NUMERIC:
cellValue = String.valueOf(cell.getNumericCellValue());
break;
case BOOLEAN:
cellValue = String.valueOf(cell.getBooleanCellValue());
break;
default:
cellValue = cell.getCellFormula();
}
}
break;
default:
cellValue = null;
}
return cellValue;
}
示例14: getValue
import org.apache.poi.ss.usermodel.Cell; //导入方法依赖的package包/类
/** 从表格之中读取数据并进行处理
* @param fieldInfo
* @param cell 当前cell
* @return
* @throws Exception
*/
public static Object getValue(ImportFieldInfo fieldInfo, Cell cell) throws Exception{
int size = fieldInfo.getTypeChain().size();
Class<?> type = fieldInfo.getTypeChain().get(size - 1);
String dateFormat = fieldInfo.getDateFormat();
int cellType = cell.getCellType();
Object obj = null ;
switch (cellType) {
case Cell.CELL_TYPE_BLANK:
return null;
case Cell.CELL_TYPE_BOOLEAN:
obj = cell.getBooleanCellValue();
break;
case Cell.CELL_TYPE_STRING:
obj = cell.getStringCellValue();
break;
case Cell.CELL_TYPE_NUMERIC:
if(DateUtil.isCellDateFormatted(cell)){
obj = DateUtil.getJavaDate(cell.getNumericCellValue());
}else if(Number.class.isAssignableFrom(type) || ClassUtils.isBaseNumberType(type)){
//当pojo字段类型是数字型时以数字形式获取
obj = cell.getNumericCellValue();
}else{
//其他类型都以string获取
obj = DATA_FORMATTER.formatCellValue(cell);
}
break;
case Cell.CELL_TYPE_ERROR:
return null;
}
if(fieldInfo.getImportProcessor() != null){
obj = fieldInfo.getImportProcessor().process(obj);
}
obj = ConvertUtils.convertIfNeccesary(obj, type, dateFormat);
return obj;
}
示例15: getCellValue
import org.apache.poi.ss.usermodel.Cell; //导入方法依赖的package包/类
/**
* 获取单元格值
*
* @param row 获取的行
* @param column 获取单元格列号
* @return 单元格值
*/
public Object getCellValue(Row row, int column) {
Object val = "";
try {
Cell cell = row.getCell(column);
if (cell != null) {
if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
// val = cell.getNumericCellValue();
// 当excel 中的数据为数值或日期是需要特殊处理
if (HSSFDateUtil.isCellDateFormatted(cell)) {
double d = cell.getNumericCellValue();
Date date = HSSFDateUtil.getJavaDate(d);
SimpleDateFormat dformat = new SimpleDateFormat(
"yyyy-MM-dd");
val = dformat.format(date);
} else {
NumberFormat nf = NumberFormat.getInstance();
nf.setGroupingUsed(false);// true时的格式:1,234,567,890
val = nf.format(cell.getNumericCellValue());// 数值类型的数据为double,所以需要转换一下
}
} else if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
val = cell.getStringCellValue();
} else if (cell.getCellType() == Cell.CELL_TYPE_FORMULA) {
val = cell.getCellFormula();
} else if (cell.getCellType() == Cell.CELL_TYPE_BOOLEAN) {
val = cell.getBooleanCellValue();
} else if (cell.getCellType() == Cell.CELL_TYPE_ERROR) {
val = cell.getErrorCellValue();
}
}
} catch (Exception e) {
return val;
}
return val;
}