Source Code Cross Referenced for TestBugs.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:        package org.apache.poi.hssf.usermodel;
019:
020:        import junit.framework.TestCase;
021:        import org.apache.poi.hssf.util.Region;
022:        import org.apache.poi.util.TempFile;
023:
024:        import java.io.*;
025:        import java.util.Iterator;
026:
027:        /**
028:         * Testcases for bugs entered in bugzilla
029:         * the Test name contains the bugzilla bug id
030:         * @author Avik Sengupta
031:         * @author Yegor Kozlov
032:         */
033:
034:        public class TestBugs extends TestCase {
035:            public TestBugs(String s) {
036:                super (s);
037:            }
038:
039:            /** Test reading AND writing a complicated workbook
040:             *Test opening resulting sheet in excel*/
041:            public void test15228() throws java.io.IOException {
042:                String readFilename = System.getProperty("HSSF.testdata.path");
043:                FileInputStream in = new FileInputStream(readFilename
044:                        + File.separator + "15228.xls");
045:                HSSFWorkbook wb = new HSSFWorkbook(in);
046:                HSSFSheet s = wb.getSheetAt(0);
047:                HSSFRow r = s.createRow(0);
048:                HSSFCell c = r.createCell((short) 0);
049:                c.setCellValue(10);
050:                File file = TempFile.createTempFile("test15228", ".xls");
051:                FileOutputStream out = new FileOutputStream(file);
052:                wb.write(out);
053:                assertTrue("No exception thrown", true);
054:                assertTrue("File Should Exist", file.exists());
055:
056:            }
057:
058:            public void test13796() throws java.io.IOException {
059:                String readFilename = System.getProperty("HSSF.testdata.path");
060:                FileInputStream in = new FileInputStream(readFilename
061:                        + File.separator + "13796.xls");
062:                HSSFWorkbook wb = new HSSFWorkbook(in);
063:                HSSFSheet s = wb.getSheetAt(0);
064:                HSSFRow r = s.createRow(0);
065:                HSSFCell c = r.createCell((short) 0);
066:                c.setCellValue(10);
067:                File file = TempFile.createTempFile("test13796", ".xls");
068:                FileOutputStream out = new FileOutputStream(file);
069:                wb.write(out);
070:                assertTrue("No exception thrown", true);
071:                assertTrue("File Should Exist", file.exists());
072:
073:            }
074:
075:            /**Test writing a hyperlink
076:             * Open resulting sheet in Excel and check that A1 contains a hyperlink*/
077:            public void test23094() throws Exception {
078:                File file = TempFile.createTempFile("test23094", ".xls");
079:                FileOutputStream out = new FileOutputStream(file);
080:                HSSFWorkbook wb = new HSSFWorkbook();
081:                HSSFSheet s = wb.createSheet();
082:                HSSFRow r = s.createRow(0);
083:                r
084:                        .createCell((short) 0)
085:                        .setCellFormula(
086:                                "HYPERLINK( \"http://jakarta.apache.org\", \"Jakarta\" )");
087:                assertTrue("No Exception expected", true);
088:                wb.write(out);
089:                out.close();
090:            }
091:
092:            /* test hyperlinks
093:             * open resulting file in excel, and check that there is a link to Google
094:             **/
095:            public void test15353() throws Exception {
096:                HSSFWorkbook wb = new HSSFWorkbook();
097:                HSSFSheet sheet = wb.createSheet("My sheet");
098:
099:                HSSFRow row = sheet.createRow((short) 0);
100:                HSSFCell cell = row.createCell((short) 0);
101:                cell
102:                        .setCellFormula("HYPERLINK(\"http://google.com\",\"Google\")");
103:
104:                // Write out the workbook
105:                File f = TempFile.createTempFile("test15353", ".xls");
106:                FileOutputStream fileOut = new FileOutputStream(f);
107:                wb.write(fileOut);
108:                fileOut.close();
109:            }
110:
111:            /** test reading of a formula with a name and a cell ref in one
112:             **/
113:            public void test14460() throws Exception {
114:                String filename = System.getProperty("HSSF.testdata.path");
115:                filename = filename + "/14460.xls";
116:                FileInputStream in = new FileInputStream(filename);
117:                HSSFWorkbook wb = new HSSFWorkbook(in);
118:                HSSFSheet sheet = wb.getSheetAt(0);
119:                assertTrue("No exception throws", true);
120:            }
121:
122:            public void test14330() throws Exception {
123:                String filedir = System.getProperty("HSSF.testdata.path");
124:                String filename = filedir + "/14330-1.xls";
125:                FileInputStream in = new FileInputStream(filename);
126:                HSSFWorkbook wb = new HSSFWorkbook(in);
127:                HSSFSheet sheet = wb.getSheetAt(0);
128:
129:                filename = filedir + "/14330-2.xls";
130:                in = new FileInputStream(filename);
131:                wb = new HSSFWorkbook(in);
132:                sheet = wb.getSheetAt(0);
133:                assertTrue("No exception throws", true);
134:            }
135:
136:            /** test rewriting a file with large number of unique strings
137:             *open resulting file in Excel to check results!*/
138:            public void test15375() {
139:                try {
140:                    String filename = System.getProperty("HSSF.testdata.path");
141:                    filename = filename + "/15375.xls";
142:                    FileInputStream in = new FileInputStream(filename);
143:                    HSSFWorkbook wb = new HSSFWorkbook(in);
144:                    HSSFSheet sheet = wb.getSheetAt(0);
145:
146:                    HSSFRow row = sheet.getRow(5);
147:                    HSSFCell cell = row.getCell((short) 3);
148:                    if (cell == null)
149:                        cell = row.createCell((short) 3);
150:
151:                    // Write test
152:                    cell.setCellType(HSSFCell.CELL_TYPE_STRING);
153:                    cell.setCellValue("a test");
154:
155:                    // change existing numeric cell value
156:
157:                    HSSFRow oRow = sheet.getRow(14);
158:                    HSSFCell oCell = oRow.getCell((short) 4);
159:                    oCell.setCellValue(75);
160:                    oCell = oRow.getCell((short) 5);
161:                    oCell.setCellValue("0.3");
162:
163:                    // Write the output to a file
164:                    File f = TempFile.createTempFile("test15375", ".xls");
165:                    FileOutputStream fileOut = new FileOutputStream(f);
166:                    wb.write(fileOut);
167:                    fileOut.close();
168:                } catch (java.io.FileNotFoundException ex) {
169:                    ex.printStackTrace();
170:                } catch (java.io.IOException ex) {
171:                    ex.printStackTrace();
172:                }
173:
174:            }
175:
176:            /** test writing a file with large number of unique strings
177:             *open resulting file in Excel to check results!*/
178:
179:            public void test15375_2() throws Exception {
180:                HSSFWorkbook wb = new HSSFWorkbook();
181:                HSSFSheet sheet = wb.createSheet();
182:
183:                String tmp1 = null;
184:                String tmp2 = null;
185:                String tmp3 = null;
186:
187:                for (int i = 0; i < 6000; i++) {
188:                    tmp1 = "Test1" + i;
189:                    tmp2 = "Test2" + i;
190:                    tmp3 = "Test3" + i;
191:
192:                    HSSFRow row = sheet.createRow((short) i);
193:
194:                    HSSFCell cell = row.createCell((short) 0);
195:                    cell.setCellValue(tmp1);
196:                    cell = row.createCell((short) 1);
197:                    cell.setCellValue(tmp2);
198:                    cell = row.createCell((short) 2);
199:                    cell.setCellValue(tmp3);
200:                }
201:                File f = TempFile.createTempFile("test15375-2", ".xls");
202:                FileOutputStream fileOut = new FileOutputStream(f);
203:                wb.write(fileOut);
204:                fileOut.close();
205:            }
206:
207:            /** another test for the number of unique strings issue
208:             *test opening the resulting file in Excel*/
209:            public void test22568() {
210:                int r = 2000;
211:                int c = 3;
212:
213:                HSSFWorkbook wb = new HSSFWorkbook();
214:                HSSFSheet sheet = wb.createSheet("ExcelTest");
215:
216:                int col_cnt = 0, rw_cnt = 0;
217:
218:                col_cnt = c;
219:                rw_cnt = r;
220:
221:                HSSFRow rw = null;
222:                HSSFCell cell = null;
223:                rw = sheet.createRow((short) 0);
224:                //Header row
225:                for (short j = 0; j < col_cnt; j++) {
226:                    cell = rw.createCell((short) j);
227:                    cell.setCellValue("Col " + (j + 1));
228:                }
229:
230:                for (int i = 1; i < rw_cnt; i++) {
231:                    rw = sheet.createRow((short) i);
232:                    for (short j = 0; j < col_cnt; j++) {
233:                        cell = rw.createCell((short) j);
234:                        cell.setCellValue("Row:" + (i + 1) + ",Column:"
235:                                + (j + 1));
236:                    }
237:                }
238:
239:                sheet.setDefaultColumnWidth((short) 18);
240:
241:                try {
242:                    File f = TempFile.createTempFile("test22568", ".xls");
243:                    FileOutputStream out = new FileOutputStream(f);
244:                    wb.write(out);
245:
246:                    out.close();
247:                } catch (java.io.IOException io_Excp) {
248:                    System.out.println(io_Excp.getMessage());
249:                }
250:            }
251:
252:            /**Double byte strings*/
253:            public void test15556() throws java.io.IOException {
254:
255:                String filename = System.getProperty("HSSF.testdata.path");
256:                filename = filename + "/15556.xls";
257:                FileInputStream in = new FileInputStream(filename);
258:                HSSFWorkbook wb = new HSSFWorkbook(in);
259:                HSSFSheet sheet = wb.getSheetAt(0);
260:                HSSFRow row = sheet.getRow(45);
261:                this .assertTrue("Read row fine!", true);
262:
263:            }
264:
265:            /**Double byte strings */
266:            public void test22742() throws java.io.IOException {
267:                String filename = System.getProperty("HSSF.testdata.path");
268:                filename = filename + "/22742.xls";
269:                FileInputStream in = new FileInputStream(filename);
270:                HSSFWorkbook wb = new HSSFWorkbook(in);
271:                this .assertTrue("Read workbook!", true);
272:
273:            }
274:
275:            /*Double byte strings */
276:            public void test12561_1() throws java.io.IOException {
277:
278:                String filename = System.getProperty("HSSF.testdata.path");
279:                filename = filename + "/12561-1.xls";
280:                FileInputStream in = new FileInputStream(filename);
281:                HSSFWorkbook wb = new HSSFWorkbook(in);
282:                this .assertTrue("Read workbook!", true);
283:
284:            }
285:
286:            /*Double byte strings */
287:            public void test12561_2() throws java.io.IOException {
288:
289:                String filename = System.getProperty("HSSF.testdata.path");
290:                filename = filename + "/12561-2.xls";
291:                FileInputStream in = new FileInputStream(filename);
292:                HSSFWorkbook wb = new HSSFWorkbook(in);
293:                this .assertTrue("Read workbook!", true);
294:
295:            }
296:
297:            /*Double byte strings
298:             File supplied by jubeson*/
299:            public void test12843_1() throws java.io.IOException {
300:                String filename = System.getProperty("HSSF.testdata.path");
301:                filename = filename + "/12843-1.xls";
302:                FileInputStream in = new FileInputStream(filename);
303:                HSSFWorkbook wb = new HSSFWorkbook(in);
304:                this .assertTrue("Read workbook!", true);
305:            }
306:
307:            /*Double byte strings
308:             File supplied by Paul Chung*/
309:            public void test12843_2() throws java.io.IOException {
310:                String filename = System.getProperty("HSSF.testdata.path");
311:                filename = filename + "/12843-2.xls";
312:                FileInputStream in = new FileInputStream(filename);
313:                HSSFWorkbook wb = new HSSFWorkbook(in);
314:                this .assertTrue("Read workbook!", true);
315:            }
316:
317:            /** Reference to Name*/
318:            public void test13224() throws java.io.IOException {
319:                String filename = System.getProperty("HSSF.testdata.path");
320:                filename = filename + "/13224.xls";
321:                FileInputStream in = new FileInputStream(filename);
322:                HSSFWorkbook wb = new HSSFWorkbook(in);
323:                this .assertTrue("Read workbook!", true);
324:
325:            }
326:
327:            /** Illegal argument exception - cannot store duplicate value in Map*/
328:            public void test19599() throws java.io.IOException {
329:                String filename = System.getProperty("HSSF.testdata.path");
330:                FileInputStream in = new FileInputStream(filename
331:                        + "/19599-1.xls");
332:                HSSFWorkbook wb = new HSSFWorkbook(in);
333:                in = new FileInputStream(filename + "/19599-2.xls");
334:                wb = new HSSFWorkbook(in);
335:                this .assertTrue("Read workbook, No exceptions", true);
336:
337:            }
338:
339:            public void test24215() throws Exception {
340:                String filename = System.getProperty("HSSF.testdata.path");
341:                HSSFWorkbook wb = new HSSFWorkbook(new FileInputStream(filename
342:                        + "/24215.xls"));
343:
344:                for (int sheetIndex = 0; sheetIndex < wb.getNumberOfSheets(); sheetIndex++) {
345:                    HSSFSheet sheet = wb.getSheetAt(sheetIndex);
346:                    int rows = sheet.getLastRowNum();
347:
348:                    for (int rowIndex = 0; rowIndex < rows; rowIndex++) {
349:                        HSSFRow row = sheet.getRow(rowIndex);
350:                        int cells = row.getLastCellNum();
351:
352:                        for (short cellIndex = 0; cellIndex < cells; cellIndex++) {
353:                            HSSFCell cell = row.getCell(cellIndex);
354:                        }
355:                    }
356:                }
357:                assertTrue("No Exceptions while reading file", true);
358:            }
359:
360:            public void test18800() throws Exception {
361:                ByteArrayOutputStream out = new ByteArrayOutputStream();
362:                HSSFWorkbook book = new HSSFWorkbook();
363:                book.createSheet("TEST");
364:                HSSFSheet sheet = book.cloneSheet(0);
365:                book.setSheetName(1, "CLONE");
366:                sheet.createRow(0).createCell((short) 0).setCellValue("Test");
367:                book.write(out);
368:
369:                book = new HSSFWorkbook(new ByteArrayInputStream(out
370:                        .toByteArray()));
371:                sheet = book.getSheet("CLONE");
372:                HSSFRow row = sheet.getRow(0);
373:                HSSFCell cell = row.getCell((short) 0);
374:                System.out.println(cell.getStringCellValue());
375:            }
376:
377:            /**
378:             * Merged regions were being removed from the parent in cloned sheets
379:             * @throws Exception
380:             */
381:            public void test22720() throws Exception {
382:                HSSFWorkbook workBook = new HSSFWorkbook();
383:                workBook.createSheet("TEST");
384:                HSSFSheet template = workBook.getSheetAt(0);
385:
386:                template
387:                        .addMergedRegion(new Region(0, (short) 0, 1, (short) 2));
388:                template
389:                        .addMergedRegion(new Region(1, (short) 0, 2, (short) 2));
390:
391:                HSSFSheet clone = workBook.cloneSheet(0);
392:                int originalMerged = template.getNumMergedRegions();
393:                assertEquals("2 merged regions", 2, originalMerged);
394:
395:                //        remove merged regions from clone
396:                for (int i = template.getNumMergedRegions() - 1; i >= 0; i--) {
397:                    clone.removeMergedRegion(i);
398:                }
399:
400:                assertEquals("Original Sheet's Merged Regions were removed",
401:                        originalMerged, template.getNumMergedRegions());
402:                //        check if template's merged regions are OK
403:                if (template.getNumMergedRegions() > 0) {
404:                    // fetch the first merged region...EXCEPTION OCCURS HERE
405:                    template.getMergedRegionAt(0);
406:                }
407:                //make sure we dont exception
408:
409:            }
410:
411:            /*Tests read and write of Unicode strings in formula results
412:             * bug and testcase submitted by Sompop Kumnoonsate
413:             * The file contains THAI unicode characters. 
414:             */
415:            public void testUnicodeStringFormulaRead() throws Exception {
416:
417:                String filename = System.getProperty("HSSF.testdata.path");
418:                filename = filename + "/25695.xls";
419:                FileInputStream in = new FileInputStream(filename);
420:                HSSFWorkbook w;
421:                w = new HSSFWorkbook(in);
422:                in.close();
423:
424:                HSSFCell a1 = w.getSheetAt(0).getRow(0).getCell((short) 0);
425:                HSSFCell a2 = w.getSheetAt(0).getRow(0).getCell((short) 1);
426:                HSSFCell b1 = w.getSheetAt(0).getRow(1).getCell((short) 0);
427:                HSSFCell b2 = w.getSheetAt(0).getRow(1).getCell((short) 1);
428:                HSSFCell c1 = w.getSheetAt(0).getRow(2).getCell((short) 0);
429:                HSSFCell c2 = w.getSheetAt(0).getRow(2).getCell((short) 1);
430:                HSSFCell d1 = w.getSheetAt(0).getRow(3).getCell((short) 0);
431:                HSSFCell d2 = w.getSheetAt(0).getRow(3).getCell((short) 1);
432:
433:                /*     // THAI code page
434:                       System.out.println("a1="+unicodeString(a1.getStringCellValue()));
435:                       System.out.println("a2="+unicodeString(a2.getStringCellValue()));
436:                       // US code page
437:                       System.out.println("b1="+unicodeString(b1.getStringCellValue()));
438:                       System.out.println("b2="+unicodeString(b2.getStringCellValue()));
439:                       // THAI+US
440:                       System.out.println("c1="+unicodeString(c1.getStringCellValue()));
441:                       System.out.println("c2="+unicodeString(c2.getStringCellValue()));
442:                       // US+THAI
443:                       System.out.println("d1="+unicodeString(d1.getStringCellValue()));
444:                       System.out.println("d2="+unicodeString(d2.getStringCellValue()));
445:                 */
446:                assertEquals("String Cell value", a1.getStringCellValue(), a2
447:                        .getStringCellValue());
448:                assertEquals("String Cell value", b1.getStringCellValue(), b2
449:                        .getStringCellValue());
450:                assertEquals("String Cell value", c1.getStringCellValue(), c2
451:                        .getStringCellValue());
452:                assertEquals("String Cell value", d1.getStringCellValue(), d2
453:                        .getStringCellValue());
454:
455:                File xls = TempFile
456:                        .createTempFile("testFormulaUnicode", ".xls");
457:                FileOutputStream out = new FileOutputStream(xls);
458:                w.write(out);
459:                out.close();
460:                in = new FileInputStream(xls);
461:
462:                HSSFWorkbook rw = new HSSFWorkbook(in);
463:                in.close();
464:
465:                HSSFCell ra1 = rw.getSheetAt(0).getRow(0).getCell((short) 0);
466:                HSSFCell ra2 = rw.getSheetAt(0).getRow(0).getCell((short) 1);
467:                HSSFCell rb1 = rw.getSheetAt(0).getRow(1).getCell((short) 0);
468:                HSSFCell rb2 = rw.getSheetAt(0).getRow(1).getCell((short) 1);
469:                HSSFCell rc1 = rw.getSheetAt(0).getRow(2).getCell((short) 0);
470:                HSSFCell rc2 = rw.getSheetAt(0).getRow(2).getCell((short) 1);
471:                HSSFCell rd1 = rw.getSheetAt(0).getRow(3).getCell((short) 0);
472:                HSSFCell rd2 = rw.getSheetAt(0).getRow(3).getCell((short) 1);
473:
474:                assertEquals("Re-Written String Cell value", a1
475:                        .getStringCellValue(), ra1.getStringCellValue());
476:                assertEquals("Re-Written String Cell value", b1
477:                        .getStringCellValue(), rb1.getStringCellValue());
478:                assertEquals("Re-Written String Cell value", c1
479:                        .getStringCellValue(), rc1.getStringCellValue());
480:                assertEquals("Re-Written String Cell value", d1
481:                        .getStringCellValue(), rd1.getStringCellValue());
482:                assertEquals("Re-Written Formula String Cell value", a1
483:                        .getStringCellValue(), ra2.getStringCellValue());
484:                assertEquals("Re-Written Formula String Cell value", b1
485:                        .getStringCellValue(), rb2.getStringCellValue());
486:                assertEquals("Re-Written Formula String Cell value", c1
487:                        .getStringCellValue(), rc2.getStringCellValue());
488:                assertEquals("Re-Written Formula String Cell value", d1
489:                        .getStringCellValue(), rd2.getStringCellValue());
490:
491:            }
492:
493:            private static String unicodeString(String ss) {
494:                char s[] = ss.toCharArray();
495:                java.lang.StringBuffer sb = new java.lang.StringBuffer();
496:                for (int x = 0; x < s.length; x++) {
497:                    sb.append("\\u").append(Integer.toHexString(s[x]));
498:                }
499:                return sb.toString();
500:            }
501:
502:            /** Error in opening wb*/
503:            public void test32822() throws Exception {
504:                String readFilename = System.getProperty("HSSF.testdata.path");
505:                FileInputStream in = new FileInputStream(readFilename
506:                        + File.separator + "32822.xls");
507:                HSSFWorkbook wb = new HSSFWorkbook(in);
508:                assertTrue("No Exceptions while reading file", true);
509:            }
510:
511:            /**fail to read wb with chart */
512:            public void test15573() throws java.io.IOException {
513:                String filename = System.getProperty("HSSF.testdata.path");
514:                filename = filename + "/15573.xls";
515:                FileInputStream in = new FileInputStream(filename);
516:                HSSFWorkbook wb = new HSSFWorkbook(in);
517:                assertTrue("No Exceptions while reading file", true);
518:
519:            }
520:
521:            /**names and macros */
522:            public void test27852() throws java.io.IOException {
523:                String filename = System.getProperty("HSSF.testdata.path");
524:                filename = filename + "/27852.xls";
525:                FileInputStream in = new FileInputStream(filename);
526:                HSSFWorkbook wb = new HSSFWorkbook(in);
527:                assertTrue("No Exceptions while reading file", true);
528:                for (int i = 0; i < wb.getNumberOfNames(); i++) {
529:                    HSSFName name = wb.getNameAt(i);
530:                    name.getNameName();
531:                    name.getReference();
532:                }
533:                assertTrue("No Exceptions till here!", true);
534:            }
535:
536:            public void test33082() throws java.io.IOException {
537:                String filename = System.getProperty("HSSF.testdata.path");
538:                filename = filename + "/33082.xls";
539:                FileInputStream in = new FileInputStream(filename);
540:                HSSFWorkbook wb = new HSSFWorkbook(in);
541:                assertTrue("Read book fine!", true);
542:            }
543:
544:            /*NullPointerException on reading file*/
545:            public void test34775() throws java.io.IOException {
546:                String filename = System.getProperty("HSSF.testdata.path");
547:                filename = filename + "/34775.xls";
548:                FileInputStream in = new FileInputStream(filename);
549:                HSSFWorkbook wb = new HSSFWorkbook(in);
550:                assertTrue("Read book fine!", true);
551:            }
552:
553:            /** Error when reading then writing ArrayValues in NameRecord's*/
554:            public void test37630() throws java.io.IOException {
555:                String filename = System.getProperty("HSSF.testdata.path");
556:                filename = filename + "/37630.xls";
557:                FileInputStream in = new FileInputStream(filename);
558:                HSSFWorkbook wb = new HSSFWorkbook(in);
559:                File file = TempFile.createTempFile("test37630", ".xls");
560:                FileOutputStream out = new FileOutputStream(file);
561:                wb.write(out);
562:
563:                assertTrue("Read book fine!", true);
564:            }
565:
566:            protected String cwd = System.getProperty("HSSF.testdata.path");
567:
568:            /**
569:             * Bug 25183: org.apache.poi.hssf.usermodel.HSSFSheet.setPropertiesFromSheet
570:             */
571:            public void test25183() throws Exception {
572:                FileInputStream in = new FileInputStream(new File(cwd,
573:                        "25183.xls"));
574:                HSSFWorkbook wb = new HSSFWorkbook(in);
575:                in.close();
576:                assertTrue("No Exceptions while reading file", true);
577:
578:                //serialize and read again
579:                ByteArrayOutputStream out = new ByteArrayOutputStream();
580:                wb.write(out);
581:                out.close();
582:
583:                wb = new HSSFWorkbook(new ByteArrayInputStream(out
584:                        .toByteArray()));
585:                assertTrue("No Exceptions while reading file", true);
586:            }
587:
588:            /**
589:             * Bug 26100: 128-character message in IF statement cell causes HSSFWorkbook open failure
590:             */
591:            public void test26100() throws Exception {
592:                FileInputStream in = new FileInputStream(new File(cwd,
593:                        "26100.xls"));
594:                HSSFWorkbook wb = new HSSFWorkbook(in);
595:                in.close();
596:                assertTrue("No Exceptions while reading file", true);
597:
598:                ByteArrayOutputStream out = new ByteArrayOutputStream();
599:                wb.write(out);
600:                out.close();
601:
602:                wb = new HSSFWorkbook(new ByteArrayInputStream(out
603:                        .toByteArray()));
604:                assertTrue("No Exceptions while reading file", true);
605:            }
606:
607:            /**
608:             * Bug 27933: Unable to use a template (xls) file containing a wmf graphic
609:             */
610:            public void test27933() throws Exception {
611:                FileInputStream in = new FileInputStream(new File(cwd,
612:                        "27933.xls"));
613:                HSSFWorkbook wb = new HSSFWorkbook(in);
614:                in.close();
615:                assertTrue("No Exceptions while reading file", true);
616:
617:                //serialize and read again
618:                ByteArrayOutputStream out = new ByteArrayOutputStream();
619:                wb.write(out);
620:                out.close();
621:
622:                wb = new HSSFWorkbook(new ByteArrayInputStream(out
623:                        .toByteArray()));
624:                assertTrue("No Exceptions while reading file", true);
625:            }
626:
627:            /**
628:             * Bug 29206:  	NPE on HSSFSheet.getRow for blank rows
629:             */
630:            public void test29206() throws Exception {
631:                //the first check with blank workbook
632:                HSSFWorkbook wb = new HSSFWorkbook();
633:                HSSFSheet sheet = wb.createSheet();
634:
635:                for (int i = 1; i < 400; i++) {
636:                    HSSFRow row = sheet.getRow(i);
637:                    if (row != null) {
638:                        HSSFCell cell = row.getCell((short) 0);
639:                    }
640:                }
641:
642:                //now check on an existing xls file
643:                FileInputStream in = new FileInputStream(new File(cwd,
644:                        "Simple.xls"));
645:                wb = new HSSFWorkbook(in);
646:                in.close();
647:
648:                for (int i = 1; i < 400; i++) {
649:                    HSSFRow row = sheet.getRow(i);
650:                    if (row != null) {
651:                        HSSFCell cell = row.getCell((short) 0);
652:                    }
653:                }
654:
655:                assertTrue("No Exceptions while reading file", true);
656:            }
657:
658:            /**
659:             * Bug 29675: POI 2.5 final corrupts output when starting workbook has a graphic
660:             */
661:            public void test29675() throws Exception {
662:                FileInputStream in = new FileInputStream(new File(cwd,
663:                        "29675.xls"));
664:                HSSFWorkbook wb = new HSSFWorkbook(in);
665:                in.close();
666:                assertTrue("No Exceptions while reading file", true);
667:
668:                //serialize and read again
669:                ByteArrayOutputStream out = new ByteArrayOutputStream();
670:                wb.write(out);
671:                out.close();
672:
673:                wb = new HSSFWorkbook(new ByteArrayInputStream(out
674:                        .toByteArray()));
675:                assertTrue("No Exceptions while reading file", true);
676:            }
677:
678:            /**
679:             * Bug 29942: Importing Excel files that have been created by Open Office on Linux
680:             */
681:            public void test29942() throws Exception {
682:                FileInputStream in = new FileInputStream(new File(cwd,
683:                        "29942.xls"));
684:                HSSFWorkbook wb = new HSSFWorkbook(in);
685:                in.close();
686:
687:                HSSFSheet sheet = wb.getSheetAt(0);
688:                int count = 0;
689:                for (int i = sheet.getFirstRowNum(); i <= sheet.getLastRowNum(); i++) {
690:                    HSSFRow row = sheet.getRow(i);
691:                    if (row != null) {
692:                        HSSFCell cell = row.getCell((short) 0);
693:                        assertEquals(HSSFCell.CELL_TYPE_STRING, cell
694:                                .getCellType());
695:                        count++;
696:                    }
697:                }
698:                assertEquals(85, count); //should read 85 rows
699:                assertTrue("No Exceptions while reading file", true);
700:
701:                //serialize and read again
702:                ByteArrayOutputStream out = new ByteArrayOutputStream();
703:                wb.write(out);
704:                out.close();
705:
706:                wb = new HSSFWorkbook(new ByteArrayInputStream(out
707:                        .toByteArray()));
708:                assertTrue("No Exceptions while reading file", true);
709:            }
710:
711:            /**
712:             * Bug 29982: Unable to read spreadsheet when dropdown list cell is selected -
713:             *  Unable to construct record instance
714:             */
715:            public void test29982() throws Exception {
716:                FileInputStream in = new FileInputStream(new File(cwd,
717:                        "29982.xls"));
718:                HSSFWorkbook wb = new HSSFWorkbook(in);
719:                in.close();
720:                assertTrue("No Exceptions while reading file", true);
721:
722:                //serialize and read again
723:                ByteArrayOutputStream out = new ByteArrayOutputStream();
724:                wb.write(out);
725:                out.close();
726:
727:                wb = new HSSFWorkbook(new ByteArrayInputStream(out
728:                        .toByteArray()));
729:                assertTrue("No Exceptions while reading file", true);
730:            }
731:
732:            /**
733:             * Bug 30540: HSSFSheet.setRowBreak throws NullPointerException
734:             */
735:            public void test30540() throws Exception {
736:                FileInputStream in = new FileInputStream(new File(cwd,
737:                        "30540.xls"));
738:                HSSFWorkbook wb = new HSSFWorkbook(in);
739:                in.close();
740:
741:                HSSFSheet s = wb.getSheetAt(0);
742:                s.setRowBreak(1);
743:                assertTrue("No Exceptions while reading file", true);
744:
745:                //serialize and read again
746:                ByteArrayOutputStream out = new ByteArrayOutputStream();
747:                wb.write(out);
748:                out.close();
749:
750:                wb = new HSSFWorkbook(new ByteArrayInputStream(out
751:                        .toByteArray()));
752:                assertTrue("No Exceptions while reading file", true);
753:            }
754:
755:            /**
756:             * Bug 31749: {Need help urgently}[This is critical] workbook.write() corrupts the file......?
757:             */
758:            public void test31749() throws Exception {
759:                FileInputStream in = new FileInputStream(new File(cwd,
760:                        "31749.xls"));
761:                HSSFWorkbook wb = new HSSFWorkbook(in);
762:                in.close();
763:                assertTrue("No Exceptions while reading file", true);
764:
765:                //serialize and read again
766:                ByteArrayOutputStream out = new ByteArrayOutputStream();
767:                wb.write(out);
768:                out.close();
769:
770:                wb = new HSSFWorkbook(new ByteArrayInputStream(out
771:                        .toByteArray()));
772:                assertTrue("No Exceptions while reading file", true);
773:            }
774:
775:            /**
776:             * Bug 31979: {urgent help needed .....}poi library does not support form objects properly.
777:             */
778:            public void test31979() throws Exception {
779:                FileInputStream in = new FileInputStream(new File(cwd,
780:                        "31979.xls"));
781:                HSSFWorkbook wb = new HSSFWorkbook(in);
782:                in.close();
783:
784:                assertTrue("No Exceptions while reading file", true);
785:
786:                //serialize and read again
787:                ByteArrayOutputStream out = new ByteArrayOutputStream();
788:                wb.write(out);
789:                out.close();
790:
791:                //wb = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
792:                assertTrue("No Exceptions while reading file", true);
793:
794:            }
795:
796:            /**
797:             * Bug 35564: HSSFCell.java: NullPtrExc in isGridsPrinted() and getProtect()
798:             *  when HSSFWorkbook is created from file
799:             */
800:            public void test35564() throws Exception {
801:                FileInputStream in = new FileInputStream(new File(cwd,
802:                        "35564.xls"));
803:                HSSFWorkbook wb = new HSSFWorkbook(in);
804:                in.close();
805:
806:                HSSFSheet sheet = wb.getSheetAt(0);
807:                assertEquals(false, sheet.isGridsPrinted());
808:                assertEquals(false, sheet.getProtect());
809:
810:                assertTrue("No Exceptions while reading file", true);
811:
812:                //serialize and read again
813:                ByteArrayOutputStream out = new ByteArrayOutputStream();
814:                wb.write(out);
815:                out.close();
816:
817:                wb = new HSSFWorkbook(new ByteArrayInputStream(out
818:                        .toByteArray()));
819:                assertTrue("No Exceptions while reading file", true);
820:
821:            }
822:
823:            /**
824:             * Bug 35565: HSSFCell.java: NullPtrExc in getColumnBreaks() when HSSFWorkbook is created from file
825:             */
826:            public void test35565() throws Exception {
827:                FileInputStream in = new FileInputStream(new File(cwd,
828:                        "35565.xls"));
829:                HSSFWorkbook wb = new HSSFWorkbook(in);
830:                in.close();
831:
832:                HSSFSheet sheet = wb.getSheetAt(0);
833:                assertNotNull(sheet);
834:
835:                assertTrue("No Exceptions while reading file", true);
836:
837:                //serialize and read again
838:                ByteArrayOutputStream out = new ByteArrayOutputStream();
839:                wb.write(out);
840:                out.close();
841:
842:                wb = new HSSFWorkbook(new ByteArrayInputStream(out
843:                        .toByteArray()));
844:                assertTrue("No Exceptions while reading file", true);
845:
846:            }
847:
848:            /**
849:             * Bug 37376: Cannot open the saved Excel file if checkbox controls exceed certain limit
850:             */
851:            public void test37376() throws Exception {
852:                FileInputStream in = new FileInputStream(new File(cwd,
853:                        "37376.xls"));
854:                HSSFWorkbook wb = new HSSFWorkbook(in);
855:                in.close();
856:
857:                assertTrue("No Exceptions while reading file", true);
858:
859:                //serialize and read again
860:                ByteArrayOutputStream out = new ByteArrayOutputStream();
861:                wb.write(out);
862:                out.close();
863:
864:                wb = new HSSFWorkbook(new ByteArrayInputStream(out
865:                        .toByteArray()));
866:                assertTrue("No Exceptions while reading file", true);
867:
868:            }
869:
870:            /**
871:             * Bug 40285:  	CellIterator Skips First Column
872:             */
873:            public void test40285() throws Exception {
874:                FileInputStream in = new FileInputStream(new File(cwd,
875:                        "40285.xls"));
876:                HSSFWorkbook wb = new HSSFWorkbook(in);
877:                in.close();
878:
879:                HSSFSheet sheet = wb.getSheetAt(0);
880:                int rownum = 0;
881:                for (Iterator it = sheet.rowIterator(); it.hasNext(); rownum++) {
882:                    HSSFRow row = (HSSFRow) it.next();
883:                    assertEquals(rownum, row.getRowNum());
884:                    int cellNum = 0;
885:                    for (Iterator it2 = row.cellIterator(); it2.hasNext(); cellNum++) {
886:                        HSSFCell cell = (HSSFCell) it2.next();
887:                        assertEquals(cellNum, cell.getCellNum());
888:                    }
889:                }
890:            }
891:
892:            /**
893:             * Bug 40296:  	HSSFCell.setCellFormula throws
894:             *   ClassCastException if cell is created using HSSFRow.createCell(short column, int type)
895:             */
896:            public void test40296() throws Exception {
897:                HSSFWorkbook wb = new HSSFWorkbook();
898:
899:                HSSFWorkbook workBook = new HSSFWorkbook();
900:                HSSFSheet workSheet = workBook.createSheet("Sheet1");
901:                HSSFCell cell;
902:                HSSFRow row;
903:
904:                row = workSheet.createRow(0);
905:                cell = row.createCell((short) 0, HSSFCell.CELL_TYPE_NUMERIC);
906:                cell.setCellValue(1.0);
907:                cell = row.createCell((short) 1, HSSFCell.CELL_TYPE_NUMERIC);
908:                cell.setCellValue(2.0);
909:                cell = row.createCell((short) 2, HSSFCell.CELL_TYPE_FORMULA);
910:                cell.setCellFormula("SUM(A1:B1)");
911:
912:                //serialize and read again
913:                ByteArrayOutputStream out = new ByteArrayOutputStream();
914:                wb.write(out);
915:                out.close();
916:
917:                wb = new HSSFWorkbook(new ByteArrayInputStream(out
918:                        .toByteArray()));
919:                assertTrue("No Exceptions while reading file", true);
920:            }
921:
922:            /**
923:             * Test bug 38266: NPE when adding a row break
924:             *
925:             * User's diagnosis:
926:             * 1. Manually (i.e., not using POI) create an Excel Workbook, making sure it
927:             * contains a sheet that doesn't have any row breaks
928:             * 2. Using POI, create a new HSSFWorkbook from the template in step #1
929:             * 3. Try adding a row break (via sheet.setRowBreak()) to the sheet mentioned in step #1
930:             * 4. Get a NullPointerException
931:             */
932:            public void test38266() throws Exception {
933:                String[] files = { "Simple.xls", "SimpleMultiCell.xls",
934:                        "duprich1.xls" };
935:                for (int i = 0; i < files.length; i++) {
936:                    FileInputStream in = new FileInputStream(new File(cwd,
937:                            files[i]));
938:                    HSSFWorkbook wb = new HSSFWorkbook(in);
939:                    in.close();
940:
941:                    HSSFSheet sheet = wb.getSheetAt(0);
942:                    int[] breaks = sheet.getRowBreaks();
943:                    assertNull(breaks);
944:
945:                    //add 3 row breaks
946:                    for (int j = 1; j <= 3; j++) {
947:                        sheet.setRowBreak(j * 20);
948:                    }
949:
950:                    assertTrue("No Exceptions while adding row breaks in "
951:                            + files[i], true);
952:                }
953:            }
954:
955:            public void test40738() throws Exception {
956:                FileInputStream in = new FileInputStream(new File(cwd,
957:                        "SimpleWithAutofilter.xls"));
958:                HSSFWorkbook wb = new HSSFWorkbook(in);
959:                in.close();
960:
961:                //serialize and read again
962:                ByteArrayOutputStream out = new ByteArrayOutputStream();
963:                wb.write(out);
964:                out.close();
965:
966:                wb = new HSSFWorkbook(new ByteArrayInputStream(out
967:                        .toByteArray()));
968:                assertTrue("No Exceptions while reading file", true);
969:
970:            }
971:
972:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.