Example usage for org.apache.poi.hssf.extractor ExcelExtractor setFormulasNotResults

List of usage examples for org.apache.poi.hssf.extractor ExcelExtractor setFormulasNotResults

Introduction

In this page you can find the example usage for org.apache.poi.hssf.extractor ExcelExtractor setFormulasNotResults.

Prototype

@Override
    public void setFormulasNotResults(boolean formulasNotResults) 

Source Link

Usage

From source file:com.bayareasoftware.chartengine.ds.util.ExcelDump.java

License:Apache License

private static void runNew(String fileName) throws Exception {
    InputStream inp = new FileInputStream(fileName);
    HSSFWorkbook wb = new HSSFWorkbook(new POIFSFileSystem(inp));
    ExcelExtractor xt = new ExcelExtractor(wb);

    xt.setFormulasNotResults(false);
    xt.setIncludeBlankCells(true);/*  ww w  . j  ava 2  s  . c o  m*/
    xt.setIncludeSheetNames(false);
    String text = xt.getText();
    String[] lines = StringUtil.splitCompletely(text, '\n');
    for (int i = 0; i < lines.length; i++) {
        System.out.println((i + 1) + ") " + lines[i]);
    }
    System.out.println("XLS: \n" + text);
}

From source file:com.frameworkset.platform.cms.searchmanager.extractors.CmsExtractorMsExcel.java

License:Open Source License

/** 
 * ?excel2003 /*from  w  w w .j  ava 2s. co  m*/
 * @param path 
 * @return 
 * @throws IOException 
 */
public String readExcel(InputStream in) throws IOException {

    String content = null;
    try {

        HSSFWorkbook wb = new HSSFWorkbook(in);
        ExcelExtractor extractor = new ExcelExtractor(wb);
        extractor.setFormulasNotResults(true);
        extractor.setIncludeSheetNames(false);
        content = extractor.getText();
        this.m_documentSummary = extractor.getDocSummaryInformation();
        this.m_summary = extractor.getSummaryInformation();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    return content;
}

From source file:it.smartcommunitylab.riciclo.app.importer.converter.DataImporter.java

License:Apache License

private Rifiuti readExcel(InputStream inp) throws Exception {
    HSSFWorkbook wb = new HSSFWorkbook(new POIFSFileSystem(inp));
    ExcelExtractor extractor = new ExcelExtractor(wb);

    extractor.setFormulasNotResults(true);
    extractor.setIncludeSheetNames(false);

    Rifiuti rifiuti = new Rifiuti();

    Set<String> sheetNames = Sets.newHashSet();
    for (int i = 0; i < wb.getNumberOfSheets(); i++) {
        sheetNames.add(wb.getSheetAt(i).getSheetName());
    }/*from  www. ja va  2  s  .  c  o m*/

    Set missingExpected = Sets.newHashSet(expectedSheets);
    missingExpected.removeAll(sheetNames);

    Set additionalFound = Sets.newHashSet(sheetNames);
    additionalFound.removeAll(expectedSheets);

    if (!missingExpected.isEmpty() || !additionalFound.isEmpty()) {
        throw new ImportError(Lists.newArrayList("Missing sheet(s) expected: " + missingExpected,
                "Additional sheet(s) found: " + additionalFound));
    }

    for (int i = 0; i < wb.getNumberOfSheets(); i++) {
        Sheet sheet = wb.getSheetAt(i);
        Thread.sleep(500);
        //         System.out.println(sheet.getSheetName());
        //         if (sheet.getRow(0).getLastCellNum() == 1 && !oneColumnAsMany.contains(sheet.getSheetName())) {
        //         } else {
        {
            System.err.println(">" + sheet.getSheetName());
            List<Map<String, String>> result = getSheetMap(sheet);
            mapMap(rifiuti, sheet.getSheetName(), result);
        }
    }

    completePuntiRaccolta(rifiuti);

    return rifiuti;
}

From source file:it.smartcommunitylab.ungiorno.importer.Importer.java

License:Apache License

private HSSFWorkbook readFile(InputStream inp, Set<String> expected) throws IOException, ImportError {

    HSSFWorkbook wb = new HSSFWorkbook(new POIFSFileSystem(inp));
    ExcelExtractor extractor = new ExcelExtractor(wb);

    extractor.setFormulasNotResults(true);
    extractor.setIncludeSheetNames(false);

    Set<String> sheetNames = Sets.newHashSet();
    for (int i = 0; i < wb.getNumberOfSheets(); i++) {
        sheetNames.add(wb.getSheetAt(i).getSheetName());
    }/*  w  w  w  . ja  va  2 s .com*/

    Set<String> missingExpected = new HashSet<String>(expected);
    missingExpected.removeAll(sheetNames);

    Set<String> additionalFound = Sets.newHashSet(sheetNames);
    additionalFound.removeAll(expected);

    if (!missingExpected.isEmpty() || !additionalFound.isEmpty()) {
        System.err.println("Missing sheet(s) expected: " + missingExpected + " - Additional sheet(s) found: "
                + additionalFound);
        throw new ImportError(Lists.newArrayList("Missing sheet(s) expected: " + missingExpected,
                "Additional sheet(s) found: " + additionalFound));
    }
    return wb;
}

From source file:net.sourceforge.docfetcher.model.parse.MSExcelParser.java

License:Open Source License

protected String renderText(File file, String filename) throws ParseException {
    InputStream in = null;/* w w  w .java  2s . c om*/
    try {
        in = new FileInputStream(file);
        ExcelExtractor extractor = null;
        try {
            POIFSFileSystem fs = new POIFSFileSystem(in);
            extractor = new ExcelExtractor(fs);
            extractor.setFormulasNotResults(ProgramConf.Bool.IndexExcelFormulas.get());
            return extractor.getText();
        } catch (OldExcelFormatException e) {
            /*
             * POI doesn't support the old Excel 5.0/7.0 (BIFF5) format,
             * only the BIFF8 format from Excel 97/2000/XP/2003. Thus, we
             * fall back to another Excel library.
             */
            Closeables.closeQuietly(in);
            return extractWithJexcelAPI(file);
        } finally {
            Closeables.closeQuietly(extractor);
        }
    } catch (IOException e) {
        throw new ParseException(e);
    } catch (RuntimeException e) {
        // POI can throw NullPointerExceptions on some odd Excel files
        throw new ParseException(e);
    } finally {
        Closeables.closeQuietly(in);
    }
}

From source file:net.sourceforge.docfetcher.parse.MSExcelParser.java

License:Open Source License

public String renderText(File file) throws ParseException {
    InputStream in = null;//from  ww w  .  j  a v  a 2 s.  co  m
    try {
        in = new FileInputStream(file);
        ExcelExtractor extractor = null;
        try {
            POIFSFileSystem fs = new POIFSFileSystem(in);
            extractor = new ExcelExtractor(fs);
        } catch (OldExcelFormatException e) {
            /*
             * POI doesn't support the old Excel 5.0/7.0 (BIFF5) format,
             * only the BIFF8 format from Excel 97/2000/XP/2003. Thus, we
             * fall back to another Excel library.
             */
            in.close();
            return extractWithJexcelAPI(file);
        } catch (Exception e) {
            // This can happen if the file has the "xls" extension, but is not an Excel document
            throw new ParseException(file, Msg.file_corrupted.value());
        } finally {
            in.close();
        }
        extractor.setFormulasNotResults(true);
        return extractor.getText();
    } catch (FileNotFoundException e) {
        throw new ParseException(file, Msg.file_not_found.value());
    } catch (IOException e) {
        throw new ParseException(file, Msg.file_not_readable.value());
    }
}

From source file:net.sourceforge.vaticanfetcher.model.parse.MSExcelParser.java

License:Open Source License

protected String renderText(File file, String filename) throws ParseException {
    InputStream in = null;//  w  w  w.j a  v a  2 s  .c o m
    try {
        in = new FileInputStream(file);
        ExcelExtractor extractor = null;
        try {
            POIFSFileSystem fs = new POIFSFileSystem(in);
            extractor = new ExcelExtractor(fs);
        } catch (OldExcelFormatException e) {
            /*
             * POI doesn't support the old Excel 5.0/7.0 (BIFF5) format,
             * only the BIFF8 format from Excel 97/2000/XP/2003. Thus, we
             * fall back to another Excel library.
             */
            Closeables.closeQuietly(in);
            return extractWithJexcelAPI(file);
        }
        extractor.setFormulasNotResults(ProgramConf.Bool.IndexExcelFormulas.get());
        return extractor.getText();
    } catch (IOException e) {
        throw new ParseException(e);
    } catch (RuntimeException e) {
        // POI can throw NullPointerExceptions on some odd Excel files
        throw new ParseException(e);
    } finally {
        Closeables.closeQuietly(in);
    }
}