Source Code Cross Referenced for ExcelExportHelper.java in  » XML-UI » xui32 » com » xoetrope » io » 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 » XML UI » xui32 » com.xoetrope.io 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.xoetrope.io;
002:
003:        import java.io.IOException;
004:        import java.io.File;
005:
006:        import jxl.CellView;
007:        import jxl.Workbook;
008:        import jxl.format.Colour;
009:        import jxl.write.Label;
010:        import jxl.write.WritableCellFormat;
011:        import jxl.write.WritableSheet;
012:        import jxl.write.WritableWorkbook;
013:        import jxl.write.WriteException;
014:
015:        /**
016:         * Export an Excel worksheet to a new workbook.
017:         *
018:         * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
019:         * the GNU Public License (GPL), please see license.txt for more details. If
020:         * you make commercial use of this software you must purchase a commercial
021:         * license from Xoetrope.</p>
022:         * <p> $Revision: 1.4 $</p>
023:         * @deprecated use the com.xoetrope.export classes instead
024:         */
025:        public class ExcelExportHelper extends XExportHelper {
026:            /**
027:             * The excel workbook being output
028:             */
029:            protected WritableWorkbook workbookOut = null;
030:            /**
031:             * The excel sheet being output
032:             */
033:            protected WritableSheet sheetOut = null;
034:
035:            /**
036:             * The excel format of the title fields
037:             */
038:            protected WritableCellFormat titleFormat;
039:
040:            /**
041:             * The excel format of the subtitle fields
042:             */
043:            protected WritableCellFormat subTitleFormat;
044:
045:            /**
046:             * The excel format of the section divider fields
047:             */
048:            protected WritableCellFormat sectionFormat;
049:
050:            /**
051:             * The excel format of the body fields
052:             */
053:            protected WritableCellFormat bodyFormat;
054:
055:            /**
056:             * Flag indicating if the exporter is in the process of exporting a table
057:             */
058:            protected boolean isInTable;
059:            /**
060:             * Flag indicating if the exporter is in the process of exporting a table header
061:             */
062:            protected boolean isInTableHeader;
063:
064:            /**
065:             * Flag indicating if the exporter is in the process of exporting a table record
066:             */
067:            protected boolean isInRecord;
068:
069:            /**
070:             * Flag indicating if the exporter is in the process of exporting grouped elements
071:             */
072:            protected boolean isInGroup;
073:
074:            /**
075:             * The current record or row index
076:             */
077:            protected int recordIndex;
078:
079:            /**
080:             * The current colum or field index
081:             */
082:            protected int columnIndex;
083:
084:            /**
085:             * Setup an exporter for excel sheets.
086:             * @param fileName The name of the file to export
087:             * @throws java.io.IOException thrown if the stream is not ready or if it is in an invalid state
088:             */
089:            public ExcelExportHelper(String fileName) throws IOException {
090:                defaultExtension = ".xls";
091:
092:                workbookOut = Workbook.createWorkbook(new File(fileName));
093:                sheetOut = workbookOut.createSheet("export", 0);
094:
095:                titleFormat = new WritableCellFormat();
096:                subTitleFormat = new WritableCellFormat();
097:                sectionFormat = new WritableCellFormat();
098:                bodyFormat = new WritableCellFormat();
099:
100:                try {
101:                    titleFormat.setBackground(Colour.VERY_LIGHT_YELLOW);
102:                    subTitleFormat.setBackground(Colour.VERY_LIGHT_YELLOW);
103:                    sectionFormat.setBackground(Colour.GRAY_25);
104:                    bodyFormat.setBackground(Colour.WHITE);
105:                } catch (WriteException ex) {
106:                }
107:
108:                int[] charWidths = { 50, 50, 30, 20 };
109:                CellView cv;
110:                for (int i = 0; i < charWidths.length; i++) {
111:                    cv = sheetOut.getColumnView(i);
112:                    cv.setSize(charWidths[i] * 256);
113:                    sheetOut.setColumnView(i, cv);
114:                }
115:            }
116:
117:            /**
118:             * Write the opening of a document
119:             * @throws IOException thrown if the stream is not ready or if it is in an invalid state
120:             */
121:            public void startDocument() throws IOException {
122:                addCell(recordIndex++, 0, "CoolSelector Export", titleFormat);
123:            }
124:
125:            /**
126:             * Write the ending of a document
127:             * @throws IOException thrown if the stream is not ready or if it is in an invalid state
128:             */
129:            public void endDocument() throws IOException {
130:            }
131:
132:            /**
133:             * Write the opening of a table
134:             * @throws IOException thrown if the stream is not ready or if it is in an invalid state
135:             */
136:            public void startTable() throws IOException {
137:            }
138:
139:            /**
140:             * Write the ending of a table
141:             * @throws IOException thrown if the stream is not ready or if it is in an invalid state
142:             */
143:            public void endTable() throws IOException {
144:            }
145:
146:            /**
147:             * Write the opening of a table group of records
148:             * @throws IOException thrown if the stream is not ready or if it is in an invalid state
149:             */
150:            public void startGroup() throws IOException {
151:                isInGroup = true;
152:                columnIndex = 0;
153:            }
154:
155:            /**
156:             * Write the ending of a table group of records
157:             * @throws IOException thrown if the stream is not ready or if it is in an invalid state
158:             */
159:            public void endGroup() throws IOException {
160:                isInGroup = false;
161:            }
162:
163:            /**
164:             * Write the opening of a table record
165:             * @throws IOException thrown if the stream is not ready or if it is in an invalid state
166:             */
167:            public void startRecord() throws IOException {
168:                isInRecord = true;
169:            }
170:
171:            /**
172:             * Write the ending of a table record
173:             * @throws IOException thrown if the stream is not ready or if it is in an invalid state
174:             */
175:            public void endRecord() throws IOException {
176:                recordIndex++;
177:            }
178:
179:            /**
180:             * Write the opening of a table record
181:             * @throws IOException thrown if the stream is not ready or if it is in an invalid state
182:             */
183:            public void startHeader() throws IOException {
184:                isInTableHeader = true;
185:                columnIndex = 0;
186:            }
187:
188:            /**
189:             * Write the ending of a table record
190:             * @throws IOException thrown if the stream is not ready or if it is in an invalid state
191:             */
192:            public void endHeader() throws IOException {
193:                isInTableHeader = false;
194:                recordIndex++;
195:            }
196:
197:            /**
198:             * Write a field
199:             * @param name the field name
200:             * @param value the field value
201:             * @throws IOException thrown if the stream is not ready or if it is in an invalid state
202:             */
203:            public void writeField(String name, String value)
204:                    throws IOException {
205:                if (isInTableHeader)
206:                    addCell(recordIndex, columnIndex++, name, bodyFormat);
207:                else if (isInGroup)
208:                    addCell(recordIndex, columnIndex++, value, bodyFormat);
209:                else {
210:                    addCell(recordIndex, 0, name, bodyFormat);
211:                    addCell(recordIndex++, 1, value, bodyFormat);
212:                }
213:            }
214:
215:            /**
216:             * Write the section title and terminate with a line feed, new line as appropriate
217:             * @param text the text to output
218:             * @throws IOException thrown if the stream is not ready or if it is in an invalid state
219:             */
220:            public void writeSectionTitle(String text) throws IOException {
221:                addCell(recordIndex++, 0, text, sectionFormat);
222:            }
223:
224:            /**
225:             * Write the begining/opening of an element
226:             * @param elementName the element name
227:             * @throws IOException thrown if the stream is not ready or if it is in an invalid state
228:             */
229:            public void startElement(String elementName) throws IOException {
230:                firstField = true;
231:                columnIndex = 0;
232:            }
233:
234:            /**
235:             * Write the matching ending element
236:             * @throws IOException thrown if the stream is not ready or if it is in an invalid state
237:             */
238:            public void matchElement() throws IOException {
239:            }
240:
241:            /**
242:             * Write the end of an element opening
243:             * @throws IOException thrown if the stream is not ready or if it is in an invalid state
244:             */
245:            public void endElement() throws IOException {
246:            }
247:
248:            /**
249:             * Write the closing of an element
250:             * @throws IOException thrown if the stream is not ready or if it is in an invalid state
251:             */
252:            public void closeElement() throws IOException {
253:            }
254:
255:            /**
256:             * Write the end of a section
257:             * @throws IOException thrown if the stream is not ready or if it is in an invalid state
258:             */
259:            public void writeSectionEnd() throws IOException {
260:            }
261:
262:            /**
263:             * Write the text and terminate with a line feed, new line as appropriate
264:             * @param elementName the element name
265:             * @param name the field or attribute name
266:             * @param value the field or attribute value
267:             * @throws IOException thrown if the stream is not ready or if it is in an invalid state
268:             */
269:            public void writeElement(String elementName, String name,
270:                    String value) throws IOException {
271:                addCell(recordIndex, 0, name, bodyFormat);
272:                addCell(recordIndex++, 1, value, bodyFormat);
273:            }
274:
275:            /**
276:             * Write the text and terminate with a line feed, new line as appropriate
277:             * @param elementName the element name
278:             * @param names the field or attribute names
279:             * @param values the field or attribute value
280:             * @throws IOException thrown if the stream is not ready or if it is in an invalid state
281:             */
282:            public void writeElement(String elementName, String[] names,
283:                    String[] values) throws IOException {
284:                for (int i = 0; i < names.length; i++) {
285:                    //      addCell( recordIndex, i, names[ i ], bodyFormat );
286:                    addCell(recordIndex, i, values[i], bodyFormat);
287:                }
288:            }
289:
290:            /**
291:             * Output a blank line
292:             * @throws IOException thrown if the stream is not ready or if it is in an invalid state
293:             */
294:            public void writeBlankLine() throws IOException {
295:                recordIndex++;
296:            }
297:
298:            /**
299:             * Flushes and closes any existing stream
300:             * @throws java.io.IOException thrown if the stream is not ready or if it is in an invalid state
301:             */
302:            public void close() throws IOException {
303:                workbookOut.write();
304:                workbookOut.close();
305:            }
306:
307:            /**
308:             * Adds a cell to an Excel sheet. Zero based indexing is used.
309:             * @param row the row in the sheet
310:             * @param col the column in the sheet 
311:             * @param value the value to write to the excel sheet's cell
312:             * @param cellFormat the cell format
313:             */
314:            protected void addCell(int row, int col, String value,
315:                    WritableCellFormat cellFormat) {
316:                try {
317:                    Label labelOut = new Label(col, row, value);
318:                    labelOut.setCellFormat(cellFormat);
319:                    sheetOut.addCell(labelOut);
320:                } catch (WriteException ex) {
321:                    ex.printStackTrace();
322:                }
323:            }
324:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.