Example usage for org.apache.poi.hssf.usermodel HSSFCell getNumericCellValue

List of usage examples for org.apache.poi.hssf.usermodel HSSFCell getNumericCellValue

Introduction

In this page you can find the example usage for org.apache.poi.hssf.usermodel HSSFCell getNumericCellValue.

Prototype

public double getNumericCellValue() 

Source Link

Document

Get the value of the cell as a number.

Usage

From source file:org.logic2j.contrib.excel.ExcelReader.java

License:Open Source License

/**
 * @param sheet/*from www.ja v a2s . c o m*/
 * @param rowNumber Row index
 * @param theTargetClass
 * @return Null if row is empty or only containing nulls.
 */
private <T> List<T> readRow(Sheet sheet, final int rowNumber, Class<T> theTargetClass) {
    final HSSFRow row = ((HSSFSheet) sheet).getRow(rowNumber);
    if (row == null) {
        return null;
    }
    final int nbCols = row.getPhysicalNumberOfCells();
    final ArrayList<T> values = new ArrayList<T>();
    boolean hasSomeData = false;
    for (int c = 0; c < nbCols; c++) {
        final HSSFCell cell = row.getCell(c);
        Object value = null;
        if (cell != null) {
            switch (cell.getCellType()) {
            case Cell.CELL_TYPE_FORMULA:
                value = cell.getCellFormula();
                break;
            case Cell.CELL_TYPE_NUMERIC:
                value = cell.getNumericCellValue();
                break;
            case Cell.CELL_TYPE_STRING:
                value = cell.getStringCellValue();
                break;
            case Cell.CELL_TYPE_BLANK:
                break;
            default:
                throw new PrologNonSpecificError("Excel cell at row=" + rowNumber + ", column=" + c
                        + " of type " + cell.getCellType() + " not handled, value is " + value);
            }
        }
        value = mapCellValue(value);
        if (value != null) {
            hasSomeData = true;
        }
        final T cast = TypeUtils.safeCastOrNull("casting Excel cell", value, theTargetClass);
        values.add(cast);
    }
    if (!hasSomeData) {
        return null;
    }
    return values;
}

From source file:org.mcisb.excel.ExcelReader.java

License:Open Source License

/**
 * /*from   ww w.  j  a v  a  2 s. c  o  m*/
 * @param cell
 * @return Object
 */
private static Object getValue(HSSFCell cell) {
    if (cell == null) {
        return null;
    }

    switch (cell.getCellType()) {
    case Cell.CELL_TYPE_BOOLEAN: {
        return Boolean.valueOf(cell.getBooleanCellValue());
    }
    case Cell.CELL_TYPE_NUMERIC: {
        return Double.valueOf(cell.getNumericCellValue());
    }
    case Cell.CELL_TYPE_STRING: {
        return cell.getRichStringCellValue().getString().trim();
    }
    default: {
        return null;
    }
    }
}

From source file:org.mifos.application.importexport.xls.XlsClientsImporter.java

License:Open Source License

private String getCellStringValue(final HSSFRow row, final XlsImportConstants xlsImportConstant) {
    final HSSFCell cell = row.getCell(xlsImportConstant.value(), HSSFRow.RETURN_BLANK_AS_NULL);
    if (cell != null) {
        switch (cell.getCellType()) {
        case HSSFCell.CELL_TYPE_STRING:
            HSSFRichTextString richText = cell.getRichStringCellValue();
            return (richText == null) ? "" : richText.getString();
        case HSSFCell.CELL_TYPE_NUMERIC:
            int intVal = (int) cell.getNumericCellValue();
            return String.valueOf(intVal);
        default:/*from   w  w  w. ja  v a 2 s . c  om*/
            return "";
        }
    } else {
        return "";
    }
}

From source file:org.mifos.application.importexport.xls.XlsClientsImporter.java

License:Open Source License

private Integer getCellIntegerValue(final HSSFRow row, final XlsImportConstants xlsImportConstant) {
    final HSSFCell cell = row.getCell(xlsImportConstant.value(), HSSFRow.RETURN_BLANK_AS_NULL);
    if (cell == null) {
        return null;
    } else {/*  ww w  .  j ava 2s . c  o m*/
        Double val = cell.getNumericCellValue();
        return val.intValue();
    }
}

From source file:org.modeshape.sequencer.msoffice.excel.ExcelMetadataReader.java

License:Apache License

public static ExcelMetadata instance(InputStream stream) throws IOException {
    ExcelMetadata metadata = new ExcelMetadata();
    HSSFWorkbook wb = new HSSFWorkbook(new POIFSFileSystem(stream));

    List<ExcelSheetMetadata> sheets = new ArrayList<ExcelSheetMetadata>();

    for (int sheetInd = 0; sheetInd < wb.getNumberOfSheets(); sheetInd++) {
        ExcelSheetMetadata meta = new ExcelSheetMetadata();
        meta.setName(wb.getSheetName(sheetInd));
        sheets.add(meta);// ww w . j ava2 s  .c  o m

        HSSFSheet worksheet = wb.getSheetAt(sheetInd);
        int lastRowNum = worksheet.getLastRowNum();

        StringBuilder buff = new StringBuilder();
        for (int rowNum = worksheet.getFirstRowNum(); rowNum <= lastRowNum; rowNum++) {
            HSSFRow row = worksheet.getRow(rowNum);

            // Empty rows are returned as null
            if (row == null) {
                continue;
            }

            int lastCellNum = row.getLastCellNum();
            for (int cellNum = row.getFirstCellNum(); cellNum < lastCellNum; cellNum++) {
                HSSFCell cell = row.getCell(cellNum);

                // Undefined cells are returned as null
                if (cell == null) {
                    continue;
                }

                /*
                 * Builds a string of body content from all string, numeric,
                 * and formula values in the body of each worksheet.
                 * 
                 *  This code currently duplicates the POI 3.1 ExcelExtractor behavior of
                 *  combining the body text from all worksheets into a single string.
                 */
                switch (cell.getCellType()) {
                case HSSFCell.CELL_TYPE_STRING:
                    buff.append(cell.getRichStringCellValue().getString());
                    break;
                case HSSFCell.CELL_TYPE_NUMERIC:
                    buff.append(cell.getNumericCellValue());
                    break;
                case HSSFCell.CELL_TYPE_FORMULA:
                    buff.append(cell.getCellFormula());
                    break;
                }

                HSSFComment comment = cell.getCellComment();
                if (comment != null) {
                    // Filter out row delimiter characters from comment
                    String commentText = comment.getString().getString().replace(ROW_DELIMITER_CHAR, ' ');

                    buff.append(" [");
                    buff.append(commentText);
                    buff.append(" by ");
                    buff.append(comment.getAuthor());
                    buff.append(']');
                }

                if (cellNum < lastCellNum - 1) {
                    buff.append(CELL_DELIMITER_CHAR);
                } else {
                    buff.append(ROW_DELIMITER_CHAR);
                }
            }
        }
        meta.setText(buff.toString());
    }

    metadata.setSheets(sheets);
    metadata.setMetadata(wb.getSummaryInformation());
    return metadata;
}

From source file:org.nuxeo.ecm.core.convert.plugins.text.extractors.XL2TextConverter.java

License:Apache License

protected void appendTextFromCell(HSSFCell cell, StringBuffer sb) {
    String cellValue = null;//from w ww. j ava2 s  .c o m
    switch (cell.getCellType()) {
    case HSSFCell.CELL_TYPE_NUMERIC:
        cellValue = Double.toString(cell.getNumericCellValue()).trim();
        break;
    case HSSFCell.CELL_TYPE_STRING:
        cellValue = cell.getStringCellValue().trim().replaceAll("\n", " ");
        break;
    }

    if (cellValue != null && cellValue.length() > 0) {
        sb.append(cellValue);
    }
}

From source file:org.ofbiz.product.spreadsheetimport.ImportProductServices.java

License:Apache License

/**
 * This method is responsible to import spreadsheet data into "Product" and
 * "InventoryItem" entities into database. The method uses the
 * ImportProductHelper class to perform its operation. The method uses "Apache
 * POI" api for importing spreadsheet (xls files) data.
 *
 * Note : Create the spreadsheet directory in the ofbiz home folder and keep
 * your xls files in this folder only.//from  w w w.j a va  2 s  .c  o  m
 *
 * @param dctx the dispatch context
 * @param context the context
 * @return the result of the service execution
 */
public static Map<String, Object> productImportFromSpreadsheet(DispatchContext dctx,
        Map<String, ? extends Object> context) {
    Delegator delegator = dctx.getDelegator();
    Locale locale = (Locale) context.get("locale");
    // System.getProperty("user.dir") returns the path upto ofbiz home
    // directory
    String path = System.getProperty("user.dir") + "/spreadsheet";
    List<File> fileItems = FastList.newInstance();

    if (UtilValidate.isNotEmpty(path)) {
        File importDir = new File(path);
        if (importDir.isDirectory() && importDir.canRead()) {
            File[] files = importDir.listFiles();
            // loop for all the containing xls file in the spreadsheet
            // directory
            for (int i = 0; i < files.length; i++) {
                if (files[i].getName().toUpperCase().endsWith("XLS")) {
                    fileItems.add(files[i]);
                }
            }
        } else {
            return ServiceUtil.returnError(
                    UtilProperties.getMessage(resource, "ProductProductImportDirectoryNotFound", locale));
        }
    } else {
        return ServiceUtil.returnError(
                UtilProperties.getMessage(resource, "ProductProductImportPathNotSpecified", locale));
    }

    if (fileItems.size() < 1) {
        return ServiceUtil.returnError(
                UtilProperties.getMessage(resource, "ProductProductImportPathNoSpreadsheetExists", locale)
                        + path);
    }

    for (File item : fileItems) {
        // read all xls file and create workbook one by one.
        List<Map<String, Object>> products = FastList.newInstance();
        List<Map<String, Object>> inventoryItems = FastList.newInstance();
        POIFSFileSystem fs = null;
        HSSFWorkbook wb = null;
        try {
            fs = new POIFSFileSystem(new FileInputStream(item));
            wb = new HSSFWorkbook(fs);
        } catch (IOException e) {
            Debug.logError("Unable to read or create workbook from file", module);
            return ServiceUtil.returnError(UtilProperties.getMessage(resource,
                    "ProductProductImportCannotCreateWorkbookFromFile", locale));
        }

        // 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
        // in database
        for (int j = 0; j < products.size(); j++) {
            GenericValue productGV = delegator.makeValue("Product", products.get(j));
            GenericValue inventoryItemGV = delegator.makeValue("InventoryItem", inventoryItems.get(j));
            if (!ImportProductHelper.checkProductExists(productGV.getString("productId"), delegator)) {
                try {
                    delegator.create(productGV);
                    delegator.create(inventoryItemGV);
                } catch (GenericEntityException e) {
                    Debug.logError("Cannot store product", module);
                    return ServiceUtil.returnError(UtilProperties.getMessage(resource,
                            "ProductProductImportCannotStoreProduct", locale));
                }
            }
        }
        int uploadedProducts = products.size() + 1;
        if (products.size() > 0)
            Debug.logInfo("Uploaded " + uploadedProducts + " products from file " + item.getName(), module);
    }
    return ServiceUtil.returnSuccess();
}

From source file:org.ofbiz.tools.rest.FixOfcTools.java

/**
 * ?? //from  w ww.ja  va 2 s.c o  m
 * @param cell
 * @return
 */
public static String convertCell(HSSFCell cell) {
    String cellValue = "";
    if (cell == null) {
        return cellValue;
    }
    NumberFormat formater = NumberFormat.getInstance();
    formater.setGroupingUsed(false);
    switch (cell.getCellType()) {
    case HSSFCell.CELL_TYPE_NUMERIC:
        cellValue = formater.format(cell.getNumericCellValue());
        break;
    case HSSFCell.CELL_TYPE_STRING:
        cellValue = cell.getStringCellValue();
        break;
    case HSSFCell.CELL_TYPE_BLANK:
        cellValue = cell.getStringCellValue();
        break;
    case HSSFCell.CELL_TYPE_BOOLEAN:
        cellValue = Boolean.valueOf(cell.getBooleanCellValue()).toString();
        break;
    case HSSFCell.CELL_TYPE_ERROR:
        cellValue = String.valueOf(cell.getErrorCellValue());
        break;
    default:
        cellValue = "";
    }
    return cellValue.replaceAll("\\s", "").trim();
}

From source file:org.opencms.search.extractors.CmsExtractorMsExcel.java

License:Open Source License

/**
 * Extracts the text from the Excel table content.<p>
 * //from  www .j  av a  2  s .c o m
 * @param in the document input stream
 * @return the extracted text
 * @throws IOException if something goes wring
 */
protected String extractTableContent(InputStream in) throws IOException {

    HSSFWorkbook excelWb = new HSSFWorkbook(in);
    StringBuffer result = new StringBuffer(4096);

    int numberOfSheets = excelWb.getNumberOfSheets();

    for (int i = 0; i < numberOfSheets; i++) {
        HSSFSheet sheet = excelWb.getSheetAt(i);
        int numberOfRows = sheet.getPhysicalNumberOfRows();
        if (numberOfRows > 0) {

            if (CmsStringUtil.isNotEmpty(excelWb.getSheetName(i))) {
                // append sheet name to content
                if (i > 0) {
                    result.append("\n\n");
                }
                result.append(excelWb.getSheetName(i).trim());
                result.append(":\n\n");
            }

            Iterator rowIt = sheet.rowIterator();
            while (rowIt.hasNext()) {
                HSSFRow row = (HSSFRow) rowIt.next();
                if (row != null) {
                    boolean hasContent = false;
                    Iterator it = row.cellIterator();
                    while (it.hasNext()) {
                        HSSFCell cell = (HSSFCell) it.next();
                        String text = null;
                        try {
                            switch (cell.getCellType()) {
                            case HSSFCell.CELL_TYPE_BLANK:
                            case HSSFCell.CELL_TYPE_ERROR:
                                // ignore all blank or error cells
                                break;
                            case HSSFCell.CELL_TYPE_NUMERIC:
                                text = Double.toString(cell.getNumericCellValue());
                                break;
                            case HSSFCell.CELL_TYPE_BOOLEAN:
                                text = Boolean.toString(cell.getBooleanCellValue());
                                break;
                            case HSSFCell.CELL_TYPE_STRING:
                            default:
                                text = cell.getStringCellValue();
                                break;
                            }
                        } catch (Exception e) {
                            // ignore this cell
                        }
                        if ((text != null) && (text.length() != 0)) {
                            result.append(text.trim());
                            result.append(' ');
                            hasContent = true;
                        }
                    }
                    if (hasContent) {
                        // append a newline at the end of each row that has content                            
                        result.append('\n');
                    }
                }
            }
        }
    }

    return result.toString();
}

From source file:org.opencrx.kernel.portal.wizard.ImportPropertiesFromXlsController.java

License:BSD License

/**
 * Create or update property./*from  w ww  .j  av  a 2  s. c o  m*/
 * 
 * @param prodConfTypeSet
 * @param productConfigurationTypeSetName
 * @param productConfigurationTypeSetDescription
 * @param prodConfType
 * @param productConfigurationTypeName
 * @param productConfigurationTypeDescription
 * @param crxObject
 * @param propSet
 * @param propertySetName
 * @param propertySetDescription
 * @param propertyType
 * @param propertyName
 * @param propertyDescription
 * @param propertyValue
 * @param productSegment
 * @return
 */
public Property createOrUpdatePropertyOfPropertySet(ProductConfigurationTypeSet prodConfTypeSet,
        String productConfigurationTypeSetName, String productConfigurationTypeSetDescription,
        ProductConfigurationType prodConfType, String productConfigurationTypeName,
        String productConfigurationTypeDescription, CrxObject crxObject, PropertySet propSet,
        String propertySetName, String propertySetDescription, String propertyType, String propertyName,
        String propertyDescription, HSSFCell propertyValue,
        org.opencrx.kernel.product1.jmi1.Segment productSegment, ApplicationContext app) {
    PersistenceManager pm = JDOHelper.getPersistenceManager(productSegment);
    ProductConfigurationTypeSet productConfigurationTypeSet = prodConfTypeSet;
    ProductConfigurationType productConfigurationType = prodConfType;
    PropertySet propertySet = propSet;
    Property property = null;
    if (prodConfTypeSet != null || productConfigurationTypeSetName != null || prodConfType != null
            || productConfigurationTypeName != null) {
        if (productConfigurationTypeSet == null && productConfigurationTypeSetName != null
                && !productConfigurationTypeSetName.isEmpty()) {
            // try to locate productConfigurationTypeSet with respective name (or create new productConfigurationTypeSet)
            ProductConfigurationTypeSetQuery productConfigurationTypeSetQuery = (ProductConfigurationTypeSetQuery) pm
                    .newQuery(ProductConfigurationTypeSet.class);
            productConfigurationTypeSetQuery.name().equalTo(productConfigurationTypeSetName);
            try {
                pm.currentTransaction().begin();
                Iterator<ProductConfigurationTypeSet> pcts = productSegment
                        .getConfigurationTypeSet(productConfigurationTypeSetQuery).iterator();
                if (pcts.hasNext()) {
                    productConfigurationTypeSet = pcts.next();
                } else {
                    // create new ProductConfigurationTypeSet
                    productConfigurationTypeSet = pm.newInstance(ProductConfigurationTypeSet.class);
                    productConfigurationTypeSet.setName(productConfigurationTypeSetName);
                    productSegment.addConfigurationTypeSet(getUidAsString(), productConfigurationTypeSet);
                }
                productConfigurationTypeSet.setDescription(productConfigurationTypeSetDescription);
                pm.currentTransaction().commit();
                //System.out.println("productConfigurationTypeSet found/committed name=" + productConfigurationTypeSet.getName());
            } catch (Exception e) {
                new ServiceException(e).log();
                try {
                    pm.currentTransaction().rollback();
                } catch (Exception e1) {
                }
            }
        }
        if (productConfigurationTypeSet != null && productConfigurationType == null
                && productConfigurationTypeName != null && !productConfigurationTypeName.isEmpty()) {
            // try to locate productConfigurationType with respective name (or create new productConfigurationType)
            ProductConfigurationTypeQuery productConfigurationTypeFilter = (ProductConfigurationTypeQuery) pm
                    .newQuery(ProductConfigurationType.class);
            productConfigurationTypeFilter.name().equalTo(productConfigurationTypeName);
            try {
                pm.currentTransaction().begin();
                Iterator<ProductConfigurationType> pct = productConfigurationTypeSet
                        .getConfigurationType(productConfigurationTypeFilter).iterator();
                if (pct.hasNext()) {
                    productConfigurationType = (ProductConfigurationType) pct.next();
                } else {
                    // create new ProductConfigurationType
                    productConfigurationType = pm.newInstance(ProductConfigurationType.class);
                    productConfigurationType.setName(productConfigurationTypeName);
                    productConfigurationTypeSet.addConfigurationType(getUidAsString(),
                            productConfigurationType);
                }
                productConfigurationType.setDescription(productConfigurationTypeDescription);
                pm.currentTransaction().commit();
                //System.out.println("productConfigurationType found/committed name=" + productConfigurationTypeSet.getName());
            } catch (Exception e) {
                new ServiceException(e).log();
                try {
                    pm.currentTransaction().rollback();
                } catch (Exception e1) {
                }
            }
        }
    } else if (crxObject != null) {
        // try to locate PropertySet with same parent and name (or create new PropertySet)
        PropertySetQuery propertySetFilter = (PropertySetQuery) pm.newQuery(PropertySet.class);
        propertySetFilter.name().equalTo(propertySetName);
        try {
            pm.currentTransaction().begin();
            Iterator<PropertySet> ps = crxObject.getPropertySet(propertySetFilter).iterator();
            if (ps.hasNext()) {
                propertySet = (PropertySet) ps.next();
            } else {
                // create new PropertySet
                propertySet = pm.newInstance(PropertySet.class);
                propertySet.setName(propertySetName);
                crxObject.addPropertySet(getUidAsString(), propertySet);
            }
            propertySet.setDescription(propertySetDescription);
            pm.currentTransaction().commit();
        } catch (Exception e) {
            new ServiceException(e).log();
            try {
                pm.currentTransaction().rollback();
            } catch (Exception e1) {
            }
        }
    }
    if ((propertySet != null || productConfigurationType != null) && propertyType != null
            && !propertyType.isEmpty() && propertyName != null && !propertyName.isEmpty()) {
        // try to locate property with same parent and name (or create new property)
        PropertyQuery propertyQuery = (PropertyQuery) pm.newQuery(Property.class);
        propertyQuery.name().equalTo(propertyName);
        Iterator<Property> p = null;
        if (productConfigurationType != null) {
            p = productConfigurationType.getProperty(propertyQuery).iterator();
        } else {
            p = propertySet.getProperty(propertyQuery).iterator();
        }
        try {
            while (p.hasNext() && property == null) {
                property = p.next();
                if (!((property instanceof StringProperty) && (propertyType.equals(PROPERTY_DTYPE_STRING))
                        || (property instanceof DecimalProperty)
                                && (propertyType.equals(PROPERTY_DTYPE_DECIMAL))
                        || (property instanceof IntegerProperty)
                                && (propertyType.equals(PROPERTY_DTYPE_INTEGER))
                        || (property instanceof BooleanProperty)
                                && (propertyType.equals(PROPERTY_DTYPE_BOOLEAN))
                        || (property instanceof DateTimeProperty)
                                && (propertyType.equals(PROPERTY_DTYPE_DATETIME))
                        || (property instanceof DateProperty) && (propertyType.equals(PROPERTY_DTYPE_DATE))
                        || (property instanceof ReferenceProperty)
                                && (propertyType.equals(PROPERTY_DTYPE_REFERENCE))
                        || (property instanceof UriProperty) && (propertyType.equals(PROPERTY_DTYPE_URI)))) {
                    property = null;
                }
            }
            pm.currentTransaction().begin();
            if (propertyType.equals(PROPERTY_DTYPE_STRING)) {
                if (property == null) {
                    // create new StringProperty
                    property = pm.newInstance(StringProperty.class);
                    property.setName(propertyName);
                    if (productConfigurationType != null) {
                        productConfigurationType.addProperty(getUidAsString(), property);
                    } else {
                        propertySet.addProperty(getUidAsString(), property);
                    }
                }
                if (property != null) {
                    property.setDescription(propertyDescription);
                    ((StringProperty) property).setStringValue(
                            propertyValue != null ? propertyValue.getStringCellValue().trim() : null);
                }
            } else if (propertyType.equals(PROPERTY_DTYPE_DECIMAL)) {
                if (property == null) {
                    // create new DecimalProperty
                    property = pm.newInstance(DecimalProperty.class);
                    property.setName(propertyName);
                    if (productConfigurationType != null) {
                        productConfigurationType.addProperty(getUidAsString(), property);
                    } else {
                        propertySet.addProperty(getUidAsString(), property);
                    }
                }
                if (property != null) {
                    property.setDescription(propertyDescription);
                    ((DecimalProperty) property).setDecimalValue(
                            propertyValue != null ? new BigDecimal(propertyValue.getNumericCellValue()) : null);
                }
            } else if (propertyType.equals(PROPERTY_DTYPE_INTEGER)) {
                if (property == null) {
                    // create new IntegerProperty
                    property = pm.newInstance(IntegerProperty.class);
                    property.setName(propertyName);
                    if (productConfigurationType != null) {
                        productConfigurationType.addProperty(getUidAsString(), property);
                    } else {
                        propertySet.addProperty(getUidAsString(), property);
                    }
                }
                if (property != null) {
                    property.setDescription(propertyDescription);
                    ((IntegerProperty) property).setIntegerValue(propertyValue != null
                            ? (new BigDecimal(propertyValue.getNumericCellValue())).intValue()
                            : null);
                }
            } else if (propertyType.equals(PROPERTY_DTYPE_BOOLEAN)) {
                if (property == null) {
                    // create new BooleanProperty
                    property = pm.newInstance(BooleanProperty.class);
                    property.setName(propertyName);
                    if (productConfigurationType != null) {
                        productConfigurationType.addProperty(getUidAsString(), property);
                    } else {
                        propertySet.addProperty(getUidAsString(), property);
                    }
                }
                if (property != null) {
                    property.setDescription(propertyDescription);
                    ((BooleanProperty) property).setBooleanValue(
                            propertyValue != null ? propertyValue.getBooleanCellValue() : null);
                }
            } else if (propertyType.equals(PROPERTY_DTYPE_DATETIME)) {
                if (property == null) {
                    // create new DateTimeProperty
                    property = pm.newInstance(DateTimeProperty.class);
                    property.setName(propertyName);
                    if (productConfigurationType != null) {
                        productConfigurationType.addProperty(getUidAsString(), property);
                    } else {
                        propertySet.addProperty(getUidAsString(), property);
                    }
                }
                if (property != null) {
                    property.setDescription(propertyDescription);
                    ((DateTimeProperty) property).setDateTimeValue(propertyValue != null
                            ? HSSFDateUtil.getJavaDate(propertyValue.getNumericCellValue())
                            : null);
                }
            } else if (propertyType.equals(PROPERTY_DTYPE_DATE)) {
                if (property == null) {
                    // create new DateTimeProperty
                    property = pm.newInstance(DateProperty.class);
                    property.setName(propertyName);
                    if (productConfigurationType != null) {
                        productConfigurationType.addProperty(getUidAsString(), property);
                    } else {
                        propertySet.addProperty(getUidAsString(), property);
                    }
                }
                if (property != null) {
                    property.setDescription(propertyDescription);
                    if (propertyValue != null) {
                        TimeZone timezone = TimeZone.getTimeZone(app.getCurrentTimeZone());
                        SimpleDateFormat dateonlyf = new SimpleDateFormat("yyyyMMdd", app.getCurrentLocale());
                        dateonlyf.setTimeZone(timezone);
                        String date = dateonlyf
                                .format(HSSFDateUtil.getJavaDate(propertyValue.getNumericCellValue()))
                                .substring(0, 8);
                        XMLGregorianCalendar cal = org.w3c.spi2.Datatypes.create(XMLGregorianCalendar.class,
                                date);
                        ((DateProperty) property).setDateValue(cal);
                    } else {
                        ((DateProperty) property).setDateValue(null);
                    }
                }
            } else if (propertyType.equals(PROPERTY_DTYPE_REFERENCE)) {
                if (property == null) {
                    // create new ReferenceProperty
                    property = pm.newInstance(ReferenceProperty.class);
                    property.setName(propertyName);
                    if (productConfigurationType != null) {
                        productConfigurationType.addProperty(getUidAsString(), property);
                    } else {
                        propertySet.addProperty(getUidAsString(), property);
                    }
                }
                if (property != null) {
                    property.setDescription(propertyDescription);
                    BasicObject basicObject = null;
                    if (propertyValue != null) {
                        try {
                            String xri = propertyValue.getStringCellValue().trim();
                            basicObject = (BasicObject) pm.getObjectById(new Path(xri));
                        } catch (Exception e) {
                        }
                    }
                    ((ReferenceProperty) property).setReferenceValue(basicObject);
                }
            } else if (propertyType.equals(PROPERTY_DTYPE_URI)) {
                if (property == null) {
                    // create new UriProperty
                    property = pm.newInstance(UriProperty.class);
                    property.setName(propertyName);
                    if (productConfigurationType != null) {
                        productConfigurationType.addProperty(getUidAsString(), property);
                    } else {
                        propertySet.addProperty(getUidAsString(), property);
                    }
                }
                if (property != null) {
                    property.setDescription(propertyDescription);
                    ((UriProperty) property).setUriValue(
                            propertyValue != null ? propertyValue.getStringCellValue().trim() : null);
                }
            }
            pm.currentTransaction().commit();
        } catch (Exception e) {
            new ServiceException(e).log();
            try {
                pm.currentTransaction().rollback();
            } catch (Exception e1) {
            }
        }
    }
    return property;
}