Lines 19-30
Link Here
|
19 |
import java.io.ByteArrayInputStream; |
19 |
import java.io.ByteArrayInputStream; |
20 |
import java.io.ByteArrayOutputStream; |
20 |
import java.io.ByteArrayOutputStream; |
21 |
import java.io.FileInputStream; |
21 |
import java.io.FileInputStream; |
22 |
import java.io.FileNotFoundException; |
|
|
23 |
|
22 |
|
|
|
23 |
import junit.framework.TestCase; |
24 |
|
24 |
import org.apache.poi.poifs.filesystem.POIFSFileSystem; |
25 |
import org.apache.poi.poifs.filesystem.POIFSFileSystem; |
25 |
|
26 |
|
26 |
import junit.framework.TestCase; |
|
|
27 |
|
28 |
/** |
27 |
/** |
29 |
* Tests for how HSSFWorkbook behaves with XLS files |
28 |
* Tests for how HSSFWorkbook behaves with XLS files |
30 |
* with a WORKBOOK directory entry (instead of the more |
29 |
* with a WORKBOOK directory entry (instead of the more |
Lines 34-44
Link Here
|
34 |
private String dirPath; |
33 |
private String dirPath; |
35 |
private String xlsHidden = "TwoSheetsOneHidden.xls"; |
34 |
private String xlsHidden = "TwoSheetsOneHidden.xls"; |
36 |
private String xlsShown = "TwoSheetsNoneHidden.xls"; |
35 |
private String xlsShown = "TwoSheetsNoneHidden.xls"; |
|
|
36 |
private HSSFWorkbook wbH; |
37 |
private HSSFWorkbook wbU; |
37 |
|
38 |
|
38 |
protected void setUp() throws Exception { |
39 |
protected void setUp() throws Exception { |
39 |
super.setUp(); |
40 |
super.setUp(); |
40 |
|
41 |
|
41 |
dirPath = System.getProperty("HSSF.testdata.path"); |
42 |
dirPath = System.getProperty("HSSF.testdata.path"); |
|
|
43 |
FileInputStream isH = new FileInputStream(dirPath + "/" + xlsHidden); |
44 |
POIFSFileSystem fsH = new POIFSFileSystem(isH); |
45 |
|
46 |
FileInputStream isU = new FileInputStream(dirPath + "/" + xlsShown); |
47 |
POIFSFileSystem fsU = new POIFSFileSystem(isU); |
48 |
|
49 |
wbH = new HSSFWorkbook(fsH); |
50 |
wbU = new HSSFWorkbook(fsU); |
42 |
} |
51 |
} |
43 |
|
52 |
|
44 |
/** |
53 |
/** |
Lines 47-62
Link Here
|
47 |
* the hidden flags are |
56 |
* the hidden flags are |
48 |
*/ |
57 |
*/ |
49 |
public void testTextSheets() throws Exception { |
58 |
public void testTextSheets() throws Exception { |
50 |
FileInputStream isH = new FileInputStream(dirPath + "/" + xlsHidden); |
59 |
// Both should have two sheets |
51 |
POIFSFileSystem fsH = new POIFSFileSystem(isH); |
|
|
52 |
|
53 |
FileInputStream isU = new FileInputStream(dirPath + "/" + xlsShown); |
54 |
POIFSFileSystem fsU = new POIFSFileSystem(isU); |
55 |
|
56 |
HSSFWorkbook wbH = new HSSFWorkbook(fsH); |
57 |
HSSFWorkbook wbU = new HSSFWorkbook(fsU); |
58 |
|
59 |
// Both should have two sheets |
60 |
assertEquals(2, wbH.sheets.size()); |
60 |
assertEquals(2, wbH.sheets.size()); |
61 |
assertEquals(2, wbU.sheets.size()); |
61 |
assertEquals(2, wbU.sheets.size()); |
62 |
|
62 |
|
Lines 73-82
Link Here
|
73 |
assertEquals(1, wbU.getSheetAt(1).getRow(0).getLastCellNum()); |
73 |
assertEquals(1, wbU.getSheetAt(1).getRow(0).getLastCellNum()); |
74 |
|
74 |
|
75 |
// Text should be sheet based |
75 |
// Text should be sheet based |
76 |
assertEquals("Sheet1A1", wbH.getSheetAt(0).getRow(0).getCell((short)0).getStringCellValue()); |
76 |
assertEquals("Sheet1A1", wbH.getSheetAt(0).getRow(0).getCell((short)0).getRichStringCellValue().getString()); |
77 |
assertEquals("Sheet2A1", wbH.getSheetAt(1).getRow(0).getCell((short)0).getStringCellValue()); |
77 |
assertEquals("Sheet2A1", wbH.getSheetAt(1).getRow(0).getCell((short)0).getRichStringCellValue().getString()); |
78 |
assertEquals("Sheet1A1", wbU.getSheetAt(0).getRow(0).getCell((short)0).getStringCellValue()); |
78 |
assertEquals("Sheet1A1", wbU.getSheetAt(0).getRow(0).getCell((short)0).getRichStringCellValue().getString()); |
79 |
assertEquals("Sheet2A1", wbU.getSheetAt(1).getRow(0).getCell((short)0).getStringCellValue()); |
79 |
assertEquals("Sheet2A1", wbU.getSheetAt(1).getRow(0).getCell((short)0).getRichStringCellValue().getString()); |
80 |
} |
80 |
} |
81 |
|
81 |
|
82 |
/** |
82 |
/** |
Lines 84-90
Link Here
|
84 |
* as expected |
84 |
* as expected |
85 |
*/ |
85 |
*/ |
86 |
public void testHideUnHideFlags() throws Exception { |
86 |
public void testHideUnHideFlags() throws Exception { |
87 |
// TODO |
87 |
assertTrue(wbH.isSheetHidden(0)); |
|
|
88 |
assertFalse(wbH.isSheetHidden(1)); |
89 |
assertFalse(wbU.isSheetHidden(0)); |
90 |
assertFalse(wbU.isSheetHidden(1)); |
88 |
} |
91 |
} |
89 |
|
92 |
|
90 |
/** |
93 |
/** |
Lines 92-98
Link Here
|
92 |
* one hidden |
95 |
* one hidden |
93 |
*/ |
96 |
*/ |
94 |
public void testHide() throws Exception { |
97 |
public void testHide() throws Exception { |
95 |
// TODO |
98 |
wbU.setSheetHidden(0, true); |
|
|
99 |
assertTrue(wbU.isSheetHidden(0)); |
100 |
assertFalse(wbU.isSheetHidden(1)); |
101 |
ByteArrayOutputStream out = new ByteArrayOutputStream(); |
102 |
wbU.write(out); |
103 |
out.close(); |
104 |
HSSFWorkbook wb2 = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray())); |
105 |
assertTrue(wb2.isSheetHidden(0)); |
106 |
assertFalse(wb2.isSheetHidden(1)); |
96 |
} |
107 |
} |
97 |
|
108 |
|
98 |
/** |
109 |
/** |
Lines 100-105
Link Here
|
100 |
* none hidden |
111 |
* none hidden |
101 |
*/ |
112 |
*/ |
102 |
public void testUnHide() throws Exception { |
113 |
public void testUnHide() throws Exception { |
103 |
// TODO |
114 |
wbH.setSheetHidden(0, false); |
|
|
115 |
assertFalse(wbH.isSheetHidden(0)); |
116 |
assertFalse(wbH.isSheetHidden(1)); |
117 |
ByteArrayOutputStream out = new ByteArrayOutputStream(); |
118 |
wbH.write(out); |
119 |
out.close(); |
120 |
HSSFWorkbook wb2 = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray())); |
121 |
assertFalse(wb2.isSheetHidden(0)); |
122 |
assertFalse(wb2.isSheetHidden(1)); |
104 |
} |
123 |
} |
105 |
} |
124 |
} |