01: /* ====================================================================
02: Licensed to the Apache Software Foundation (ASF) under one or more
03: contributor license agreements. See the NOTICE file distributed with
04: this work for additional information regarding copyright ownership.
05: The ASF licenses this file to You under the Apache License, Version 2.0
06: (the "License"); you may not use this file except in compliance with
07: the License. You may obtain a copy of the License at
08:
09: http://www.apache.org/licenses/LICENSE-2.0
10:
11: Unless required by applicable law or agreed to in writing, software
12: distributed under the License is distributed on an "AS IS" BASIS,
13: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: See the License for the specific language governing permissions and
15: limitations under the License.
16: ==================================================================== */
17:
18: package org.apache.poi.hssf.dev;
19:
20: import java.io.FileInputStream;
21: import java.io.InputStream;
22: import java.io.IOException;
23:
24: import org.apache.poi.poifs.filesystem.POIFSFileSystem;
25: import org.apache.poi.hssf.record.Record;
26:
27: import org.apache.poi.hssf.eventusermodel.HSSFRequest;
28: import org.apache.poi.hssf.eventusermodel.HSSFListener;
29: import org.apache.poi.hssf.eventusermodel.HSSFEventFactory;
30:
31: /**
32: *
33: * @author andy
34: */
35:
36: public class EFBiffViewer {
37: String file;
38:
39: /** Creates a new instance of EFBiffViewer */
40:
41: public EFBiffViewer() {
42: }
43:
44: public void run() throws IOException {
45: FileInputStream fin = new FileInputStream(file);
46: POIFSFileSystem poifs = new POIFSFileSystem(fin);
47: InputStream din = poifs.createDocumentInputStream("Workbook");
48: HSSFRequest req = new HSSFRequest();
49:
50: req.addListenerForAllRecords(new HSSFListener() {
51: public void processRecord(Record rec) {
52: System.out.println(rec.toString());
53: }
54: });
55: HSSFEventFactory factory = new HSSFEventFactory();
56:
57: factory.processEvents(req, din);
58: }
59:
60: public void setFile(String file) {
61: this .file = file;
62: }
63:
64: public static void main(String[] args) {
65: if ((args.length == 1) && !args[0].equals("--help")) {
66: try {
67: EFBiffViewer viewer = new EFBiffViewer();
68:
69: viewer.setFile(args[0]);
70: viewer.run();
71: } catch (IOException e) {
72: e.printStackTrace();
73: }
74: } else {
75: System.out.println("EFBiffViewer");
76: System.out
77: .println("Outputs biffview of records based on HSSFEventFactory");
78: System.out
79: .println("usage: java org.apache.poi.hssf.dev.EBBiffViewer "
80: + "filename");
81: }
82: }
83: }
|