本文整理汇总了Java中org.apache.poi.xssf.usermodel.XSSFCell.getStringCellValue方法的典型用法代码示例。如果您正苦于以下问题:Java XSSFCell.getStringCellValue方法的具体用法?Java XSSFCell.getStringCellValue怎么用?Java XSSFCell.getStringCellValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.poi.xssf.usermodel.XSSFCell
的用法示例。
在下文中一共展示了XSSFCell.getStringCellValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
}
示例2: 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;
}
示例3: 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)
));
}
}
示例4: 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();
}
示例5: 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;
}
示例6: 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;
}
示例7: validate
import org.apache.poi.xssf.usermodel.XSSFCell; //导入方法依赖的package包/类
@Override
public ValidationResult validate(XSSFCell cell) {
int cellType = cell.getCellType();
if (cellType == Cell.CELL_TYPE_BLANK) {
return null;
}
double cellValue;
if (cellType == Cell.CELL_TYPE_NUMERIC) {
cellValue = cell.getNumericCellValue();
} else if (cellType == Cell.CELL_TYPE_STRING) {
String stringValue = cell.getStringCellValue();
try{
cellValue = Double.parseDouble(stringValue);
//Warning
}catch(NumberFormatException e){
//Error
return new ValidationResultImpl(cell.getSheet().getSheetName(), cell.getReference(), false, "Value type is not as expected!");
}
} else {
return new ValidationResultImpl(cell.getSheet().getSheetName(), cell.getReference(), false, "Value type is not as expected!"); //Error
}
if (operator.check(cellValue)) {
//True
return null;
} else {
//Error
return new ValidationResultImpl(cell.getSheet().getSheetName(), cell.getReference(), false, "Error!");
}
}
示例8: getCellDataAsString
import org.apache.poi.xssf.usermodel.XSSFCell; //导入方法依赖的package包/类
private String getCellDataAsString(XSSFCell cell) {
String value = "";
if (cell != null) {
int cellType = cell.getCellType();
switch (cellType) {
case Cell.CELL_TYPE_BLANK:
value = "";
break;
case Cell.CELL_TYPE_BOOLEAN:
value = (cell.getBooleanCellValue()) ? "true" : "false";
break;
case Cell.CELL_TYPE_ERROR:
value = cell.getErrorCellString();
break;
case Cell.CELL_TYPE_FORMULA:
value = cell.getStringCellValue();
break;
case Cell.CELL_TYPE_NUMERIC:
value = Double.toString(cell.getNumericCellValue());
break;
case Cell.CELL_TYPE_STRING:
default:
value = cell.getStringCellValue();
}
}
return value.trim();
}
示例9: autoSizeRow
import org.apache.poi.xssf.usermodel.XSSFCell; //导入方法依赖的package包/类
public void autoSizeRow(int row) {
float tallestCell = -1;
for (int col = 0; col <= highestModifiedCol; col++) {
SpreadsheetCell cell = getOrCreateCell(row, col);
int fontSize = cell.getFontSizeInPoints();
XSSFCell poiCell = cell.getPoiCell();
if (poiCell.getCellType() == Cell.CELL_TYPE_STRING) {
String value = poiCell.getStringCellValue();
int numLines = 1;
for (int i = 0; i < value.length(); i++) {
if (value.charAt(i) == '\n') numLines++;
}
float cellHeight = computeRowHeightInPoints(fontSize, numLines);
if (cellHeight > tallestCell) {
tallestCell = cellHeight;
}
}
}
float defaultRowHeightInPoints = sheet.getDefaultRowHeightInPoints();
float rowHeight = tallestCell;
if (rowHeight < defaultRowHeightInPoints+1) {
rowHeight = -1; // resets to the default
}
sheet.getRow(row).setHeightInPoints(rowHeight);
}
示例10: cellToString
import org.apache.poi.xssf.usermodel.XSSFCell; //导入方法依赖的package包/类
private static String cellToString(XSSFCell cell) {
Object result;
switch (cell.getCellType()) {
case Cell.CELL_TYPE_NUMERIC:
result = cell.getNumericCellValue();
break;
case Cell.CELL_TYPE_STRING:
result = cell.getStringCellValue();
break;
case Cell.CELL_TYPE_BOOLEAN:
result = cell.getBooleanCellValue();
break;
case Cell.CELL_TYPE_FORMULA:
result = cell.getCellFormula();
break;
default:
throw new RuntimeException("Unknown Cell Type");
}
return result.toString();
}
示例11: readExcel2007
import org.apache.poi.xssf.usermodel.XSSFCell; //导入方法依赖的package包/类
public static ArrayList<ArrayList<ArrayList<Object>>> readExcel2007(File file){
try{
ArrayList<ArrayList<ArrayList<Object>>> sheetArray = new ArrayList<ArrayList<ArrayList<Object>>> ();
XSSFWorkbook wb = new XSSFWorkbook(new FileInputStream(file));
for(int sheetNum = 0;sheetNum < wb.getNumberOfSheets();sheetNum++){
ArrayList<ArrayList<Object>> rowList = new ArrayList<ArrayList<Object>>();
ArrayList<Object> colList;
XSSFSheet sheet = wb.getSheetAt(sheetNum);
XSSFRow row;
XSSFCell cell;
Object value;
for(int i = 0 , rowCount = 0; rowCount < sheet.getPhysicalNumberOfRows() ; i++ ){
row = sheet.getRow(i);
colList = new ArrayList<Object>();
if(row == null){
//����ȡ��Ϊ��ʱ
if(i != sheet.getPhysicalNumberOfRows()){//�ж��Ƿ������һ��
rowList.add(colList);
}
continue;
}else{
rowCount++;
}
for( int j = 0 ; j <= row.getLastCellNum() ;j++){
cell = row.getCell(j);
if(cell == null ){
//���õ�Ԫ��Ϊ��
if(j != row.getLastCellNum()){//�ж��Ƿ��Ǹ��������һ����Ԫ��
colList.add("");
}
continue;
}
switch(cell.getCellType()){
case XSSFCell.CELL_TYPE_STRING:
value = cell.getStringCellValue();
break;
case XSSFCell.CELL_TYPE_NUMERIC:
if ("@".equals(cell.getCellStyle().getDataFormatString())) {
value = df.format(cell.getNumericCellValue());
} else if ("General".equals(cell.getCellStyle()
.getDataFormatString())) {
value = nf.format(cell.getNumericCellValue());
} else {
value = sdf.format(HSSFDateUtil.getJavaDate(cell
.getNumericCellValue()));
}
break;
case XSSFCell.CELL_TYPE_BOOLEAN:
value = Boolean.valueOf(cell.getBooleanCellValue());
break;
case XSSFCell.CELL_TYPE_BLANK:
value = "";
break;
default:
value = cell.toString();
}// end switch
colList.add(value);
}//end for j
rowList.add(colList);
}//end for i
sheetArray.add(rowList);
}// end sheetNum
return sheetArray;
}catch(Exception e){
return null;
}
}
示例12: readTypeString
import org.apache.poi.xssf.usermodel.XSSFCell; //导入方法依赖的package包/类
@Override
public String readTypeString(XSSFCell cell) {
return cell.getStringCellValue();
}
示例13: validate
import org.apache.poi.xssf.usermodel.XSSFCell; //导入方法依赖的package包/类
@Override
public ValidationResult validate(XSSFCell cell) {
//result ??
int cellType = cell.getCellType();
if (cellType == Cell.CELL_TYPE_BLANK) {
return null;
}
double cellValue;
if (cellType == Cell.CELL_TYPE_NUMERIC) {
cellValue = cell.getNumericCellValue();
} else if (cellType == Cell.CELL_TYPE_STRING) {
String stringValue = cell.getStringCellValue();
try{
cellValue = Double.parseDouble(stringValue);
//Warning
}catch(NumberFormatException e){
//Error
return new ValidationResultImpl(cell.getSheet().getSheetName(), cell.getReference(), false, "Error!");
}
} else {
//Error
return new ValidationResultImpl(cell.getSheet().getSheetName(), cell.getReference(), false, "Error!");
}
//TODO : refactor above code, they are duplicate with DecimalValidator!
int intRepresentation = (int) cellValue;
if(Double.compare(cellValue, intRepresentation)==0){
//Continue...
}else{
//Error
return new ValidationResultImpl(cell.getSheet().getSheetName(), cell.getReference(), false, "Error!");
}
if (operator.check(cellValue)) {
//True
} else {
return new ValidationResultImpl(cell.getSheet().getSheetName(), cell.getReference(), false, "Error!");
//Error
}
return null;
}
示例14: readPatients
import org.apache.poi.xssf.usermodel.XSSFCell; //导入方法依赖的package包/类
protected static List<SEPatient> readPatients(XSSFSheet xlSheet)
{
String property,value,unit;
List<SEPatient> patients = new ArrayList<SEPatient>();
try
{
int rows = xlSheet.getPhysicalNumberOfRows();
for (int r = 0; r < rows; r++)
{
XSSFRow row = xlSheet.getRow(r);
if (row == null)
continue;
int cells = row.getPhysicalNumberOfCells();
if(r==0)
{// Allocate the number of patients we have
for(int i=1;i<cells;i++)
patients.add(new SEPatient());
}
property = row.getCell(0).getStringCellValue();
if(property==null||property.isEmpty())
continue;
Log.info("Processing Patient Field : "+property);
for (int c = 1; c < cells; c++)
{
String cellValue=null;
XSSFCell cell = row.getCell(c);
switch(cell.getCellType())
{
case XSSFCell.CELL_TYPE_NUMERIC:
cellValue = Double.toString(cell.getNumericCellValue());
break;
case XSSFCell.CELL_TYPE_STRING:
cellValue = cell.getStringCellValue();
break;
}
if(cellValue==null||cellValue.isEmpty())
continue;
int split = cellValue.indexOf(" ");
// Pull The Value
if(split==-1)
{
value=cellValue;
unit="";
}
else
{
value = cellValue.substring(0,split);
unit = cellValue.substring(split+1);
}
if(value.equals("INF"))
value = "Infinity";
if(!setProperty(patients.get(c-1),property,value,unit))
{
Log.error("Error pulling"+property+" from "+cellValue);
break;
}
}
}
}
catch(Exception ex)
{
Log.error("Error reading XLS",ex);
return null;
}
return patients;
}
示例15: getExcelReader
import org.apache.poi.xssf.usermodel.XSSFCell; //导入方法依赖的package包/类
public static List<Map<String, String>> getExcelReader() {
String[] colName = { "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday" };
List<Map<String, String>> list = new ArrayList<Map<String, String>>();
try {
FileInputStream fis = new FileInputStream("c:\\wdmFx\\db\\webtoonList1.xlsx");
XSSFWorkbook workbook = new XSSFWorkbook(fis);
// 시트 수 (첫번째에만 존재하므로 0을 준다)
// 만약 각 시트를 읽기위해서는 FOR문을 한번더 돌려준다
XSSFSheet sheet = workbook.getSheetAt(0);
int rows = sheet.getPhysicalNumberOfRows();
Map<String, String> map = null;
for (int i = 0; i < rows; i++) {
if (i != 0) {
XSSFRow row = sheet.getRow(i); // 행을 읽는다
String value = "";
// 셀의 갯수를 실제 필드갯수로 지정.
int cells = colName.length;
map = new LinkedHashMap<String, String>();
for (int j = 0; j < cells; j++) {
XSSFCell cell = row.getCell(j); // 셀값을 읽는다
if (cell != null) {
switch (cell.getCellType()) {
case XSSFCell.CELL_TYPE_FORMULA:
if (!"".equals(cell.toString())) {
value = cell.getCellFormula();
}
break;
case XSSFCell.CELL_TYPE_NUMERIC:
value = cell.getRawValue();
break;
case XSSFCell.CELL_TYPE_STRING:
value = cell.getStringCellValue();
break;
case XSSFCell.CELL_TYPE_BLANK:
value = "";
break;
case XSSFCell.CELL_TYPE_ERROR:
value = cell.getErrorCellValue() + "";
break;
default:
break;
}
map.put(colName[j], value);
}
} // end for
if (map.get(colName[0]) != null)
list.add(map);
} // end for
}
} catch (IOException e) {
e.printStackTrace();
}
return list;
}