本文整理匯總了Java中org.apache.poi.xssf.usermodel.XSSFWorkbook.getSheet方法的典型用法代碼示例。如果您正苦於以下問題:Java XSSFWorkbook.getSheet方法的具體用法?Java XSSFWorkbook.getSheet怎麽用?Java XSSFWorkbook.getSheet使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.poi.xssf.usermodel.XSSFWorkbook
的用法示例。
在下文中一共展示了XSSFWorkbook.getSheet方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: ExcelReader
import org.apache.poi.xssf.usermodel.XSSFWorkbook; //導入方法依賴的package包/類
public ExcelReader(String fileName, String sheetName) {
int rowNumber = 0;
int colNumber = 0;
try {
FileInputStream file = new FileInputStream(new File(fileName));
XSSFWorkbook workbook = new XSSFWorkbook(file);
XSSFSheet sheet;
Iterator<Row> rowIterator;
if (sheetName != null)
sheet = workbook.getSheet(sheetName);
else
sheet = workbook.getSheetAt(0);
Row row;
Cell cell;
Iterator<Cell> cellIterator;
if (sheet != null) {
rowIterator = sheet.iterator();
while (rowIterator.hasNext()) {
row = rowIterator.next();
cellIterator = row.cellIterator();
colNumber = 0;
while (cellIterator.hasNext()) {
cell = cellIterator.next();
if (rowNumber == 0)
celNum.put(cellVal(cell), colNumber);
else
celValues.put("["+ rowNumber +","+ colNumber +"]", cellVal(cell));
colNumber++;
}
rowNumber++;
}
}
rowCount = rowNumber - 1;
file.close();
}
catch (Exception x) {
x.printStackTrace();
}
}