import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
private List<BookmarkRequirementInfo> getBookmarkRequirementInfo(String filePath) {
List<BookmarkRequirementInfo> productBookmarkInfoList = null;
try {
File file = new File(filePath);
OPCPackage opcPackage = OPCPackage.open(file);
XSSFWorkbook xssfWorkbook = new XSSFWorkbook(opcPackage);
XSSFSheet xssfSheet = xssfWorkbook.getSheetAt(0);
int totalRows = xssfSheet.getPhysicalNumberOfRows();
productBookmarkInfoList = new ArrayList<BookmarkRequirementInfo>(totalRows);
for (int rownum = 1; rownum < totalRows; rownum++) {
XSSFRow row = xssfSheet.getRow(rownum);
XSSFCell idCell = row.getCell(0);
XSSFCell productNameCell = row.getCell(4);
XSSFCell quantityCell = row.getCell(6);
String formattedId = idCell.getStringCellValue();
String productName = productNameCell.getStringCellValue();
int quantity = (int)quantityCell.getNumericCellValue();
BookmarkRequirementInfo productBookmarkInfo = new BookmarkRequirementInfo(productName, formattedId, quantity);
productBookmarkInfoList.add(productBookmarkInfo);
}
} catch (Exception e) {
logger.log(Level.SEVERE, e.getMessage(), e);
}
return productBookmarkInfoList;
}
转载于:https://blog.51cto.com/keeplearning/1227036