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