Source Code Cross Referenced for EventExample.java in  » Collaboration » poi-3.0.2-beta2 » org » apache » poi » hssf » usermodel » examples » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Collaboration » poi 3.0.2 beta2 » org.apache.poi.hssf.usermodel.examples 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* ====================================================================
002:         Licensed to the Apache Software Foundation (ASF) under one or more
003:         contributor license agreements.  See the NOTICE file distributed with
004:         this work for additional information regarding copyright ownership.
005:         The ASF licenses this file to You under the Apache License, Version 2.0
006:         (the "License"); you may not use this file except in compliance with
007:         the License.  You may obtain a copy of the License at
008:
009:         http://www.apache.org/licenses/LICENSE-2.0
010:
011:         Unless required by applicable law or agreed to in writing, software
012:         distributed under the License is distributed on an "AS IS" BASIS,
013:         WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         See the License for the specific language governing permissions and
015:         limitations under the License.
016:         ==================================================================== */
017:
018:        package org.apache.poi.hssf.usermodel.examples;
019:
020:        import org.apache.poi.hssf.eventusermodel.HSSFEventFactory;
021:        import org.apache.poi.hssf.eventusermodel.HSSFListener;
022:        import org.apache.poi.hssf.eventusermodel.HSSFRequest;
023:        import org.apache.poi.hssf.record.*;
024:        import org.apache.poi.poifs.filesystem.POIFSFileSystem;
025:
026:        import java.io.FileInputStream;
027:        import java.io.IOException;
028:        import java.io.InputStream;
029:
030:        /**
031:         * This example shows how to use the event API for reading a file.
032:         */
033:        public class EventExample implements  HSSFListener {
034:            private SSTRecord sstrec;
035:
036:            /**
037:             * This method listens for incoming records and handles them as required.
038:             * @param record    The record that was found while reading.
039:             */
040:            public void processRecord(Record record) {
041:                switch (record.getSid()) {
042:                // the BOFRecord can represent either the beginning of a sheet or the workbook
043:                case BOFRecord.sid:
044:                    BOFRecord bof = (BOFRecord) record;
045:                    if (bof.getType() == bof.TYPE_WORKBOOK) {
046:                        System.out.println("Encountered workbook");
047:                        // assigned to the class level member
048:                    } else if (bof.getType() == bof.TYPE_WORKSHEET) {
049:                        System.out.println("Encountered sheet reference");
050:                    }
051:                    break;
052:                case BoundSheetRecord.sid:
053:                    BoundSheetRecord bsr = (BoundSheetRecord) record;
054:                    System.out
055:                            .println("New sheet named: " + bsr.getSheetname());
056:                    break;
057:                case RowRecord.sid:
058:                    RowRecord rowrec = (RowRecord) record;
059:                    System.out.println("Row found, first column at "
060:                            + rowrec.getFirstCol() + " last column at "
061:                            + rowrec.getLastCol());
062:                    break;
063:                case NumberRecord.sid:
064:                    NumberRecord numrec = (NumberRecord) record;
065:                    System.out.println("Cell found with value "
066:                            + numrec.getValue() + " at row " + numrec.getRow()
067:                            + " and column " + numrec.getColumn());
068:                    break;
069:                // SSTRecords store a array of unique strings used in Excel.
070:                case SSTRecord.sid:
071:                    sstrec = (SSTRecord) record;
072:                    for (int k = 0; k < sstrec.getNumUniqueStrings(); k++) {
073:                        System.out.println("String table value " + k + " = "
074:                                + sstrec.getString(k));
075:                    }
076:                    break;
077:                case LabelSSTRecord.sid:
078:                    LabelSSTRecord lrec = (LabelSSTRecord) record;
079:                    System.out.println("String cell found with value "
080:                            + sstrec.getString(lrec.getSSTIndex()));
081:                    break;
082:                }
083:            }
084:
085:            /**
086:             * Read an excel file and spit out what we find.
087:             *
088:             * @param args      Expect one argument that is the file to read.
089:             * @throws IOException  When there is an error processing the file.
090:             */
091:            public static void main(String[] args) throws IOException {
092:                // create a new file input stream with the input file specified
093:                // at the command line
094:                FileInputStream fin = new FileInputStream(args[0]);
095:                // create a new org.apache.poi.poifs.filesystem.Filesystem
096:                POIFSFileSystem poifs = new POIFSFileSystem(fin);
097:                // get the Workbook (excel part) stream in a InputStream
098:                InputStream din = poifs.createDocumentInputStream("Workbook");
099:                // construct out HSSFRequest object
100:                HSSFRequest req = new HSSFRequest();
101:                // lazy listen for ALL records with the listener shown above
102:                req.addListenerForAllRecords(new EventExample());
103:                // create our event factory
104:                HSSFEventFactory factory = new HSSFEventFactory();
105:                // process our events based on the document input stream
106:                factory.processEvents(req, din);
107:                // once all the events are processed close our file input stream
108:                fin.close();
109:                // and our document input stream (don't want to leak these!)
110:                din.close();
111:                System.out.println("done.");
112:            }
113:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.