Add a test to show the bug #42618 appears to be incorrect
[poi.git] / src / testcases / org / apache / poi / hssf / usermodel / TestBugs.java
blob824715bf24ed69b4c12ef526f766f6a1dbec696c
2 /* ====================================================================
3 Licensed to the Apache Software Foundation (ASF) under one or more
4 contributor license agreements. See the NOTICE file distributed with
5 this work for additional information regarding copyright ownership.
6 The ASF licenses this file to You under the Apache License, Version 2.0
7 (the "License"); you may not use this file except in compliance with
8 the License. You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17 ==================================================================== */
20 package org.apache.poi.hssf.usermodel;
22 import junit.framework.TestCase;
23 import org.apache.poi.hssf.util.Region;
24 import org.apache.poi.util.TempFile;
26 import java.io.*;
27 import java.util.Iterator;
31 /**
32 * Testcases for bugs entered in bugzilla
33 * the Test name contains the bugzilla bug id
34 * @author Avik Sengupta
35 * @author Yegor Kozlov
38 public class TestBugs
39 extends TestCase {
40 public TestBugs(String s) {
41 super(s);
44 /** Test reading AND writing a complicated workbook
45 *Test opening resulting sheet in excel*/
46 public void test15228()
47 throws java.io.IOException {
48 String readFilename = System.getProperty("HSSF.testdata.path");
49 FileInputStream in = new FileInputStream(readFilename+File.separator+"15228.xls");
50 HSSFWorkbook wb = new HSSFWorkbook(in);
51 HSSFSheet s = wb.getSheetAt(0);
52 HSSFRow r = s.createRow(0);
53 HSSFCell c = r.createCell((short)0);
54 c.setCellValue(10);
55 File file = TempFile.createTempFile("test15228",".xls");
56 FileOutputStream out = new FileOutputStream(file);
57 wb.write(out);
58 assertTrue("No exception thrown", true);
59 assertTrue("File Should Exist", file.exists());
63 public void test13796()
64 throws java.io.IOException {
65 String readFilename = System.getProperty("HSSF.testdata.path");
66 FileInputStream in = new FileInputStream(readFilename+File.separator+"13796.xls");
67 HSSFWorkbook wb = new HSSFWorkbook(in);
68 HSSFSheet s = wb.getSheetAt(0);
69 HSSFRow r = s.createRow(0);
70 HSSFCell c = r.createCell((short)0);
71 c.setCellValue(10);
72 File file = TempFile.createTempFile("test13796",".xls");
73 FileOutputStream out = new FileOutputStream(file);
74 wb.write(out);
75 assertTrue("No exception thrown", true);
76 assertTrue("File Should Exist", file.exists());
79 /**Test writing a hyperlink
80 * Open resulting sheet in Excel and check that A1 contains a hyperlink*/
81 public void test23094() throws Exception {
82 File file = TempFile.createTempFile("test23094",".xls");
83 FileOutputStream out = new FileOutputStream(file);
84 HSSFWorkbook wb = new HSSFWorkbook();
85 HSSFSheet s = wb.createSheet();
86 HSSFRow r = s.createRow(0);
87 r.createCell((short)0).setCellFormula("HYPERLINK( \"http://jakarta.apache.org\", \"Jakarta\" )");
88 assertTrue("No Exception expected",true);
89 wb.write(out);
90 out.close();
93 /* test hyperlinks
94 * open resulting file in excel, and check that there is a link to Google
95 **/
96 public void test15353() throws Exception {
97 HSSFWorkbook wb = new HSSFWorkbook();
98 HSSFSheet sheet = wb.createSheet("My sheet");
100 HSSFRow row = sheet.createRow( (short) 0 );
101 HSSFCell cell = row.createCell( (short) 0 );
102 cell.setCellFormula("HYPERLINK(\"http://google.com\",\"Google\")");
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();
111 /** test reading of a formula with a name and a cell ref in one
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);
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);
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);
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);
146 HSSFRow row = sheet.getRow(5);
147 HSSFCell cell = row.getCell((short)3);
148 if (cell == null)
149 cell = row.createCell((short)3);
151 // Write test
152 cell.setCellType(HSSFCell.CELL_TYPE_STRING);
153 cell.setCellValue("a test");
155 // change existing numeric cell value
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");
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();
169 catch (java.io.FileNotFoundException ex) {
170 ex.printStackTrace();
172 catch (java.io.IOException ex) {
173 ex.printStackTrace();
178 /** test writing a file with large number of unique strings
179 *open resulting file in Excel to check results!*/
181 public void test15375_2() throws Exception{
182 HSSFWorkbook wb = new HSSFWorkbook();
183 HSSFSheet sheet = wb.createSheet();
185 String tmp1 = null;
186 String tmp2 = null;
187 String tmp3 = null;
189 for (int i = 0; i < 6000; i++) {
190 tmp1 = "Test1" + i;
191 tmp2 = "Test2" + i;
192 tmp3 = "Test3" + i;
194 HSSFRow row = sheet.createRow((short)i);
196 HSSFCell cell = row.createCell((short)0);
197 cell.setCellValue(tmp1);
198 cell = row.createCell((short)1);
199 cell.setCellValue(tmp2);
200 cell = row.createCell((short)2);
201 cell.setCellValue(tmp3);
203 File f = TempFile.createTempFile("test15375-2",".xls");
204 FileOutputStream fileOut = new FileOutputStream(f);
205 wb.write(fileOut);
206 fileOut.close();
208 /** another test for the number of unique strings issue
209 *test opening the resulting file in Excel*/
210 public void test22568() {
211 int r=2000;int c=3;
213 HSSFWorkbook wb = new HSSFWorkbook() ;
214 HSSFSheet sheet = wb.createSheet("ExcelTest") ;
216 int col_cnt=0, rw_cnt=0 ;
218 col_cnt = c;
219 rw_cnt = r;
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)) ;
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)) ;
239 sheet.setDefaultColumnWidth((short) 18) ;
241 try {
242 File f = TempFile.createTempFile("test22568",".xls");
243 FileOutputStream out = new FileOutputStream(f) ;
244 wb.write(out) ;
246 out.close() ;
248 catch(java.io.IOException io_Excp) {
249 System.out.println(io_Excp.getMessage()) ;
253 /**Double byte strings*/
254 public void test15556() throws java.io.IOException {
256 String filename = System.getProperty("HSSF.testdata.path");
257 filename=filename+"/15556.xls";
258 FileInputStream in = new FileInputStream(filename);
259 HSSFWorkbook wb = new HSSFWorkbook(in);
260 HSSFSheet sheet = wb.getSheetAt(0);
261 HSSFRow row = sheet.getRow(45);
262 this.assertTrue("Read row fine!" , true);
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); this.assertTrue("Read workbook!" , true);
273 /*Double byte strings */
274 public void test12561_1() throws java.io.IOException {
276 String filename = System.getProperty("HSSF.testdata.path");
277 filename=filename+"/12561-1.xls";
278 FileInputStream in = new FileInputStream(filename);
279 HSSFWorkbook wb = new HSSFWorkbook(in);
280 this.assertTrue("Read workbook!" , true);
283 /*Double byte strings */
284 public void test12561_2() throws java.io.IOException {
286 String filename = System.getProperty("HSSF.testdata.path");
287 filename=filename+"/12561-2.xls";
288 FileInputStream in = new FileInputStream(filename);
289 HSSFWorkbook wb = new HSSFWorkbook(in);
290 this.assertTrue("Read workbook!" , true);
293 /*Double byte strings
294 File supplied by jubeson*/
295 public void test12843_1() throws java.io.IOException {
296 String filename = System.getProperty("HSSF.testdata.path");
297 filename=filename+"/12843-1.xls";
298 FileInputStream in = new FileInputStream(filename);
299 HSSFWorkbook wb = new HSSFWorkbook(in);
300 this.assertTrue("Read workbook!" , true);
303 /*Double byte strings
304 File supplied by Paul Chung*/
305 public void test12843_2() throws java.io.IOException {
306 String filename = System.getProperty("HSSF.testdata.path");
307 filename=filename+"/12843-2.xls";
308 FileInputStream in = new FileInputStream(filename);
309 HSSFWorkbook wb = new HSSFWorkbook(in);
310 this.assertTrue("Read workbook!" , true);
313 /** Reference to Name*/
314 public void test13224() throws java.io.IOException {
315 String filename = System.getProperty("HSSF.testdata.path");
316 filename=filename+"/13224.xls";
317 FileInputStream in = new FileInputStream(filename);
318 HSSFWorkbook wb = new HSSFWorkbook(in);
319 this.assertTrue("Read workbook!" , true);
323 /** Illegal argument exception - cannot store duplicate value in Map*/
324 public void test19599() throws java.io.IOException {
325 String filename = System.getProperty("HSSF.testdata.path");
326 FileInputStream in = new FileInputStream(filename+"/19599-1.xls");
327 HSSFWorkbook wb = new HSSFWorkbook(in);
328 in = new FileInputStream(filename+"/19599-2.xls");
329 wb = new HSSFWorkbook(in);
330 this.assertTrue("Read workbook, No exceptions" , true);
334 public void test24215() throws Exception {
335 String filename = System.getProperty("HSSF.testdata.path");
336 HSSFWorkbook wb = new HSSFWorkbook(new FileInputStream(filename+"/24215.xls"));
338 for (int sheetIndex = 0; sheetIndex < wb.getNumberOfSheets();sheetIndex++) {
339 HSSFSheet sheet = wb.getSheetAt(sheetIndex);
340 int rows = sheet.getLastRowNum();
342 for (int rowIndex = 0; rowIndex < rows; rowIndex++) {
343 HSSFRow row = sheet.getRow(rowIndex);
344 int cells = row.getLastCellNum();
346 for (short cellIndex = 0; cellIndex < cells; cellIndex++) {
347 HSSFCell cell = row.getCell(cellIndex);
351 assertTrue("No Exceptions while reading file", true);
354 public void test18800() throws Exception {
355 ByteArrayOutputStream out = new ByteArrayOutputStream();
356 HSSFWorkbook book = new HSSFWorkbook();
357 book.createSheet("TEST");
358 HSSFSheet sheet = book.cloneSheet(0);
359 book.setSheetName(1,"CLONE");
360 sheet.createRow(0).createCell((short)0).setCellValue("Test");
361 book.write(out);
363 book = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
364 sheet = book.getSheet("CLONE");
365 HSSFRow row = sheet.getRow(0);
366 HSSFCell cell = row.getCell((short)0);
367 System.out.println(cell.getStringCellValue());
371 * Merged regions were being removed from the parent in cloned sheets
372 * @throws Exception
374 public void test22720() throws Exception {
375 HSSFWorkbook workBook = new HSSFWorkbook();
376 workBook.createSheet("TEST");
377 HSSFSheet template = workBook.getSheetAt(0);
379 template.addMergedRegion(new Region(0, (short)0, 1, (short)2));
380 template.addMergedRegion(new Region(1, (short)0, 2, (short)2));
382 HSSFSheet clone = workBook.cloneSheet(0);
383 int originalMerged = template.getNumMergedRegions();
384 assertEquals("2 merged regions", 2, originalMerged);
386 // remove merged regions from clone
387 for (int i=template.getNumMergedRegions()-1; i>=0; i--) {
388 clone.removeMergedRegion(i);
391 assertEquals("Original Sheet's Merged Regions were removed", originalMerged, template.getNumMergedRegions());
392 // check if template's merged regions are OK
393 if (template.getNumMergedRegions()>0) {
394 // fetch the first merged region...EXCEPTION OCCURS HERE
395 template.getMergedRegionAt(0);
397 //make sure we dont exception
401 /*Tests read and write of Unicode strings in formula results
402 * bug and testcase submitted by Sompop Kumnoonsate
403 * The file contains THAI unicode characters.
405 public void testUnicodeStringFormulaRead() throws Exception {
407 String filename = System.getProperty("HSSF.testdata.path");
408 filename=filename+"/25695.xls";
409 FileInputStream in = new FileInputStream(filename);
410 HSSFWorkbook w;
411 w = new HSSFWorkbook(in);
412 in.close();
414 HSSFCell a1 = w.getSheetAt(0).getRow(0).getCell((short) 0);
415 HSSFCell a2 = w.getSheetAt(0).getRow(0).getCell((short) 1);
416 HSSFCell b1 = w.getSheetAt(0).getRow(1).getCell((short) 0);
417 HSSFCell b2 = w.getSheetAt(0).getRow(1).getCell((short) 1);
418 HSSFCell c1 = w.getSheetAt(0).getRow(2).getCell((short) 0);
419 HSSFCell c2 = w.getSheetAt(0).getRow(2).getCell((short) 1);
420 HSSFCell d1 = w.getSheetAt(0).getRow(3).getCell((short) 0);
421 HSSFCell d2 = w.getSheetAt(0).getRow(3).getCell((short) 1);
423 /* // THAI code page
424 System.out.println("a1="+unicodeString(a1.getStringCellValue()));
425 System.out.println("a2="+unicodeString(a2.getStringCellValue()));
426 // US code page
427 System.out.println("b1="+unicodeString(b1.getStringCellValue()));
428 System.out.println("b2="+unicodeString(b2.getStringCellValue()));
429 // THAI+US
430 System.out.println("c1="+unicodeString(c1.getStringCellValue()));
431 System.out.println("c2="+unicodeString(c2.getStringCellValue()));
432 // US+THAI
433 System.out.println("d1="+unicodeString(d1.getStringCellValue()));
434 System.out.println("d2="+unicodeString(d2.getStringCellValue()));
436 assertEquals("String Cell value", a1.getStringCellValue(), a2.getStringCellValue());
437 assertEquals("String Cell value", b1.getStringCellValue(), b2.getStringCellValue());
438 assertEquals("String Cell value", c1.getStringCellValue(), c2.getStringCellValue());
439 assertEquals("String Cell value", d1.getStringCellValue(), d2.getStringCellValue());
441 File xls = TempFile.createTempFile("testFormulaUnicode", ".xls");
442 FileOutputStream out = new FileOutputStream(xls);
443 w.write(out);
444 out.close();
445 in = new FileInputStream(xls);
447 HSSFWorkbook rw = new HSSFWorkbook(in);
448 in.close();
450 HSSFCell ra1 = rw.getSheetAt(0).getRow(0).getCell((short) 0);
451 HSSFCell ra2 = rw.getSheetAt(0).getRow(0).getCell((short) 1);
452 HSSFCell rb1 = rw.getSheetAt(0).getRow(1).getCell((short) 0);
453 HSSFCell rb2 = rw.getSheetAt(0).getRow(1).getCell((short) 1);
454 HSSFCell rc1 = rw.getSheetAt(0).getRow(2).getCell((short) 0);
455 HSSFCell rc2 = rw.getSheetAt(0).getRow(2).getCell((short) 1);
456 HSSFCell rd1 = rw.getSheetAt(0).getRow(3).getCell((short) 0);
457 HSSFCell rd2 = rw.getSheetAt(0).getRow(3).getCell((short) 1);
459 assertEquals("Re-Written String Cell value", a1.getStringCellValue(), ra1.getStringCellValue());
460 assertEquals("Re-Written String Cell value", b1.getStringCellValue(), rb1.getStringCellValue());
461 assertEquals("Re-Written String Cell value", c1.getStringCellValue(), rc1.getStringCellValue());
462 assertEquals("Re-Written String Cell value", d1.getStringCellValue(), rd1.getStringCellValue());
463 assertEquals("Re-Written Formula String Cell value", a1.getStringCellValue(), ra2.getStringCellValue());
464 assertEquals("Re-Written Formula String Cell value", b1.getStringCellValue(), rb2.getStringCellValue());
465 assertEquals("Re-Written Formula String Cell value", c1.getStringCellValue(), rc2.getStringCellValue());
466 assertEquals("Re-Written Formula String Cell value", d1.getStringCellValue(), rd2.getStringCellValue());
470 private static String unicodeString(String ss) {
471 char s[] = ss.toCharArray();
472 java.lang.StringBuffer sb=new java.lang.StringBuffer();
473 for (int x=0;x<s.length;x++) {
474 sb.append("\\u").append(Integer.toHexString(s[x]));
476 return sb.toString();
479 /** Error in opening wb*/
480 public void test32822() throws Exception{
481 String readFilename = System.getProperty("HSSF.testdata.path");
482 FileInputStream in = new FileInputStream(readFilename+File.separator+"32822.xls");
483 HSSFWorkbook wb = new HSSFWorkbook(in);
484 assertTrue("No Exceptions while reading file", true);
486 /**fail to read wb with chart */
487 public void test15573() throws java.io.IOException {
488 String filename = System.getProperty("HSSF.testdata.path");
489 filename=filename+"/15573.xls";
490 FileInputStream in = new FileInputStream(filename);
491 HSSFWorkbook wb = new HSSFWorkbook(in);
492 assertTrue("No Exceptions while reading file", true);
496 /**names and macros */
497 public void test27852() throws java.io.IOException {
498 String filename = System.getProperty("HSSF.testdata.path");
499 filename=filename+"/27852.xls";
500 FileInputStream in = new FileInputStream(filename);
501 HSSFWorkbook wb = new HSSFWorkbook(in);
502 assertTrue("No Exceptions while reading file", true);
503 for(int i = 0 ; i < wb.getNumberOfNames() ; i++)
505 HSSFName name = wb.getNameAt(i);
506 name.getNameName();
507 name.getReference();
509 assertTrue("No Exceptions till here!", true);
512 public void test33082() throws java.io.IOException {
513 String filename = System.getProperty("HSSF.testdata.path");
514 filename=filename+"/33082.xls";
515 FileInputStream in = new FileInputStream(filename);
516 HSSFWorkbook wb = new HSSFWorkbook(in);
517 assertTrue("Read book fine!" , true);
520 /*NullPointerException on reading file*/
521 public void test34775() throws java.io.IOException {
522 String filename = System.getProperty("HSSF.testdata.path");
523 filename=filename+"/34775.xls";
524 FileInputStream in = new FileInputStream(filename);
525 HSSFWorkbook wb = new HSSFWorkbook(in);
526 assertTrue("Read book fine!" , true);
529 /** Error when reading then writing ArrayValues in NameRecord's*/
530 public void test37630() throws java.io.IOException {
531 String filename = System.getProperty("HSSF.testdata.path");
532 filename=filename+"/37630.xls";
533 FileInputStream in = new FileInputStream(filename);
534 HSSFWorkbook wb = new HSSFWorkbook(in);
535 File file = TempFile.createTempFile("test37630",".xls");
536 FileOutputStream out = new FileOutputStream(file);
537 wb.write(out);
539 assertTrue("Read book fine!" , true);
542 protected String cwd = System.getProperty("HSSF.testdata.path");
545 * Bug 25183: org.apache.poi.hssf.usermodel.HSSFSheet.setPropertiesFromSheet
547 public void test25183() throws Exception {
548 FileInputStream in = new FileInputStream(new File(cwd, "25183.xls"));
549 HSSFWorkbook wb = new HSSFWorkbook(in);
550 in.close();
551 assertTrue("No Exceptions while reading file", true);
553 //serialize and read again
554 ByteArrayOutputStream out = new ByteArrayOutputStream();
555 wb.write(out);
556 out.close();
558 wb = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
559 assertTrue("No Exceptions while reading file", true);
563 * Bug 26100: 128-character message in IF statement cell causes HSSFWorkbook open failure
565 public void test26100() throws Exception {
566 FileInputStream in = new FileInputStream(new File(cwd, "26100.xls"));
567 HSSFWorkbook wb = new HSSFWorkbook(in);
568 in.close();
569 assertTrue("No Exceptions while reading file", true);
571 ByteArrayOutputStream out = new ByteArrayOutputStream();
572 wb.write(out);
573 out.close();
575 wb = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
576 assertTrue("No Exceptions while reading file", true);
580 * Bug 27933: Unable to use a template (xls) file containing a wmf graphic
582 public void test27933() throws Exception {
583 FileInputStream in = new FileInputStream(new File(cwd, "27933.xls"));
584 HSSFWorkbook wb = new HSSFWorkbook(in);
585 in.close();
586 assertTrue("No Exceptions while reading file", true);
588 //serialize and read again
589 ByteArrayOutputStream out = new ByteArrayOutputStream();
590 wb.write(out);
591 out.close();
593 wb = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
594 assertTrue("No Exceptions while reading file", true);
598 * Bug 29206: NPE on HSSFSheet.getRow for blank rows
600 public void test29206() throws Exception {
601 //the first check with blank workbook
602 HSSFWorkbook wb = new HSSFWorkbook();
603 HSSFSheet sheet = wb.createSheet();
605 for(int i = 1; i < 400; i++) {
606 HSSFRow row = sheet.getRow(i);
607 if(row != null) {
608 HSSFCell cell = row.getCell((short)0);
612 //now check on an existing xls file
613 FileInputStream in = new FileInputStream(new File(cwd, "Simple.xls"));
614 wb = new HSSFWorkbook(in);
615 in.close();
617 for(int i = 1; i < 400; i++) {
618 HSSFRow row = sheet.getRow(i);
619 if(row != null) {
620 HSSFCell cell = row.getCell((short)0);
624 assertTrue("No Exceptions while reading file", true);
628 * Bug 29675: POI 2.5 final corrupts output when starting workbook has a graphic
630 public void test29675() throws Exception {
631 FileInputStream in = new FileInputStream(new File(cwd, "29675.xls"));
632 HSSFWorkbook wb = new HSSFWorkbook(in);
633 in.close();
634 assertTrue("No Exceptions while reading file", true);
636 //serialize and read again
637 ByteArrayOutputStream out = new ByteArrayOutputStream();
638 wb.write(out);
639 out.close();
641 wb = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
642 assertTrue("No Exceptions while reading file", true);
646 * Bug 29942: Importing Excel files that have been created by Open Office on Linux
648 public void test29942() throws Exception {
649 FileInputStream in = new FileInputStream(new File(cwd, "29942.xls"));
650 HSSFWorkbook wb = new HSSFWorkbook(in);
651 in.close();
653 HSSFSheet sheet = wb.getSheetAt(0);
654 int count = 0;
655 for (int i = sheet.getFirstRowNum(); i <= sheet.getLastRowNum(); i++) {
656 HSSFRow row = sheet.getRow(i);
657 if (row != null) {
658 HSSFCell cell = row .getCell((short)0);
659 assertEquals(HSSFCell.CELL_TYPE_STRING, cell.getCellType());
660 count++;
663 assertEquals(85, count); //should read 85 rows
664 assertTrue("No Exceptions while reading file", true);
666 //serialize and read again
667 ByteArrayOutputStream out = new ByteArrayOutputStream();
668 wb.write(out);
669 out.close();
671 wb = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
672 assertTrue("No Exceptions while reading file", true);
676 * Bug 29982: Unable to read spreadsheet when dropdown list cell is selected -
677 * Unable to construct record instance
679 public void test29982() throws Exception {
680 FileInputStream in = new FileInputStream(new File(cwd, "29982.xls"));
681 HSSFWorkbook wb = new HSSFWorkbook(in);
682 in.close();
683 assertTrue("No Exceptions while reading file", true);
685 //serialize and read again
686 ByteArrayOutputStream out = new ByteArrayOutputStream();
687 wb.write(out);
688 out.close();
690 wb = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
691 assertTrue("No Exceptions while reading file", true);
695 * Bug 30540: HSSFSheet.setRowBreak throws NullPointerException
697 public void test30540() throws Exception {
698 FileInputStream in = new FileInputStream(new File(cwd, "30540.xls"));
699 HSSFWorkbook wb = new HSSFWorkbook(in);
700 in.close();
702 HSSFSheet s = wb.getSheetAt(0);
703 s.setRowBreak(1);
704 assertTrue("No Exceptions while reading file", true);
706 //serialize and read again
707 ByteArrayOutputStream out = new ByteArrayOutputStream();
708 wb.write(out);
709 out.close();
711 wb = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
712 assertTrue("No Exceptions while reading file", true);
716 * Bug 31749: {Need help urgently}[This is critical] workbook.write() corrupts the file......?
718 public void test31749() throws Exception {
719 FileInputStream in = new FileInputStream(new File(cwd, "31749.xls"));
720 HSSFWorkbook wb = new HSSFWorkbook(in);
721 in.close();
722 assertTrue("No Exceptions while reading file", true);
724 //serialize and read again
725 ByteArrayOutputStream out = new ByteArrayOutputStream();
726 wb.write(out);
727 out.close();
729 wb = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
730 assertTrue("No Exceptions while reading file", true);
734 * Bug 31979: {urgent help needed .....}poi library does not support form objects properly.
736 public void test31979() throws Exception {
737 FileInputStream in = new FileInputStream(new File(cwd, "31979.xls"));
738 HSSFWorkbook wb = new HSSFWorkbook(in);
739 in.close();
741 assertTrue("No Exceptions while reading file", true);
743 //serialize and read again
744 ByteArrayOutputStream out = new ByteArrayOutputStream();
745 wb.write(out);
746 out.close();
748 //wb = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
749 assertTrue("No Exceptions while reading file", true);
754 * Bug 35564: HSSFCell.java: NullPtrExc in isGridsPrinted() and getProtect()
755 * when HSSFWorkbook is created from file
757 public void test35564() throws Exception {
758 FileInputStream in = new FileInputStream(new File(cwd, "35564.xls"));
759 HSSFWorkbook wb = new HSSFWorkbook(in);
760 in.close();
762 HSSFSheet sheet = wb.getSheetAt( 0 );
763 assertEquals(false, sheet.isGridsPrinted());
764 assertEquals(false, sheet.getProtect());
766 assertTrue("No Exceptions while reading file", true);
768 //serialize and read again
769 ByteArrayOutputStream out = new ByteArrayOutputStream();
770 wb.write(out);
771 out.close();
773 wb = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
774 assertTrue("No Exceptions while reading file", true);
779 * Bug 35565: HSSFCell.java: NullPtrExc in getColumnBreaks() when HSSFWorkbook is created from file
781 public void test35565() throws Exception {
782 FileInputStream in = new FileInputStream(new File(cwd, "35565.xls"));
783 HSSFWorkbook wb = new HSSFWorkbook(in);
784 in.close();
786 HSSFSheet sheet = wb.getSheetAt( 0 );
787 assertNotNull(sheet);
789 assertTrue("No Exceptions while reading file", true);
791 //serialize and read again
792 ByteArrayOutputStream out = new ByteArrayOutputStream();
793 wb.write(out);
794 out.close();
796 wb = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
797 assertTrue("No Exceptions while reading file", true);
802 * Bug 37376: Cannot open the saved Excel file if checkbox controls exceed certain limit
804 public void test37376() throws Exception {
805 FileInputStream in = new FileInputStream(new File(cwd, "37376.xls"));
806 HSSFWorkbook wb = new HSSFWorkbook(in);
807 in.close();
809 assertTrue("No Exceptions while reading file", true);
811 //serialize and read again
812 ByteArrayOutputStream out = new ByteArrayOutputStream();
813 wb.write(out);
814 out.close();
816 wb = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
817 assertTrue("No Exceptions while reading file", true);
822 * Bug 40285: CellIterator Skips First Column
824 public void test40285() throws Exception {
825 FileInputStream in = new FileInputStream(new File(cwd, "40285.xls"));
826 HSSFWorkbook wb = new HSSFWorkbook(in);
827 in.close();
829 HSSFSheet sheet = wb.getSheetAt( 0 );
830 int rownum = 0;
831 for (Iterator it = sheet.rowIterator(); it.hasNext(); rownum++) {
832 HSSFRow row = (HSSFRow)it.next();
833 assertEquals(rownum, row.getRowNum());
834 int cellNum = 0;
835 for (Iterator it2 = row.cellIterator(); it2.hasNext(); cellNum++) {
836 HSSFCell cell = (HSSFCell)it2.next();
837 assertEquals(cellNum, cell.getCellNum());
843 * Bug 40296: HSSFCell.setCellFormula throws
844 * ClassCastException if cell is created using HSSFRow.createCell(short column, int type)
846 public void test40296() throws Exception {
847 HSSFWorkbook wb = new HSSFWorkbook();
849 HSSFWorkbook workBook = new HSSFWorkbook();
850 HSSFSheet workSheet = workBook.createSheet("Sheet1");
851 HSSFCell cell;
852 HSSFRow row;
854 row = workSheet.createRow(0);
855 cell = row.createCell((short)0, HSSFCell.CELL_TYPE_NUMERIC);
856 cell.setCellValue(1.0);
857 cell = row.createCell((short)1, HSSFCell.CELL_TYPE_NUMERIC);
858 cell.setCellValue(2.0);
859 cell = row.createCell((short)2, HSSFCell.CELL_TYPE_FORMULA);
860 cell.setCellFormula("SUM(A1:B1)");
862 //serialize and read again
863 ByteArrayOutputStream out = new ByteArrayOutputStream();
864 wb.write(out);
865 out.close();
867 wb = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
868 assertTrue("No Exceptions while reading file", true);
872 * Test bug 38266: NPE when adding a row break
874 * User's diagnosis:
875 * 1. Manually (i.e., not using POI) create an Excel Workbook, making sure it
876 * contains a sheet that doesn't have any row breaks
877 * 2. Using POI, create a new HSSFWorkbook from the template in step #1
878 * 3. Try adding a row break (via sheet.setRowBreak()) to the sheet mentioned in step #1
879 * 4. Get a NullPointerException
881 public void test38266() throws Exception {
882 String[] files = {"Simple.xls", "SimpleMultiCell.xls", "duprich1.xls"};
883 for (int i = 0; i < files.length; i++) {
884 FileInputStream in = new FileInputStream(new File(cwd, files[i]));
885 HSSFWorkbook wb = new HSSFWorkbook(in);
886 in.close();
888 HSSFSheet sheet = wb.getSheetAt( 0 );
889 int[] breaks = sheet.getRowBreaks();
890 assertNull(breaks);
892 //add 3 row breaks
893 for (int j = 1; j <= 3; j++) {
894 sheet.setRowBreak(j*20);
897 assertTrue("No Exceptions while adding row breaks in " + files[i], true);
901 public void test40738() throws Exception {
902 FileInputStream in = new FileInputStream(new File(cwd, "SimpleWithAutofilter.xls"));
903 HSSFWorkbook wb = new HSSFWorkbook(in);
904 in.close();
906 //serialize and read again
907 ByteArrayOutputStream out = new ByteArrayOutputStream();
908 wb.write(out);
909 out.close();
911 wb = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
912 assertTrue("No Exceptions while reading file", true);
917 * Bug 44200: Sheet not cloneable when Note added to excel cell
919 public void test44200() throws Exception {
920 FileInputStream in = new FileInputStream(new File(cwd, "44200.xls"));
921 HSSFWorkbook wb = new HSSFWorkbook(in);
922 in.close();
924 wb.cloneSheet(0);
925 assertTrue("No Exceptions while cloning sheet", true);
927 //serialize and read again
928 ByteArrayOutputStream out = new ByteArrayOutputStream();
929 wb.write(out);
930 out.close();
932 wb = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
933 assertTrue("No Exceptions while reading file", true);
938 * Bug 44201: Sheet not cloneable when validation added to excel cell
940 public void test44201() throws Exception {
941 FileInputStream in = new FileInputStream(new File(cwd, "44201.xls"));
942 HSSFWorkbook wb = new HSSFWorkbook(in);
943 in.close();
945 wb.cloneSheet(0);
946 assertTrue("No Exceptions while cloning sheet", true);
948 //serialize and read again
949 ByteArrayOutputStream out = new ByteArrayOutputStream();
950 wb.write(out);
951 out.close();
953 wb = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
954 assertTrue("No Exceptions while reading file", true);
959 * Bug 37684 : Unhandled Continue Record Error
961 public void test37684 () throws Exception {
962 FileInputStream in = new FileInputStream(new File(cwd, "37684-1.xls"));
963 HSSFWorkbook wb = new HSSFWorkbook(in);
964 in.close();
966 assertTrue("No exceptions while reading workbook", true);
968 //serialize and read again
969 ByteArrayOutputStream out = new ByteArrayOutputStream();
970 wb.write(out);
971 out.close();
972 assertTrue("No exceptions while saving workbook", true);
974 wb = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
975 assertTrue("No exceptions while reading saved stream", true);
978 in = new FileInputStream(new File(cwd, "37684-2.xls"));
979 wb = new HSSFWorkbook(in);
980 in.close();
982 assertTrue("No exceptions while reading workbook", true);
984 //serialize and read again
985 out = new ByteArrayOutputStream();
986 wb.write(out);
987 out.close();
988 assertTrue("No exceptions while saving workbook", true);
990 wb = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
991 assertTrue("No exceptions while reading saved stream", true);
995 * Bug 41139: Constructing HSSFWorkbook is failed,threw threw ArrayIndexOutOfBoundsException for creating UnknownRecord
997 public void test41139() throws Exception {
998 FileInputStream in = new FileInputStream(new File(cwd, "41139.xls"));
999 HSSFWorkbook wb = new HSSFWorkbook(in);
1000 in.close();
1002 assertTrue("No Exceptions while reading file", true);
1004 //serialize and read again
1005 ByteArrayOutputStream out = new ByteArrayOutputStream();
1006 wb.write(out);
1007 out.close();
1009 wb = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
1010 assertTrue("No Exceptions while reading file", true);
1014 * Bug 42618: RecordFormatException reading a file containing
1015 * =CHOOSE(2,A2,A3,A4)
1017 public void test42618() throws Exception {
1018 FileInputStream in = new FileInputStream(new File(cwd, "SimpleWithChoose.xls"));
1019 HSSFWorkbook wb = new HSSFWorkbook(in);
1020 in.close();
1022 assertTrue("No Exceptions while reading file", true);
1024 //serialize and read again
1025 ByteArrayOutputStream out = new ByteArrayOutputStream();
1026 wb.write(out);
1027 out.close();
1029 wb = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
1030 assertTrue("No Exceptions while reading file", true);