本文整理汇总了Java中org.apache.poi.ss.usermodel.Row.getRowNum方法的典型用法代码示例。如果您正苦于以下问题:Java Row.getRowNum方法的具体用法?Java Row.getRowNum怎么用?Java Row.getRowNum使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.poi.ss.usermodel.Row
的用法示例。
在下文中一共展示了Row.getRowNum方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getStartRow
import org.apache.poi.ss.usermodel.Row; //导入方法依赖的package包/类
private int getStartRow(Sheet sheet) throws SheetParsingException {
Iterator<Row> rit = sheet.iterator();
while (rit.hasNext()) {
Row row = rit.next();
Cell cell = row.getCell(0);
if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
/*
* In my case first column is Sr.no. and Data starts where sr. no is 1 ,so this
* is start row index
*/
if (cell.getNumericCellValue() == 1.0)
return row.getRowNum();
}
}
throw new SheetParsingException("no start index found for data");
}
示例2: writeRow
import org.apache.poi.ss.usermodel.Row; //导入方法依赖的package包/类
private void writeRow(final Row row, final XMLStreamWriter out, final Map<String, String> columns) {
try {
int rowIndex = row.getRowNum();
out.writeStartElement("row");
final String rowNum = String.valueOf(rowIndex);
out.writeAttribute("row", rowNum);
int count = 0;
Iterator<Cell> cellIterator = row.iterator();
while (cellIterator.hasNext()) {
Cell cell = cellIterator.next();
int columnIndex = cell.getColumnIndex();
if (this.exportEmptyCells) {
while (count < columnIndex) {
this.writeAnyCell(rowIndex, count, null, out, columns);
count++;
}
}
this.writeCell(cell, out, columns);
count++;
}
out.writeEndElement();
} catch (XMLStreamException e) {
e.printStackTrace();
}
}
示例3: parseRow
import org.apache.poi.ss.usermodel.Row; //导入方法依赖的package包/类
public void parseRow(Row row, SheetFormat sf, Object obj) throws RowParsingException {
Iterator<Cell> cellItr = row.iterator();
cellItr.next(); // for sr. no. column skip
for (ColumnFormat field : sf.getColumns())
if (cellItr.hasNext()) {
Cell cell = cellItr.next();
try {
set(obj, field.getName(), getValue(cell, field.getType()));
} catch (CellParsingException e) {
throw new RowParsingException(e.getMessage() + " , at row " + row.getRowNum());
}
}
}
示例4: convertWithConstructor
import org.apache.poi.ss.usermodel.Row; //导入方法依赖的package包/类
public static <T> List<T> convertWithConstructor(Iterator<Row> rows, Class<T> clazz, boolean hasHeader) {
List<T> dataList = Lists.newArrayList();
while (rows.hasNext()) {
Row row = rows.next();
if (hasHeader && row.getRowNum() < 1) {
continue;
}
try {
dataList.add(convert(row, clazz));
} catch (Exception e) {
throw new RuntimeException(String.format(" convertWithConstructor has error: message=%s", e.getMessage()));
}
}
return dataList;
}
示例5: loadFromSpreadsheet
import org.apache.poi.ss.usermodel.Row; //导入方法依赖的package包/类
private Collection loadFromSpreadsheet(final InputStream excelFile)throws IOException {
HSSFWorkbook workbook = new HSSFWorkbook(excelFile);
data = new ArrayList();
Sheet sheet = workbook.getSheetAt(0);
int numberOfColumns = countNonEmptyColumns(sheet);
List rows = new ArrayList();
List rowData = new ArrayList();
for (Row row : sheet) {
if (isEmpty(row)) {
break;
} else if(row.getRowNum() == 0 ) {
//do nothing
}else {
rowData.clear();
for (int column = 0; column < numberOfColumns; column++) {
Cell cell = row.getCell(column);
rowData.add(objectFrom(workbook, cell));
}
rows.add(rowData.toArray());
}
}
return rows;
}
示例6: computeIDCG_nDCG
import org.apache.poi.ss.usermodel.Row; //导入方法依赖的package包/类
/**
* generates the IDCG and nDCG
* @param prec_recall
* @param rowPR
* @param ratings
*/
private static void computeIDCG_nDCG(Sheet prec_recall, Row rowPR, ArrayList<Rating> ratings) {
CellReference cellRefDCGFirst = new CellReference(1, COLUMN_DCG);
CellReference cellRefDCGLast = new CellReference(50, COLUMN_DCG);
Cell cellPR = rowPR.createCell(COLUMN_DCG);
cellPR.setCellFormula("SUM("+cellRefDCGFirst.formatAsString()
+":"+cellRefDCGLast.formatAsString()+")");
//Get the List of ratings and sort them by relevance (rating)
Collections.sort(ratings, new Comparator<Rating>() {
@Override
public int compare(Rating o1, Rating o2) {
return Float.compare(o2.rating, o1.rating);
}
});
//go through the sheet again and add the ideal rank
int current_position = 1;
for (Iterator<Rating> it = ratings.iterator(); it.hasNext();) {
int rank = it.next().getCompetenceRank();
Row rowPR2 = prec_recall.getRow(rank);
//CellReference cellRef = new CellReference(row.getRowNum(), cell.getColumnIndex());
cellPR = rowPR2.createCell(COLUMN_IDEAL_RANK, Cell.CELL_TYPE_NUMERIC);
cellPR.setCellValue(current_position);
CellReference cellRefNovice = new CellReference(rowPR2.getRowNum(), COLUMN_NOVICE);
CellReference cellRefIrrelevant = new CellReference(rowPR2.getRowNum(), COLUMN_IRRELEVANT);
CellReference cellRefNoviceWeight = new CellReference(0, COLUMN_NOVICE);
CellReference cellRefIrrelevantWeight = new CellReference(0, COLUMN_IRRELEVANT);
CellReference cellRefIdealRank = new CellReference(rowPR2.getRowNum(), COLUMN_IDEAL_RANK);
cellPR = rowPR2.createCell(COLUMN_IDCG, Cell.CELL_TYPE_NUMERIC);
//LOG 1 is not defined
if(current_position==1)
cellPR.setCellFormula("SUMIF("+cellRefNovice.formatAsString()+":"+cellRefIrrelevant.formatAsString()+",1,"+cellRefNoviceWeight.formatAsString()+":"+cellRefIrrelevantWeight.formatAsString()+")");
else
cellPR.setCellFormula("SUMIF("+cellRefNovice.formatAsString()+":"+cellRefIrrelevant.formatAsString()+",1,"+cellRefNoviceWeight.formatAsString()+":"+cellRefIrrelevantWeight.formatAsString()+")/LOG("+cellRefIdealRank.formatAsString()+",2)");
current_position++;
}
//sum of iDCG
cellPR = rowPR.createCell(COLUMN_IDCG, Cell.CELL_TYPE_NUMERIC);
CellReference cellRefIDCGFirst = new CellReference(1, COLUMN_IDCG);
CellReference cellRefIDCGLast = new CellReference(50, COLUMN_IDCG);
cellPR.setCellFormula("SUM("+cellRefIDCGFirst.formatAsString()+":"+cellRefIDCGLast.formatAsString()+")");
//nDCG
CellReference cellRefDCG = new CellReference(rowPR.getRowNum(), COLUMN_DCG);
CellReference cellRefIDCG = new CellReference(rowPR.getRowNum(), COLUMN_IDCG);
cellPR = rowPR.createCell(COLUMN_nDCG, Cell.CELL_TYPE_NUMERIC);
cellPR.setCellFormula("SUM("+cellRefDCG.formatAsString()+"/"+cellRefIDCG.formatAsString()+")");
}