Exemplo n.º 1
0
  public Object call() throws Exception {
    OPCPackage pkg = null;
    try {
      if (fileURL != null) {
        pkg = OPCPackage.open(fileURL);
      } else {
        pkg = PackageHelper.open(is);
      }
      XSSFReader r = new XSSFReader(pkg);

      StylesTable styles = r.getStylesTable();
      ReadOnlySharedStringsTable strings = new ReadOnlySharedStringsTable(pkg);
      sheetContentsHandler = new DefaultTalendSheetContentsHandler(cache);
      DataFormatter formatter = new DataFormatter();
      boolean formulasNotResults = false;

      XMLReader parser = XMLReaderFactory.createXMLReader();
      ContentHandler handler =
          new TalendXSSFSheetXMLHandler(
              styles, strings, sheetContentsHandler, formatter, formulasNotResults);
      parser.setContentHandler(handler);

      XSSFReader.SheetIterator sheets = (XSSFReader.SheetIterator) r.getSheetsData();
      List<InputStream> iss = new ArrayList<InputStream>();
      while (sheets.hasNext()) {
        InputStream sheet = sheets.next();
        String sheetName = sheets.getSheetName();

        boolean match = false;

        for (int i = 0; i < sheetNames.size(); i++) {
          if ((asRegexs.get(i) && sheetName.matches(sheetNames.get(i)))
              || (!asRegexs.get(i) && sheetName.equals(sheetNames.get(i)))) {
            match = true;
            iss.add(sheet);
            break;
          }
        }

        if (!match) {
          sheet.close();
        }
      }

      if (iss.size() < 1) {
        throw new RuntimeException("No match sheets");
      }

      for (InputStream is : iss) {
        try {
          InputSource sheetSource = new InputSource(is);
          sheetSource.setEncoding(charset);
          parser.parse(sheetSource);
        } finally {
          is.close();
        }
      }

    } finally {
      if (pkg != null) {
        pkg.revert();
      }
      cache.notifyErrorOccurred();
    }
    return null;
  }
Exemplo n.º 2
0
 public boolean hasNext() {
   return cache.hasData();
 }
Exemplo n.º 3
0
 public List<String> next() {
   return cache.readData();
 }
Exemplo n.º 4
0
 public ExcelReader() {
   cache = DataBufferCache.getInstance();
   futureTask = new FutureTask(this);
   task = new Thread(futureTask);
 }