Пример #1
0
  @Override
  public Object getValueFromVariable(String reference, Integer lineNumber, String sheetName) {
    // Get the cell value
    // Get the variable value in the document
    Object cellValue = null;
    Cell varCell = null;
    Table sheet = null;
    if (reference != null && !reference.isEmpty()) {
      switch (scheme.getImportType()) {
        case ROW:
          Integer firstRow = scheme.getFirstRow();
          if (firstRow != null && firstRow >= 0 && scheme.getSheetName() != null) {
            sheet = doc.getTableByName(sheetName);
            if (sheet != null) {
              Row row = sheet.getRowByIndex(lineNumber);
              if (row != null) {
                Integer collNumber;
                try {
                  collNumber = getColumnFromReference(reference);
                } catch (NumberFormatException e) {
                  return null;
                }
                varCell = row.getCellByIndex(collNumber);
                if (varCell != null) {
                  cellValue = getCellValue(varCell);
                }
              }
            }
          }
          break;
        case SEVERAL:
          sheet = doc.getTableByName(sheetName);
          if (sheet != null) {
            varCell = sheet.getCellByPosition(reference);
            if (varCell != null) {
              cellValue = getCellValue(varCell);
            }
          }
          break;
        case UNIQUE:
          String[] references = reference.trim().split(ImportUtils.SHEET_CELL_SEPARATOR);
          if (references.length == 2) {

            sheet = doc.getTableByName(references[0]);
            if (sheet != null) {
              varCell = sheet.getCellByPosition(references[1]);
              if (varCell != null) {
                cellValue = getCellValue(varCell);
              }
            }
          }
          break;
        default:
          break;
      }
    }
    return cellValue;
  }
Пример #2
0
  @Override
  protected void getCorrespondances(List<ImportationSchemeModelDTO> schemeModelList)
      throws Throwable {
    for (ImportationSchemeModelDTO schemeModelDTO : schemeModelList) {
      // GetThe variable and the flexible element for the identification
      // key

      switch (scheme.getImportType()) {
        case ROW:
          Table sheetTable = null;
          if (scheme.getSheetName() != null && !scheme.getSheetName().isEmpty()) {
            sheetTable = doc.getTableByName(scheme.getSheetName());
          } else if (doc.getTableList().size() > 0) {
            sheetTable = doc.getTableList().get(0);
          }
          if (sheetTable != null) {
            int firstRow = 0;
            if (scheme.getFirstRow() != null) {
              firstRow = scheme.getFirstRow();
            }

            for (int i = firstRow; i < sheetTable.getRowCount(); i++) {
              getCorrespondancePerSheetOrLine(schemeModelDTO, i, scheme.getSheetName());
            }
          }
          break;
        case SEVERAL:
          for (Table sheet : doc.getTableList()) {
            getCorrespondancePerSheetOrLine(schemeModelDTO, null, sheet.getTableName());
          }
          break;
        case UNIQUE:
          getCorrespondancePerSheetOrLine(schemeModelDTO, null, null);
          break;
        default:
          break;
      }
    }
  }