KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hssf > dev > EFBiffViewer


1 /* ====================================================================
2    Copyright 2002-2004 Apache Software Foundation
3
4    Licensed under the Apache License, Version 2.0 (the "License");
5    you may not use this file except in compliance with the License.
6    You may obtain a copy of the License at
7
8        http://www.apache.org/licenses/LICENSE-2.0
9
10    Unless required by applicable law or agreed to in writing, software
11    distributed under the License is distributed on an "AS IS" BASIS,
12    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13    See the License for the specific language governing permissions and
14    limitations under the License.
15 ==================================================================== */

16
17 package org.apache.poi.hssf.dev;
18
19 import java.io.FileInputStream JavaDoc;
20 import java.io.InputStream JavaDoc;
21 import java.io.IOException JavaDoc;
22
23 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
24 import org.apache.poi.hssf.eventmodel.*;
25 import org.apache.poi.hssf.eventusermodel.*;
26 import org.apache.poi.hssf.record.Record;
27
28 import org.apache.poi.hssf.eventusermodel.HSSFRequest;
29 import org.apache.poi.hssf.eventusermodel.HSSFListener;
30 import org.apache.poi.hssf.eventusermodel.HSSFEventFactory;
31
32 /**
33  *
34  * @author andy
35  */

36
37 public class EFBiffViewer
38 {
39     String JavaDoc file;
40
41     /** Creates a new instance of EFBiffViewer */
42
43     public EFBiffViewer()
44     {
45     }
46
47     public void run()
48         throws IOException JavaDoc
49     {
50         FileInputStream JavaDoc fin = new FileInputStream JavaDoc(file);
51         POIFSFileSystem poifs = new POIFSFileSystem(fin);
52         InputStream JavaDoc din = poifs.createDocumentInputStream("Workbook");
53         HSSFRequest req = new HSSFRequest();
54
55         req.addListenerForAllRecords(new HSSFListener()
56         {
57             public void processRecord(Record rec)
58             {
59                 System.out.println(rec.toString());
60             }
61         });
62         HSSFEventFactory factory = new HSSFEventFactory();
63
64         factory.processEvents(req, din);
65     }
66
67     public void setFile(String JavaDoc file)
68     {
69         this.file = file;
70     }
71
72     public static void main(String JavaDoc [] args)
73     {
74         if ((args.length == 1) && !args[ 0 ].equals("--help"))
75         {
76             try
77             {
78                 EFBiffViewer viewer = new EFBiffViewer();
79
80                 viewer.setFile(args[ 0 ]);
81                 viewer.run();
82             }
83             catch (IOException JavaDoc e)
84             {
85                 e.printStackTrace();
86             }
87         }
88         else
89         {
90             System.out.println("EFBiffViewer");
91             System.out.println(
92                 "Outputs biffview of records based on HSSFEventFactory");
93             System.out
94                 .println("usage: java org.apache.poi.hssf.dev.EBBiffViewer "
95                          + "filename");
96         }
97     }
98 }
99
Popular Tags