Package loxia.support.excel

Examples of loxia.support.excel.ReadStatus


    }
    return readStatus;
  }
 
  public ReadStatus readSheet(InputStream is, int sheetNo, Map<String, Object> beans) {
    ReadStatus readStatus = new DefaultReadStatus();
    readStatus.setStatus(ReadStatus.STATUS_SUCCESS);
    OgnlStack stack = new OgnlStack(beans);
    try {
      Workbook wb = WorkbookFactory.create(is);
      readSheet(wb,sheetNo,
          definition.getExcelSheets().iterator().next(),
          stack, readStatus);     
    } catch (IOException e) {
      readStatus.setStatus(ReadStatus.STATUS_READ_FILE_ERROR);     
    } catch (InvalidFormatException e) {
      readStatus.setStatus(ReadStatus.STATUS_READ_FILE_ERROR);
    }
    return readStatus;
  }
View Full Code Here


 
  private ExcelManipulatorDefinition definition;
  private boolean skipErrors = true;
 
  public ReadStatus readAll(InputStream is, Map<String, Object> beans) {
    ReadStatus readStatus = new DefaultReadStatus();
    readStatus.setStatus(ReadStatus.STATUS_SUCCESS);
    try {
      Workbook wb = WorkbookFactory.create(is);
      if(definition.getExcelSheets().size() == 0 ||
        wb.getNumberOfSheets() < definition.getExcelSheets().size()){
        readStatus.setStatus(ReadStatus.STATUS_SETTING_ERROR);
        readStatus.setMessage("No sheet definition found or Sheet Number in definition is more than number in file.");
      }else{
        OgnlStack stack = new OgnlStack(beans);
        for(int i=0; i< definition.getExcelSheets().size(); i++){
          readSheet(wb,i,
              definition.getExcelSheets().get(i), stack, readStatus);
        }
      }
    } catch (IOException e) {
      readStatus.setStatus(ReadStatus.STATUS_READ_FILE_ERROR);     
    } catch (InvalidFormatException e) {
      readStatus.setStatus(ReadStatus.STATUS_READ_FILE_ERROR);
    }
    return readStatus;
  }
View Full Code Here

    }
    return readStatus;
  }
 
  public ReadStatus readAllPerSheet(InputStream is, Map<String, Object> beans) {
    ReadStatus readStatus = new DefaultReadStatus();
    readStatus.setStatus(ReadStatus.STATUS_SUCCESS);
    try {
      Workbook wb = WorkbookFactory.create(is);
      if(definition.getExcelSheets().size() == 0){
        readStatus.setStatus(ReadStatus.STATUS_SETTING_ERROR);   
        readStatus.setMessage("No sheet definition found");
      }else{
        //Only first ExcelSheet Definition will be used
        ExcelSheet sheetDefinition = definition.getExcelSheets().iterator().next();
       
        Map<String,List<Object>> cacheMap = new HashMap<String, List<Object>>();
        for(String key: beans.keySet()){
          if(beans.get(key) != null)
            cacheMap.put(key, new ArrayList<Object>());
        }
        for(int i = 0; i< wb.getNumberOfSheets(); i++){
          Map<String, Object> clonedBeans = cloneMap(beans);
          readSheet(wb,i, sheetDefinition, new OgnlStack(clonedBeans), readStatus);
          for(String key: clonedBeans.keySet())
            cacheMap.get(key).add(clonedBeans.get(key));
        }
        for(String key: beans.keySet()){
          if(cacheMap.containsKey(key)){
            beans.put(key, cacheMap.get(key));
          }else{
            beans.put(key, null);
          }
        }
      }
    } catch (IOException e) {
      readStatus.setStatus(ReadStatus.STATUS_READ_FILE_ERROR);     
    } catch (InvalidFormatException e) {
      readStatus.setStatus(ReadStatus.STATUS_READ_FILE_ERROR);
    } catch (InstantiationException e) {     
      e.printStackTrace();
      readStatus.setStatus(ReadStatus.STATUS_SYSTEM_ERROR);
      readStatus.setMessage("New Instance Error");
    } catch (IllegalAccessException e) {
      e.printStackTrace();
      readStatus.setStatus(ReadStatus.STATUS_SYSTEM_ERROR);
      readStatus.setMessage("New Instance Error");
    }
    return readStatus;
  }
View Full Code Here

TOP

Related Classes of loxia.support.excel.ReadStatus

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.