Source Code Cross Referenced for BigExample.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.usermodel.*;
021:        import org.apache.poi.hssf.util.HSSFColor;
022:
023:        import java.io.FileOutputStream;
024:        import java.io.IOException;
025:
026:        /**
027:         * Demonstrates many features of the user API at once.  Used in the HOW-TO guide.
028:         *
029:         * @author Glen Stampoultzis (glens at apache.org)
030:         * @author Andrew Oliver (acoliver at apache.org)
031:         */
032:        public class BigExample {
033:            public static void main(String[] args) throws IOException {
034:                short rownum;
035:
036:                // create a new file
037:                FileOutputStream out = new FileOutputStream("workbook.xls");
038:                // create a new workbook
039:                HSSFWorkbook wb = new HSSFWorkbook();
040:                // create a new sheet
041:                HSSFSheet s = wb.createSheet();
042:                // declare a row object reference
043:                HSSFRow r = null;
044:                // declare a cell object reference
045:                HSSFCell c = null;
046:                // create 3 cell styles
047:                HSSFCellStyle cs = wb.createCellStyle();
048:                HSSFCellStyle cs2 = wb.createCellStyle();
049:                HSSFCellStyle cs3 = wb.createCellStyle();
050:                // create 2 fonts objects
051:                HSSFFont f = wb.createFont();
052:                HSSFFont f2 = wb.createFont();
053:
054:                //set font 1 to 12 point type
055:                f.setFontHeightInPoints((short) 12);
056:                //make it red
057:                f.setColor((short) HSSFColor.RED.index);
058:                // make it bold
059:                //arial is the default font
060:                f.setBoldweight(f.BOLDWEIGHT_BOLD);
061:
062:                //set font 2 to 10 point type
063:                f2.setFontHeightInPoints((short) 10);
064:                //make it the color at palette index 0xf (white)
065:                f2.setColor((short) HSSFColor.WHITE.index);
066:                //make it bold
067:                f2.setBoldweight(f2.BOLDWEIGHT_BOLD);
068:
069:                //set cell stlye
070:                cs.setFont(f);
071:                //set the cell format see HSSFDataFromat for a full list
072:                cs.setDataFormat(HSSFDataFormat
073:                        .getBuiltinFormat("($#,##0_);[Red]($#,##0)"));
074:
075:                //set a thin border
076:                cs2.setBorderBottom(cs2.BORDER_THIN);
077:                //fill w fg fill color
078:                cs2.setFillPattern((short) HSSFCellStyle.SOLID_FOREGROUND);
079:                // set foreground fill to red
080:                cs2.setFillForegroundColor((short) HSSFColor.RED.index);
081:
082:                // set the font
083:                cs2.setFont(f2);
084:
085:                // set the sheet name to HSSF Test
086:                wb.setSheetName(0, "HSSF Test");
087:                // create a sheet with 300 rows (0-299)
088:                for (rownum = (short) 0; rownum < 300; rownum++) {
089:                    // create a row
090:                    r = s.createRow(rownum);
091:                    // on every other row
092:                    if ((rownum % 2) == 0) {
093:                        // make the row height bigger  (in twips - 1/20 of a point)
094:                        r.setHeight((short) 0x249);
095:                    }
096:
097:                    //r.setRowNum(( short ) rownum);
098:                    // create 50 cells (0-49) (the += 2 becomes apparent later
099:                    for (short cellnum = (short) 0; cellnum < 50; cellnum += 2) {
100:                        // create a numeric cell
101:                        c = r.createCell(cellnum);
102:                        // do some goofy math to demonstrate decimals
103:                        c
104:                                .setCellValue(rownum
105:                                        * 10000
106:                                        + cellnum
107:                                        + (((double) rownum / 1000) + ((double) cellnum / 10000)));
108:
109:                        // on every other row
110:                        if ((rownum % 2) == 0) {
111:                            // set this cell to the first cell style we defined
112:                            c.setCellStyle(cs);
113:                        }
114:
115:                        // create a string cell (see why += 2 in the
116:                        c = r.createCell((short) (cellnum + 1));
117:
118:                        // set the cell's string value to "TEST"
119:                        c.setCellValue("TEST");
120:                        // make this column a bit wider
121:                        s.setColumnWidth((short) (cellnum + 1),
122:                                (short) ((50 * 8) / ((double) 1 / 20)));
123:
124:                        // on every other row
125:                        if ((rownum % 2) == 0) {
126:                            // set this to the white on red cell style
127:                            // we defined above
128:                            c.setCellStyle(cs2);
129:                        }
130:
131:                    }
132:                }
133:
134:                //draw a thick black border on the row at the bottom using BLANKS
135:                // advance 2 rows
136:                rownum++;
137:                rownum++;
138:
139:                r = s.createRow(rownum);
140:
141:                // define the third style to be the default
142:                // except with a thick black border at the bottom
143:                cs3.setBorderBottom(cs3.BORDER_THICK);
144:
145:                //create 50 cells
146:                for (short cellnum = (short) 0; cellnum < 50; cellnum++) {
147:                    //create a blank type cell (no value)
148:                    c = r.createCell(cellnum);
149:                    // set it to the thick black border style
150:                    c.setCellStyle(cs3);
151:                }
152:
153:                //end draw thick black border
154:
155:                // demonstrate adding/naming and deleting a sheet
156:                // create a sheet, set its title then delete it
157:                s = wb.createSheet();
158:                wb.setSheetName(1, "DeletedSheet");
159:                wb.removeSheetAt(1);
160:                //end deleted sheet
161:
162:                // write the workbook to the output stream
163:                // close our file (don't blow out our file handles
164:                wb.write(out);
165:                out.close();
166:            }
167:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.