Source Code Cross Referenced for TestCellStyle.java in  » Collaboration » poi-3.0.2-beta2 » org » apache » poi » hssf » usermodel » 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 
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:        /*
019:         * TestCellStyle.java
020:         *
021:         * Created on December 11, 2001, 5:51 PM
022:         */
023:        package org.apache.poi.hssf.usermodel;
024:
025:        import java.io.*;
026:
027:        import java.util.*;
028:
029:        import junit.framework.*;
030:        import org.apache.poi.util.TempFile;
031:
032:        /**
033:         * Class to test cell styling functionality
034:         *
035:         * @author Andrew C. Oliver
036:         */
037:
038:        public class TestCellStyle extends TestCase {
039:
040:            /** Creates a new instance of TestCellStyle */
041:
042:            public TestCellStyle(String name) {
043:                super (name);
044:            }
045:
046:            /**
047:             * TEST NAME:  Test Write Sheet Font <P>
048:             * OBJECTIVE:  Test that HSSF can create a simple spreadsheet with numeric and string values and styled with fonts.<P>
049:             * SUCCESS:    HSSF creates a sheet.  Filesize matches a known good.  HSSFSheet objects
050:             *             Last row, first row is tested against the correct values (99,0).<P>
051:             * FAILURE:    HSSF does not create a sheet or excepts.  Filesize does not match the known good.
052:             *             HSSFSheet last row or first row is incorrect.             <P>
053:             *
054:             */
055:
056:            public void testWriteSheetFont() throws IOException {
057:                File file = TempFile.createTempFile("testWriteSheetFont",
058:                        ".xls");
059:                FileOutputStream out = new FileOutputStream(file);
060:                HSSFWorkbook wb = new HSSFWorkbook();
061:                HSSFSheet s = wb.createSheet();
062:                HSSFRow r = null;
063:                HSSFCell c = null;
064:                HSSFFont fnt = wb.createFont();
065:                HSSFCellStyle cs = wb.createCellStyle();
066:
067:                fnt.setColor(HSSFFont.COLOR_RED);
068:                fnt.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
069:                cs.setFont(fnt);
070:                for (short rownum = (short) 0; rownum < 100; rownum++) {
071:                    r = s.createRow(rownum);
072:
073:                    // r.setRowNum(( short ) rownum);
074:                    for (short cellnum = (short) 0; cellnum < 50; cellnum += 2) {
075:                        c = r.createCell(cellnum);
076:                        c
077:                                .setCellValue(rownum
078:                                        * 10000
079:                                        + cellnum
080:                                        + (((double) rownum / 1000) + ((double) cellnum / 10000)));
081:                        c = r.createCell((short) (cellnum + 1));
082:                        c.setCellValue("TEST");
083:                        c.setCellStyle(cs);
084:                    }
085:                }
086:                wb.write(out);
087:                out.close();
088:                SanityChecker sanityChecker = new SanityChecker();
089:                sanityChecker.checkHSSFWorkbook(wb);
090:                assertEquals("LAST ROW == 99", 99, s.getLastRowNum());
091:                assertEquals("FIRST ROW == 0", 0, s.getFirstRowNum());
092:
093:                // assert((s.getLastRowNum() == 99));
094:            }
095:
096:            /**
097:             * Tests that is creating a file with a date or an calendar works correctly.
098:             */
099:            public void testDataStyle() throws Exception {
100:                File file = TempFile.createTempFile("testWriteSheetStyleDate",
101:                        ".xls");
102:                FileOutputStream out = new FileOutputStream(file);
103:                HSSFWorkbook wb = new HSSFWorkbook();
104:                HSSFSheet s = wb.createSheet();
105:                HSSFCellStyle cs = wb.createCellStyle();
106:                HSSFRow row = s.createRow((short) 0);
107:
108:                // with Date:
109:                HSSFCell cell = row.createCell((short) 1);
110:                cs.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy"));
111:                cell.setCellStyle(cs);
112:                cell.setCellValue(new Date());
113:
114:                // with Calendar:
115:                cell = row.createCell((short) 2);
116:                cs.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy"));
117:                cell.setCellStyle(cs);
118:                Calendar cal = Calendar.getInstance();
119:                cal.setTime(new Date());
120:                cell.setCellValue(cal);
121:
122:                wb.write(out);
123:                out.close();
124:                SanityChecker sanityChecker = new SanityChecker();
125:                sanityChecker.checkHSSFWorkbook(wb);
126:
127:                assertEquals("LAST ROW ", 0, s.getLastRowNum());
128:                assertEquals("FIRST ROW ", 0, s.getFirstRowNum());
129:
130:            }
131:
132:            /**
133:             * TEST NAME:  Test Write Sheet Style <P>
134:             * OBJECTIVE:  Test that HSSF can create a simple spreadsheet with numeric and string values and styled with colors
135:             *             and borders.<P>
136:             * SUCCESS:    HSSF creates a sheet.  Filesize matches a known good.  HSSFSheet objects
137:             *             Last row, first row is tested against the correct values (99,0).<P>
138:             * FAILURE:    HSSF does not create a sheet or excepts.  Filesize does not match the known good.
139:             *             HSSFSheet last row or first row is incorrect.             <P>
140:             *
141:             */
142:
143:            public void testWriteSheetStyle() throws IOException {
144:                File file = TempFile.createTempFile("testWriteSheetStyle",
145:                        ".xls");
146:                FileOutputStream out = new FileOutputStream(file);
147:                HSSFWorkbook wb = new HSSFWorkbook();
148:                HSSFSheet s = wb.createSheet();
149:                HSSFRow r = null;
150:                HSSFCell c = null;
151:                HSSFFont fnt = wb.createFont();
152:                HSSFCellStyle cs = wb.createCellStyle();
153:                HSSFCellStyle cs2 = wb.createCellStyle();
154:
155:                cs.setBorderBottom(HSSFCellStyle.BORDER_THIN);
156:                cs.setBorderLeft(HSSFCellStyle.BORDER_THIN);
157:                cs.setBorderRight(HSSFCellStyle.BORDER_THIN);
158:                cs.setBorderTop(HSSFCellStyle.BORDER_THIN);
159:                cs.setFillForegroundColor((short) 0xA);
160:                cs.setFillPattern((short) 1);
161:                fnt.setColor((short) 0xf);
162:                fnt.setItalic(true);
163:                cs2.setFillForegroundColor((short) 0x0);
164:                cs2.setFillPattern((short) 1);
165:                cs2.setFont(fnt);
166:                for (short rownum = (short) 0; rownum < 100; rownum++) {
167:                    r = s.createRow(rownum);
168:
169:                    // r.setRowNum(( short ) rownum);
170:                    for (short cellnum = (short) 0; cellnum < 50; cellnum += 2) {
171:                        c = r.createCell(cellnum);
172:                        c
173:                                .setCellValue(rownum
174:                                        * 10000
175:                                        + cellnum
176:                                        + (((double) rownum / 1000) + ((double) cellnum / 10000)));
177:                        c.setCellStyle(cs);
178:                        c = r.createCell((short) (cellnum + 1));
179:                        c.setCellValue("TEST");
180:                        c.setCellStyle(cs2);
181:                    }
182:                }
183:                wb.write(out);
184:                out.close();
185:                SanityChecker sanityChecker = new SanityChecker();
186:                sanityChecker.checkHSSFWorkbook(wb);
187:                assertEquals("LAST ROW == 99", 99, s.getLastRowNum());
188:                assertEquals("FIRST ROW == 0", 0, s.getFirstRowNum());
189:
190:                // assert((s.getLastRowNum() == 99));
191:            }
192:
193:            public static void main(String[] ignored_args) {
194:                System.out
195:                        .println("Testing org.apache.poi.hssf.usermodel.HSSFCellStyle");
196:                junit.textui.TestRunner.run(TestCellStyle.class);
197:            }
198:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.