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