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; }
public boolean hasNext() { return cache.hasData(); }
public List<String> next() { return cache.readData(); }
public ExcelReader() { cache = DataBufferCache.getInstance(); futureTask = new FutureTask(this); task = new Thread(futureTask); }