當前位置: 首頁>>代碼示例>>Java>>正文


Java XSSFCell.getStringCellValue方法代碼示例

本文整理匯總了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;
    }

}
 
開發者ID:theysay,項目名稱:preceive-batch,代碼行數:21,代碼來源:XLSXSourceProvider.java

示例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;
}
 
開發者ID:ykaragol,項目名稱:poi-data-validation,代碼行數:19,代碼來源:TextLengthValidator.java

示例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)
        ));
    }
}
 
開發者ID:hjj2017,項目名稱:xgame-code_server,代碼行數:33,代碼來源:XSSFUtil.java

示例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();
}
 
開發者ID:sakaiproject,項目名稱:sakai,代碼行數:25,代碼來源:SpreadsheetUploadBean.java

示例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;
}
 
開發者ID:fhm84,項目名稱:jexunit,代碼行數:36,代碼來源:ExcelLoader.java

示例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;
}
 
開發者ID:TekkLabs,項目名稱:memoria-politica,代碼行數:41,代碼來源:FedDepXlsxConverter.java

示例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!");
	}
}
 
開發者ID:ykaragol,項目名稱:poi-data-validation,代碼行數:32,代碼來源:DecimalValidator.java

示例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();
}
 
開發者ID:toolsqa,項目名稱:OptimusPrime,代碼行數:28,代碼來源:ExcelTestDataReader.java

示例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);
}
 
開發者ID:jbrundege,項目名稱:taro,代碼行數:28,代碼來源:SpreadsheetTab.java

示例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();
	}
 
開發者ID:Madusudanan,項目名稱:Selenium,代碼行數:28,代碼來源:readExcelXLSX.java

示例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;
	}
}
 
開發者ID:sqyNick,項目名稱:JavaUtils,代碼行數:68,代碼來源:ExcelUtil.java

示例12: readTypeString

import org.apache.poi.xssf.usermodel.XSSFCell; //導入方法依賴的package包/類
@Override
public String readTypeString(XSSFCell cell) {
	return cell.getStringCellValue();
}
 
開發者ID:lucastanziano,項目名稱:JavaFX-Skeleton-DEPRECATED,代碼行數:5,代碼來源:BaseCellReader.java

示例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;
}
 
開發者ID:ykaragol,項目名稱:poi-data-validation,代碼行數:43,代碼來源:NumericValidator.java

示例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;
}
 
開發者ID:ScreenBasedSimulator,項目名稱:ScreenBasedSimulator2,代碼行數:67,代碼來源:DataSetReader.java

示例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;
}
 
開發者ID:kimyearho,項目名稱:WebtoonDownloadManager,代碼行數:78,代碼來源:ExcelReader.java


注:本文中的org.apache.poi.xssf.usermodel.XSSFCell.getStringCellValue方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。