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


Java XSSFRow.getPhysicalNumberOfCells方法代码示例

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


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

示例1: readXlsx

import org.apache.poi.xssf.usermodel.XSSFRow; //导入方法依赖的package包/类
public static ArrayList readXlsx(String path) throws IOException {
    XSSFWorkbook xwb = new XSSFWorkbook(path);
    XSSFSheet sheet = xwb.getSheetAt(0);
    XSSFRow row;
    String[] cell = new String[sheet.getPhysicalNumberOfRows() + 1];
    ArrayList<String> arrayList = new ArrayList<>();
    for (int i = sheet.getFirstRowNum() + 1; i < sheet.getPhysicalNumberOfRows(); i++) {
        cell[i] = "";
        row = sheet.getRow(i);
        for (int j = row.getFirstCellNum(); j < row.getPhysicalNumberOfCells(); j++) {
            cell[i] += row.getCell(j).toString();
            cell[i] += " | ";
        }
        arrayList.add(cell[i]);
    }
    return arrayList;
}
 
开发者ID:inkss,项目名称:hotelbook-JavaWeb,代码行数:18,代码来源:ExportExcel.java

示例2: readAllLines

import org.apache.poi.xssf.usermodel.XSSFRow; //导入方法依赖的package包/类
public List<String[]> readAllLines(int sheetIndex){
	XSSFSheet sheet = getWorkBook().getSheetAt(sheetIndex);
	
	List<String[]> rows = CollectionFactory.newArrayList();
	for (int i = 0; i < sheet.getPhysicalNumberOfRows(); i++) {
		XSSFRow row = sheet.getRow(i);
		if (row != null) {
			String[] rowValues = new String[row.getPhysicalNumberOfCells()];
			for (int j = 0; j < row.getPhysicalNumberOfCells(); j++) {
				rowValues[j] = (row.getCell(j) != null)? getReader().read(row.getCell(j)) : "";
			}
			rows.add(rowValues);
		}
	}
	return rows;
}
 
开发者ID:lucastanziano,项目名称:JavaFX-Skeleton-DEPRECATED,代码行数:17,代码来源:XSSFileHelper.java

示例3: buildMaxColumn

import org.apache.poi.xssf.usermodel.XSSFRow; //导入方法依赖的package包/类
private int buildMaxColumn(XSSFSheet sheet){
	int rowCount=sheet.getPhysicalNumberOfRows();
	int maxColumnCount=0;
	for(int i=0;i<rowCount;i++){
		XSSFRow row=sheet.getRow(i);
		if(row==null){
			continue;
		}
		int columnCount=row.getPhysicalNumberOfCells();
		if(columnCount>maxColumnCount){
			maxColumnCount=columnCount;
		}
	}
	return maxColumnCount;
}
 
开发者ID:youseries,项目名称:ureport,代码行数:16,代码来源:XSSFExcelParser.java

示例4: parse

import org.apache.poi.xssf.usermodel.XSSFRow; //导入方法依赖的package包/类
/**
 * 解析导出的视频excel文件
 */
public static void parse(File file) {
	try {
		XSSFWorkbook xwb = new XSSFWorkbook(new FileInputStream(file));
		XSSFSheet sheet = xwb.getSheetAt(0);

		System.out.println(String.format("准备解析:%s, 表格:%s", file.getAbsolutePath(), sheet.getSheetName()));

		XSSFRow row = null;
		String cell = null;

		// 遍历行(从0开始)
		for (int i = 0; i < sheet.getPhysicalNumberOfRows(); i++) {
			row = sheet.getRow(i);

			// 忽略空行:真实
			if (row.getFirstCellNum() < 0) {
				continue;
			}

			// 遍历行-列
			for (int j = row.getFirstCellNum(); j < row.getPhysicalNumberOfCells(); j++) {
				if (row.getCell(j) == null) {
					continue;
				}
				cell = row.getCell(j).toString();
				if (StringUtil.isEmpty(cell)) {
					continue;
				}
				System.out.println(String.format("解析 行 %d 列 %d\t>>\t%s", i + 1, j, cell));
				appendSql(new Vi(cell));
			}
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
开发者ID:bdceo,项目名称:bd-codes,代码行数:40,代码来源:VidParser.java

示例5: processXlsx

import org.apache.poi.xssf.usermodel.XSSFRow; //导入方法依赖的package包/类
private XSSFWorkbook processXlsx(File input, HashMap<String, String> map) throws IOException {
    XSSFWorkbook workbook = new XSSFWorkbook(new FileInputStream(input));
    int rowindex = 0;
    int columnindex = 0;
    XSSFSheet sheet = workbook.getSheetAt(0);
    int rows = sheet.getPhysicalNumberOfRows();
    for (rowindex = 1; rowindex < rows; rowindex++) {
    	// Row만큼
        XSSFRow row = sheet.getRow(rowindex);
        if (row != null) {
        	// Row가 null이 아니면
            int cells = row.getPhysicalNumberOfCells();
            // 셀 갯수
            for (columnindex = 0; columnindex <= cells; columnindex++) {
            	// 셀 갯수만큼
                XSSFCell cell = row.getCell(columnindex);
                // row에서 셀 얻어오기
                if (cell != null && cell.getCellType() == 0) {
                	// 0 = Cell.CELL_TYPE_NUMERIC
                	// 학번임을 확인
                    String sNum = (String.valueOf((int) cell.getNumericCellValue()));
                    if (sNum != null) {
                    	// 학번이 null이 아니면
                        cell = row.getCell(columnindex + 1);
                        // 오른쪽 셀 얻어오기
                        if (cell.getCellType() == 1) {
                        	// 1 = Cell.CELL_TYPE_STRING
                        	// 학생 이름임을 확인
                            String type = map.get(sNum);
                            // 학번을 통해 잔류 상태 얻어오기
                            if (type != null) {
                            	// 잔류 상태가 null이 아니면
                                cell = row.getCell(columnindex + 2);
                                // 오른쪽 셀 얻어오기
                                cell.setCellValue(type);
                                // 잔류 상태 채우기
                            }
                        }
                    }
                }
            }
        }
    }
    return workbook;
}
 
开发者ID:DSM-DMS,项目名称:DMS,代码行数:46,代码来源:ResidualDownload.java

示例6: main

import org.apache.poi.xssf.usermodel.XSSFRow; //导入方法依赖的package包/类
/**
 * 解析Excel-2007 参考:http://kxjhlele.iteye.com/blog/321392
 * 
 */
public static void main(String[] args) {
    String excelPath = "D:/Download/全国汇编(物化).xlsx";

    try {
        XSSFWorkbook xwb = new XSSFWorkbook(new FileInputStream(excelPath));
        XSSFSheet sheet = xwb.getSheetAt(0);

        XSSFRow row = null;
        String cell = null;

        Map<String, String> peOrderMap = new TreeMap<String, String>();
        int porder = 0, eorder = 0;
        // 遍历所有行
        for (int i = 1; i < sheet.getPhysicalNumberOfRows(); i++) {
            row = sheet.getRow(i);
            // 遍历每一行的所有列
            for (int j = row.getFirstCellNum(); j < row.getPhysicalNumberOfCells(); j++) {
                cell = row.getCell(j).toString();
                if (j == 0 && !cell.isEmpty()) { // 试卷序号
                    porder = new Double(Double.parseDouble(cell)).intValue();
                }
                if (j == 2) { // 试卷下试题序号
                    eorder = new Double(Double.parseDouble(cell)).intValue();
                }
                if (j == 3) {// 录制老师姓名
                    peOrderMap.put(porder + "#" + eorder, cell);
                }
                System.out.print(cell + "\t");
            }
            System.out.println("");
        }

        for (Entry<String, String> en : peOrderMap.entrySet()) {
            System.out.println(en.getKey() + " - " + en.getValue());
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

}
 
开发者ID:bdceo,项目名称:bd-codes,代码行数:46,代码来源:TestPOI.java

示例7: parseKaoQinExcel

import org.apache.poi.xssf.usermodel.XSSFRow; //导入方法依赖的package包/类
/**
 * 解析考勤Excel表
 * 
 * @param file
 *            考勤文件
 */
public static void parseKaoQinExcel(File file) {
	try {
		XSSFWorkbook xwb = new XSSFWorkbook(new FileInputStream(file));
		XSSFSheet sheet = xwb.getSheetAt(0);

		System.out.println(String.format("准备解析:%s, 表格:%s",
				file.getAbsolutePath(), sheet.getSheetName()));

		XSSFRow dayRow = null; // 日期-周几
		XSSFRow timeRow = null;// 打卡时间

		String dayCell = null;
		String timeCell = null;

		// 遍历行(从0开始),从第3行开始
		for (int i = 9; i < sheet.getPhysicalNumberOfRows(); i = i + 2) {
			dayRow = sheet.getRow(i);
			timeRow = sheet.getRow(i + 1);

			// 忽略空行:真实
			if (dayRow.getFirstCellNum() < 0) {
				continue;
			}

			// 遍历行-列
			for (int j = dayRow.getFirstCellNum(); j < dayRow
					.getPhysicalNumberOfCells(); j++) {
				if (dayRow.getCell(j) == null) {
					continue;
				}
				dayCell = dayRow.getCell(j).toString();
				timeCell = timeRow.getCell(j).toString();
				if (StringUtil.isEmpty(dayCell)) {
					continue;
				}
				System.out.println(String.format(
						"解析 行=%d 列=%d\t>>\t日期=%s\t打卡=%s", i + 1, j,
						dayCell, timeCell));
			}
		}
	} catch (Exception e) {
		e.printStackTrace();
	}

}
 
开发者ID:bdceo,项目名称:bd-codes,代码行数:52,代码来源:KQParseer.java

示例8: readPatients

import org.apache.poi.xssf.usermodel.XSSFRow; //导入方法依赖的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

示例9: readCompounds

import org.apache.poi.xssf.usermodel.XSSFRow; //导入方法依赖的package包/类
protected static List<SESubstanceCompound> readCompounds(XSSFSheet xlSheet, Map<String,SESubstance> substances)
{
  String property,value,unit;
  SESubstance s;
  SESubstanceCompound compound=null;
  SESubstanceCompoundComponent component=null;		
  List<SESubstanceCompound> compounds = new ArrayList<SESubstanceCompound>();
  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++)
          compounds.add(new SESubstanceCompound());
      }
      property = row.getCell(0).getStringCellValue();
      if(property==null||property.isEmpty())
        continue;
      Log.info("Processing Patient Field : "+property);
      if(property.equals("Data Type"))
        continue;// Only one type at this point
      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);
        }
        compound=compounds.get(c-1);
        if(property.equals("Compound Name"))
        {
          compound.setName(value);
          continue;
        }
        if(property.equals("Component Name"))
        {
          s = substances.get(value);
          component = compound.getComponent(s);
          continue;
        }
        if(!setProperty(component,property,value,unit))
        {
          Log.error("Error setting property");
          break;
        }
      }
    }
  }
  catch(Exception ex)
  {
    Log.error("Error reading XLS",ex);
    return null;
  }
  return compounds;			
}
 
开发者ID:ScreenBasedSimulator,项目名称:ScreenBasedSimulator2,代码行数:82,代码来源:DataSetReader.java

示例10: readNutrition

import org.apache.poi.xssf.usermodel.XSSFRow; //导入方法依赖的package包/类
protected static Map<String,SENutrition> readNutrition(XSSFSheet xlSheet)
{
  String property,value,unit;
  SENutrition meal;
  Map<String,SENutrition> map = new HashMap<String,SENutrition>();		
  List<SENutrition> meals = new ArrayList<SENutrition>();
  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 environments we have
        for(int i=1;i<cells;i++)
          meals.add(new SENutrition());
      }
      property = row.getCell(0).getStringCellValue();
      if(property==null||property.isEmpty())
        continue;
      Log.info("Processing Nutrition 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);
        }
        meal = meals.get(c-1);
        if(property.equals("Name"))
        {
          map.put(cellValue, meal);
          continue;
        }					
        if(!setProperty(meal,property,value,unit))
        {
          Log.error("Error pulling"+property+" from "+cellValue);
          break;
        }
      }
    }
  }
  catch(Exception ex)
  {
    Log.error("Error reading XLS",ex);
    return null;
  }		
  return map;
}
 
开发者ID:ScreenBasedSimulator,项目名称:ScreenBasedSimulator2,代码行数:73,代码来源:DataSetReader.java


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