org.apache.poi.hssf.eventusermodel.HSSFRequest Java Examples

The following examples show how to use org.apache.poi.hssf.eventusermodel.HSSFRequest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Excel2003Reader.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 遍历excel下所有的sheet
 * @param fileKey 
 * @throws IOException
 */
public void process( String fileName ) throws IOException {
	
	this.fs = new POIFSFileSystem( new FileInputStream(fileName) );
	MissingRecordAwareHSSFListener listener = new MissingRecordAwareHSSFListener( this);
	formatListener = new FormatTrackingHSSFListener(listener);
	HSSFEventFactory factory = new HSSFEventFactory();
	HSSFRequest request = new HSSFRequest();
	if ( outputFormulaValues ) {
		request.addListenerForAllRecords( formatListener );
	} else {
		workbookBuildingListener = new SheetRecordCollectingListener( formatListener);
		request.addListenerForAllRecords(workbookBuildingListener);
	}
	factory.processWorkbookEvents(request, fs);
	//数据读取完成
	
}
 
Example #2
Source File: XLS2CSV.java    From jeesuite-libs with Apache License 2.0 6 votes vote down vote up
/**
 * Initiates the processing of the XLS file to CSV
 */
public List<String> process() throws IOException {
	MissingRecordAwareHSSFListener listener = new MissingRecordAwareHSSFListener(this);
	formatListener = new FormatTrackingHSSFListener(listener);

	HSSFEventFactory factory = new HSSFEventFactory();
	HSSFRequest request = new HSSFRequest();

	if(outputFormulaValues) {
		request.addListenerForAllRecords(formatListener);
	} else {
		workbookBuildingListener = new SheetRecordCollectingListener(formatListener);
		request.addListenerForAllRecords(workbookBuildingListener);
	}

	factory.processWorkbookEvents(request, fs);
	
	return results;
}
 
Example #3
Source File: XLS2CSV.java    From bdf3 with Apache License 2.0 6 votes vote down vote up
/**
 * Initiates the processing of the XLS file to CSV
 */
public void process() throws IOException {
    MissingRecordAwareHSSFListener listener = new MissingRecordAwareHSSFListener(
            this);
    formatListener = new FormatTrackingHSSFListener(listener);

    HSSFEventFactory factory = new HSSFEventFactory();
    HSSFRequest request = new HSSFRequest();

    if (outputFormulaValues) {
        request.addListenerForAllRecords(formatListener);
    } else {
        workbookBuildingListener = new SheetRecordCollectingListener(
                formatListener);
        request.addListenerForAllRecords(workbookBuildingListener);
    }

    factory.processWorkbookEvents(request, fs);
    close();
}
 
Example #4
Source File: XLS2CSV.java    From azeroth with Apache License 2.0 6 votes vote down vote up
/**
 * Initiates the processing of the XLS file to CSV
 */
public List<String> process() throws IOException {
    MissingRecordAwareHSSFListener listener = new MissingRecordAwareHSSFListener(this);
    formatListener = new FormatTrackingHSSFListener(listener);

    HSSFEventFactory factory = new HSSFEventFactory();
    HSSFRequest request = new HSSFRequest();

    if (outputFormulaValues) {
        request.addListenerForAllRecords(formatListener);
    } else {
        workbookBuildingListener = new SheetRecordCollectingListener(formatListener);
        request.addListenerForAllRecords(workbookBuildingListener);
    }

    factory.processWorkbookEvents(request, fs);

    return results;
}
 
Example #5
Source File: HSSFSaxReadHandler.java    From myexcel with Apache License 2.0 6 votes vote down vote up
public void process() throws IOException {
    long startTime = System.currentTimeMillis();
    MissingRecordAwareHSSFListener listener = new MissingRecordAwareHSSFListener(this);
    formatListener = new FormatTrackingHSSFListener(listener);

    HSSFEventFactory factory = new HSSFEventFactory();
    HSSFRequest request = new HSSFRequest();

    if (outputFormulaValues) {
        request.addListenerForAllRecords(formatListener);
    } else {
        workbookBuildingListener = new EventWorkbookBuilder.SheetRecordCollectingListener(formatListener);
        request.addListenerForAllRecords(workbookBuildingListener);
    }

    factory.processWorkbookEvents(request, fs);
    log.info("Sax import takes {} ms", System.currentTimeMillis() - startTime);
}
 
Example #6
Source File: EFBiffViewer.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public void run() throws IOException {
    NPOIFSFileSystem fs   = new NPOIFSFileSystem(new File(file), true);
    try {
        InputStream     din   = BiffViewer.getPOIFSInputStream(fs);
        try {
            HSSFRequest     req   = new HSSFRequest();
    
            req.addListenerForAllRecords(new HSSFListener()
            {
                public void processRecord(Record rec)
                {
                    System.out.println(rec);
                }
            });
            HSSFEventFactory factory = new HSSFEventFactory();
    
            factory.processEvents(req, din);
        } finally {
            din.close();
        }
    } finally {
        fs.close();
    }
}
 
Example #7
Source File: Excel2003Reader.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 遍历excel下所有的sheet
 * @param fileKey 
 * @throws IOException
 */
public void process( InputStream is ) throws IOException {
	this.fs = new POIFSFileSystem( is );
	MissingRecordAwareHSSFListener listener = new MissingRecordAwareHSSFListener( this);
	formatListener = new FormatTrackingHSSFListener(listener);
	HSSFEventFactory factory = new HSSFEventFactory();
	HSSFRequest request = new HSSFRequest();
	if ( outputFormulaValues ) {
		request.addListenerForAllRecords( formatListener );
	} else {
		workbookBuildingListener = new SheetRecordCollectingListener( formatListener);
		request.addListenerForAllRecords(workbookBuildingListener);
	}
	factory.processWorkbookEvents(request, fs);
	//数据读取完成
}
 
Example #8
Source File: Excel2003Reader.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 遍历excel下所有的sheet
 * @param fileKey 
 * @throws IOException
 */
public void process(String fileName ) throws IOException {
	
	this.fs = new POIFSFileSystem(new FileInputStream(fileName));
	MissingRecordAwareHSSFListener listener = new MissingRecordAwareHSSFListener( this);
	formatListener = new FormatTrackingHSSFListener(listener);
	HSSFEventFactory factory = new HSSFEventFactory();
	HSSFRequest request = new HSSFRequest();
	if ( outputFormulaValues ) {
		request.addListenerForAllRecords( formatListener );
	} else {
		workbookBuildingListener = new SheetRecordCollectingListener( formatListener);
		request.addListenerForAllRecords(workbookBuildingListener);
	}
	factory.processWorkbookEvents(request, fs);
	//数据读取完成
}
 
Example #9
Source File: Excel2003Reader.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 遍历excel下所有的sheet
 * @param fileKey 
 * @throws IOException
 */
public void process( InputStream is ) throws IOException {
	this.fs = new POIFSFileSystem( is );
	MissingRecordAwareHSSFListener listener = new MissingRecordAwareHSSFListener( this);
	formatListener = new FormatTrackingHSSFListener(listener);
	HSSFEventFactory factory = new HSSFEventFactory();
	HSSFRequest request = new HSSFRequest();
	if ( outputFormulaValues ) {
		request.addListenerForAllRecords( formatListener );
	} else {
		workbookBuildingListener = new SheetRecordCollectingListener( formatListener);
		request.addListenerForAllRecords(workbookBuildingListener);
	}
	factory.processWorkbookEvents(request, fs);
	//数据读取完成
}
 
Example #10
Source File: Excel2003Reader.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 遍历excel下所有的sheet
 * @param fileKey 
 * @throws IOException
 */
public void process(String fileName ) throws IOException {
	
	this.fs = new POIFSFileSystem(new FileInputStream(fileName));
	MissingRecordAwareHSSFListener listener = new MissingRecordAwareHSSFListener( this);
	formatListener = new FormatTrackingHSSFListener(listener);
	HSSFEventFactory factory = new HSSFEventFactory();
	HSSFRequest request = new HSSFRequest();
	if ( outputFormulaValues ) {
		request.addListenerForAllRecords( formatListener );
	} else {
		workbookBuildingListener = new SheetRecordCollectingListener( formatListener);
		request.addListenerForAllRecords(workbookBuildingListener);
	}
	factory.processWorkbookEvents(request, fs);
	//数据读取完成
}
 
Example #11
Source File: Excel2003Reader.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 遍历excel下所有的sheet
 * @param fileKey 
 * @throws IOException
 */
public void process( InputStream is ) throws IOException {
	this.fs = new POIFSFileSystem( is );
	MissingRecordAwareHSSFListener listener = new MissingRecordAwareHSSFListener( this);
	formatListener = new FormatTrackingHSSFListener(listener);
	HSSFEventFactory factory = new HSSFEventFactory();
	HSSFRequest request = new HSSFRequest();
	if ( outputFormulaValues ) {
		request.addListenerForAllRecords( formatListener );
	} else {
		workbookBuildingListener = new SheetRecordCollectingListener( formatListener);
		request.addListenerForAllRecords(workbookBuildingListener);
	}
	factory.processWorkbookEvents(request, fs);
	//数据读取完成
	
}
 
Example #12
Source File: Excel2003Reader.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 遍历excel下所有的sheet
 * @param fileKey 
 * @throws IOException
 */
public void process( InputStream is ) throws IOException {
	this.fs = new POIFSFileSystem( is );
	MissingRecordAwareHSSFListener listener = new MissingRecordAwareHSSFListener( this);
	formatListener = new FormatTrackingHSSFListener(listener);
	HSSFEventFactory factory = new HSSFEventFactory();
	HSSFRequest request = new HSSFRequest();
	if ( outputFormulaValues ) {
		request.addListenerForAllRecords( formatListener );
	} else {
		workbookBuildingListener = new SheetRecordCollectingListener( formatListener);
		request.addListenerForAllRecords(workbookBuildingListener);
	}
	factory.processWorkbookEvents(request, fs);
	//数据读取完成
	
}
 
Example #13
Source File: Excel2003Reader.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 遍历excel下所有的sheet
 * @param fileKey 
 * @throws IOException
 */
public void process( String fileName ) throws IOException {
	
	this.fs = new POIFSFileSystem( new FileInputStream(fileName) );
	MissingRecordAwareHSSFListener listener = new MissingRecordAwareHSSFListener( this);
	formatListener = new FormatTrackingHSSFListener(listener);
	HSSFEventFactory factory = new HSSFEventFactory();
	HSSFRequest request = new HSSFRequest();
	if ( outputFormulaValues ) {
		request.addListenerForAllRecords( formatListener );
	} else {
		workbookBuildingListener = new SheetRecordCollectingListener( formatListener);
		request.addListenerForAllRecords(workbookBuildingListener);
	}
	factory.processWorkbookEvents(request, fs);
	//数据读取完成
	
}
 
Example #14
Source File: Excel2003Reader.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 遍历excel下所有的sheet
 * @param fileKey 
 * @throws IOException
 */
public void process( InputStream is ) throws IOException {
	this.fs = new POIFSFileSystem( is );
	MissingRecordAwareHSSFListener listener = new MissingRecordAwareHSSFListener( this);
	formatListener = new FormatTrackingHSSFListener(listener);
	HSSFEventFactory factory = new HSSFEventFactory();
	HSSFRequest request = new HSSFRequest();
	if ( outputFormulaValues ) {
		request.addListenerForAllRecords( formatListener );
	} else {
		workbookBuildingListener = new SheetRecordCollectingListener( formatListener);
		request.addListenerForAllRecords(workbookBuildingListener);
	}
	factory.processWorkbookEvents(request, fs);
	//数据读取完成
	
}
 
Example #15
Source File: Excel2003Reader.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 遍历excel下所有的sheet
 * @param fileKey 
 * @throws IOException
 */
public void process( String fileName ) throws IOException {
	
	this.fs = new POIFSFileSystem( new FileInputStream(fileName) );
	MissingRecordAwareHSSFListener listener = new MissingRecordAwareHSSFListener( this);
	formatListener = new FormatTrackingHSSFListener(listener);
	HSSFEventFactory factory = new HSSFEventFactory();
	HSSFRequest request = new HSSFRequest();
	if ( outputFormulaValues ) {
		request.addListenerForAllRecords( formatListener );
	} else {
		workbookBuildingListener = new SheetRecordCollectingListener( formatListener);
		request.addListenerForAllRecords(workbookBuildingListener);
	}
	factory.processWorkbookEvents(request, fs);
	//数据读取完成
	
}
 
Example #16
Source File: Excel2003Reader.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 遍历excel下所有的sheet
 * @param fileKey 
 * @throws IOException
 */
public void process( InputStream is ) throws IOException {
	this.fs = new POIFSFileSystem( is );
	MissingRecordAwareHSSFListener listener = new MissingRecordAwareHSSFListener( this);
	formatListener = new FormatTrackingHSSFListener(listener);
	HSSFEventFactory factory = new HSSFEventFactory();
	HSSFRequest request = new HSSFRequest();
	if ( outputFormulaValues ) {
		request.addListenerForAllRecords( formatListener );
	} else {
		workbookBuildingListener = new SheetRecordCollectingListener( formatListener);
		request.addListenerForAllRecords(workbookBuildingListener);
	}
	factory.processWorkbookEvents(request, fs);
	//数据读取完成
	
}
 
Example #17
Source File: Excel2003Reader.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 遍历excel下所有的sheet
 * @param fileKey 
 * @throws IOException
 */
public void process( String fileName ) throws IOException {
	
	this.fs = new POIFSFileSystem( new FileInputStream(fileName) );
	MissingRecordAwareHSSFListener listener = new MissingRecordAwareHSSFListener( this);
	formatListener = new FormatTrackingHSSFListener(listener);
	HSSFEventFactory factory = new HSSFEventFactory();
	HSSFRequest request = new HSSFRequest();
	if ( outputFormulaValues ) {
		request.addListenerForAllRecords( formatListener );
	} else {
		workbookBuildingListener = new SheetRecordCollectingListener( formatListener);
		request.addListenerForAllRecords(workbookBuildingListener);
	}
	factory.processWorkbookEvents(request, fs);
	//数据读取完成
	
}
 
Example #18
Source File: Excel2003Reader.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 遍历excel下所有的sheet
 * @param fileKey 
 * @throws IOException
 */
public void process( InputStream is ) throws IOException {
	this.fs = new POIFSFileSystem( is );
	MissingRecordAwareHSSFListener listener = new MissingRecordAwareHSSFListener( this);
	formatListener = new FormatTrackingHSSFListener(listener);
	HSSFEventFactory factory = new HSSFEventFactory();
	HSSFRequest request = new HSSFRequest();
	if ( outputFormulaValues ) {
		request.addListenerForAllRecords( formatListener );
	} else {
		workbookBuildingListener = new SheetRecordCollectingListener( formatListener);
		request.addListenerForAllRecords(workbookBuildingListener);
	}
	factory.processWorkbookEvents(request, fs);
	//数据读取完成
	
}
 
Example #19
Source File: Excel2003Reader.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 遍历excel下所有的sheet
 * @param fileKey 
 * @throws IOException
 */
public void process( String fileName ) throws IOException {
	
	this.fs = new POIFSFileSystem( new FileInputStream(fileName) );
	MissingRecordAwareHSSFListener listener = new MissingRecordAwareHSSFListener( this);
	formatListener = new FormatTrackingHSSFListener(listener);
	HSSFEventFactory factory = new HSSFEventFactory();
	HSSFRequest request = new HSSFRequest();
	if ( outputFormulaValues ) {
		request.addListenerForAllRecords( formatListener );
	} else {
		workbookBuildingListener = new SheetRecordCollectingListener( formatListener);
		request.addListenerForAllRecords(workbookBuildingListener);
	}
	factory.processWorkbookEvents(request, fs);
	//数据读取完成
	
}
 
Example #20
Source File: XlsSaxAnalyser.java    From easyexcel with Apache License 2.0 6 votes vote down vote up
@Override
public void execute() {
    XlsReadWorkbookHolder xlsReadWorkbookHolder = xlsReadContext.xlsReadWorkbookHolder();
    MissingRecordAwareHSSFListener listener = new MissingRecordAwareHSSFListener(this);
    xlsReadWorkbookHolder.setFormatTrackingHSSFListener(new FormatTrackingHSSFListener(listener));
    EventWorkbookBuilder.SheetRecordCollectingListener workbookBuildingListener =
        new EventWorkbookBuilder.SheetRecordCollectingListener(
            xlsReadWorkbookHolder.getFormatTrackingHSSFListener());
    xlsReadWorkbookHolder.setHssfWorkbook(workbookBuildingListener.getStubHSSFWorkbook());
    HSSFEventFactory factory = new HSSFEventFactory();
    HSSFRequest request = new HSSFRequest();
    request.addListenerForAllRecords(xlsReadWorkbookHolder.getFormatTrackingHSSFListener());
    try {
        factory.processWorkbookEvents(request, xlsReadWorkbookHolder.getPoifsFileSystem());
    } catch (IOException e) {
        throw new ExcelAnalysisException(e);
    }
}
 
Example #21
Source File: Default03RecordHandlerContext.java    From easyexcel with Apache License 2.0 5 votes vote down vote up
public static Default03RecordHandlerContext getContext(HSSFRequest request, POIFSFileSystem fileSystem) {
	Default03RecordHandlerContext context = new Default03RecordHandlerContext();
	context.currColNum = 0;
	context.currRowList = Lists.newArrayList();
	context.rowQueue = new LinkedBlockingQueue<>();
	context.initHeadHandler();
	context.request = request;
	context.fileSystem = fileSystem;
	return context;
}
 
Example #22
Source File: EventBasedExcelExtractor.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private TextListener triggerExtraction() throws IOException {
    TextListener tl = new TextListener();
    FormatTrackingHSSFListener ft = new FormatTrackingHSSFListener(tl);
    tl._ft = ft;

    // Register and process
    HSSFEventFactory factory = new HSSFEventFactory();
    HSSFRequest request = new HSSFRequest();
    request.addListenerForAllRecords(ft);

    factory.processWorkbookEvents(request, _dir);

    return tl;
}
 
Example #23
Source File: XlsListSheetListener.java    From easyexcel with Apache License 2.0 5 votes vote down vote up
public void execute() {
    MissingRecordAwareHSSFListener listener = new MissingRecordAwareHSSFListener(this);
    HSSFListener formatListener = new FormatTrackingHSSFListener(listener);
    HSSFEventFactory factory = new HSSFEventFactory();
    HSSFRequest request = new HSSFRequest();
    EventWorkbookBuilder.SheetRecordCollectingListener workbookBuildingListener =
        new EventWorkbookBuilder.SheetRecordCollectingListener(formatListener);
    request.addListenerForAllRecords(workbookBuildingListener);
    try {
        factory.processWorkbookEvents(request, xlsReadContext.xlsReadWorkbookHolder().getPoifsFileSystem());
    } catch (IOException e) {
        throw new ExcelAnalysisException(e);
    }
}