当前位置: 首页>>代码示例>>Java>>正文


Java XSSFCell.toString方法代码示例

本文整理汇总了Java中org.apache.poi.xssf.usermodel.XSSFCell.toString方法的典型用法代码示例。如果您正苦于以下问题:Java XSSFCell.toString方法的具体用法?Java XSSFCell.toString怎么用?Java XSSFCell.toString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.poi.xssf.usermodel.XSSFCell的用法示例。


在下文中一共展示了XSSFCell.toString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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

示例2: readExcelFile

import org.apache.poi.xssf.usermodel.XSSFCell; //导入方法依赖的package包/类
/**
 * This method is the responsible of read the content of the .xlsx 
 * file.
 * @param path
 * @return List<Student>
 */

private List<Student> readExcelFile(String path){
	List<Student> lista = new ArrayList<Student>();
	//We here going to try to read the file
	try{
		
		FileInputStream stream = new FileInputStream(path); //Here we make an Stream to the file. 
		//Now we going to make the instance that we can work by the book and the sheet of the file
		XSSFWorkbook workBook = new XSSFWorkbook(stream); //This is the workbook
		XSSFSheet sheet = workBook.getSheetAt(0);//This is the sheet of the file
		//Now we going to iterate the rows or columns of the .xlsx file to find the information
		//of the cell that we want
		Iterator<Row> rowIterator = sheet.rowIterator();//We going start by the rows
		String gruop = "";
		String index = "";
		while(rowIterator.hasNext()){
			XSSFRow row = (XSSFRow) rowIterator.next();//The actual row
			Iterator<Cell> cellIterator = row.cellIterator();//Now we stay in the cells of the row
			while(cellIterator.hasNext()){//Now we explore the cells of this row
				XSSFCell cell = (XSSFCell) cellIterator.next();
				String tmp = cell.toString();
				if(tmp.charAt(1) == '-'){
					gruop = tmp.trim();
				}
				if(isNumber(tmp)){
					index = tmp.trim();
					int p = index.indexOf(".");
					index = index.substring(0, p);//Here we obtain the serial number of the guy
				}else{
					lista.add(new Student(tmp.trim(), gruop,index));
				}
			}
		}
		
	}catch(Exception e){
		e.printStackTrace();
	}
	
	return lista;
}
 
开发者ID:Noatino,项目名称:credentialsName,代码行数:47,代码来源:ReadExcelFile.java


注:本文中的org.apache.poi.xssf.usermodel.XSSFCell.toString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。