// get first sheet
HSSFSheet sheet = wb.getSheetAt(0);
int sheetLastRowNumber = sheet.getLastRowNum();
for (int j = 1; j <= sheetLastRowNumber; j++) {
HSSFRow row = sheet.getRow(j);
if (row != null) {
// read productId from first column "sheet column index
// starts from 0"
HSSFCell cell2 = row.getCell(2);
cell2.setCellType(HSSFCell.CELL_TYPE_STRING);
String productId = cell2.getRichStringCellValue().toString();
// read QOH from ninth column
HSSFCell cell5 = row.getCell(5);
BigDecimal quantityOnHand = BigDecimal.ZERO;
if (cell5 != null && cell5.getCellType() == HSSFCell.CELL_TYPE_NUMERIC)
quantityOnHand = new BigDecimal(cell5.getNumericCellValue());
// check productId if null then skip creating inventory item
// too.
boolean productExists = ImportProductHelper.checkProductExists(productId, delegator);
if (productId != null && !productId.trim().equalsIgnoreCase("") && !productExists) {
products.add(ImportProductHelper.prepareProduct(productId));
if (quantityOnHand.compareTo(BigDecimal.ZERO) >= 0)
inventoryItems.add(ImportProductHelper.prepareInventoryItem(productId, quantityOnHand,
delegator.getNextSeqId("InventoryItem")));
else
inventoryItems.add(ImportProductHelper.prepareInventoryItem(productId, BigDecimal.ZERO, delegator
.getNextSeqId("InventoryItem")));
}
int rowNum = row.getRowNum() + 1;
if (row.toString() != null && !row.toString().trim().equalsIgnoreCase("") && productExists) {
Debug.logWarning("Row number " + rowNum + " not imported from " + item.getName(), module);
}
}
}
// create and store values in "Product" and "InventoryItem" entity