com.agimatec.utility.fileimport.spreadsheet
Class SharedExcelRowReaderFactory

java.lang.Object
  extended by com.agimatec.utility.fileimport.spreadsheet.ExcelRowTokenizerFactory
      extended by com.agimatec.utility.fileimport.spreadsheet.SharedExcelRowReaderFactory
All Implemented Interfaces:
LineTokenizerFactory<ExcelRow,ExcelCell>

public class SharedExcelRowReaderFactory
extends ExcelRowTokenizerFactory

Description: ExcelRowTokenizerFactory that supports multiple imports on the same excel workbook. This is useful if multiple sheets should be imported by keeping the workbook instance open until it is explictly closed.

This class is not thread-safe!

Example 1:
     InputStream stream = new FileInputStream("workbook.xls");
     ExcelRowTokenizerFactory factory = new SharedExcelRowReaderFactory(stream, true);
     try {
        ImporterSpec spec1 = new ExcelImporterSpec("SheetName1") {
         protected void processRow(ExcelImportProcessor processor) throws ImporterException {
              processor.getString("column title 1"));
              processor.getBoolean("column title 2"));
           }
        };
        spec1.setLineTokenizerFactory(factory);
        Importer importer1 = new Importer(spec1);
        importer1.importFrom((InputStream) null);


        ImporterSpec spec2 = new ExcelImporterSpec("SheetName2") { ... };
        spec2.setLineTokenizerFactory(factory);
        Importer importer2 = new Importer(spec2);
        importer2.importFrom((InputStream) null);

     } finally {
      stream.close();
     }
 
or Example 2:
     InputStream stream = new FileInputStream("workbook.xls");
     ExcelRowTokenizerFactory factory = new SharedExcelRowReaderFactory();
     try {
        ImporterSpec spec1 = new ExcelImporterSpec("SheetName1") { ... };
        spec1.setLineTokenizerFactory(factory);
        Importer importer1 = new Importer(spec1);
        importer1.importFrom(stream);


        ImporterSpec spec2 = new ExcelImporterSpec("SheetName2") { ... };
        spec2.setLineTokenizerFactory(factory);
        Importer importer2 = new Importer(spec2);
        importer2.importFrom(stream);

     } finally {
      stream.close();
     }
 

User: roman.stumm
Date: 23.05.13
Time: 14:58
viaboxx GmbH, 2013

Since:
2.5.13

Constructor Summary
SharedExcelRowReaderFactory()
           
SharedExcelRowReaderFactory(InputStream stream, boolean keepOpen)
           
 
Method Summary
 LineReader<ExcelRow> createLineReader()
          initialize the lineReader.
 
Methods inherited from class com.agimatec.utility.fileimport.spreadsheet.ExcelRowTokenizerFactory
createTokenizer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SharedExcelRowReaderFactory

public SharedExcelRowReaderFactory()

SharedExcelRowReaderFactory

public SharedExcelRowReaderFactory(InputStream stream,
                                   boolean keepOpen)
Method Detail

createLineReader

public LineReader<ExcelRow> createLineReader()
Description copied from interface: LineTokenizerFactory
initialize the lineReader.

Specified by:
createLineReader in interface LineTokenizerFactory<ExcelRow,ExcelCell>
Overrides:
createLineReader in class ExcelRowTokenizerFactory


Copyright © 2008-2015. All Rights Reserved.