Lines 24-32
Link Here
|
24 |
import org.apache.poi.hssf.usermodel.HSSFWorkbook; |
24 |
import org.apache.poi.hssf.usermodel.HSSFWorkbook; |
25 |
import org.apache.poi.util.TempFile; |
25 |
import org.apache.poi.util.TempFile; |
26 |
|
26 |
|
27 |
import java.io.File; |
27 |
import java.io.*; |
28 |
import java.io.FileInputStream; |
|
|
29 |
import java.io.FileOutputStream; |
30 |
|
28 |
|
31 |
/** |
29 |
/** |
32 |
* Tests row shifting capabilities. |
30 |
* Tests row shifting capabilities. |
Lines 170-174
Link Here
|
170 |
assertTrue("Row number 6 should have a pagebreak", s.isRowBroken(6)); |
168 |
assertTrue("Row number 6 should have a pagebreak", s.isRowBroken(6)); |
171 |
|
169 |
|
172 |
} |
170 |
} |
|
|
171 |
|
172 |
|
173 |
public void testShiftWithComments() throws Exception { |
174 |
String filename = System.getProperty( "HSSF.testdata.path" ); |
175 |
filename = filename + "/comments.xls"; |
176 |
FileInputStream fin = new FileInputStream( filename ); |
177 |
HSSFWorkbook wb = new HSSFWorkbook( fin ); |
178 |
fin.close(); |
179 |
|
180 |
HSSFSheet sheet = wb.getSheet("Sheet1"); |
181 |
assertEquals(3, sheet.getLastRowNum()); |
182 |
|
183 |
// Verify comments are in the position expected |
184 |
assertNotNull(sheet.getCellComment(0,0)); |
185 |
assertNull(sheet.getCellComment(1,0)); |
186 |
assertNotNull(sheet.getCellComment(2,0)); |
187 |
assertNotNull(sheet.getCellComment(3,0)); |
188 |
|
189 |
String comment1 = sheet.getCellComment(0,0).getString().getString(); |
190 |
assertEquals(comment1,"comment top row1 (index0)\n"); |
191 |
String comment3 = sheet.getCellComment(2,0).getString().getString(); |
192 |
assertEquals(comment3,"comment top row3 (index2)\n"); |
193 |
String comment4 = sheet.getCellComment(3,0).getString().getString(); |
194 |
assertEquals(comment4,"comment top row4 (index3)\n"); |
195 |
|
196 |
// Shifting all but first line down to test comments shifting |
197 |
sheet.shiftRows(1, sheet.getLastRowNum(), 1, true, true); |
198 |
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); |
199 |
wb.write(outputStream); |
200 |
|
201 |
// Test that comments were shifted as expected |
202 |
assertEquals(4, sheet.getLastRowNum()); |
203 |
assertNotNull(sheet.getCellComment(0,0)); |
204 |
assertNull(sheet.getCellComment(1,0)); |
205 |
assertNull(sheet.getCellComment(2,0)); |
206 |
assertNotNull(sheet.getCellComment(3,0)); |
207 |
assertNotNull(sheet.getCellComment(4,0)); |
208 |
|
209 |
String comment1_shifted = sheet.getCellComment(0,0).getString().getString(); |
210 |
assertEquals(comment1,comment1_shifted); |
211 |
String comment3_shifted = sheet.getCellComment(3,0).getString().getString(); |
212 |
assertEquals(comment3,comment3_shifted); |
213 |
String comment4_shifted = sheet.getCellComment(4,0).getString().getString(); |
214 |
assertEquals(comment4,comment4_shifted); |
215 |
|
216 |
// Write out and read back in again |
217 |
// Ensure that the changes were persisted |
218 |
wb = new HSSFWorkbook( new ByteArrayInputStream(outputStream.toByteArray()) ); |
219 |
sheet = wb.getSheet("Sheet1"); |
220 |
assertEquals(4, sheet.getLastRowNum()); |
221 |
|
222 |
// Verify comments are in the position expected after the shift |
223 |
assertNotNull(sheet.getCellComment(0,0)); |
224 |
assertNull(sheet.getCellComment(1,0)); |
225 |
assertNull(sheet.getCellComment(2,0)); |
226 |
assertNotNull(sheet.getCellComment(3,0)); |
227 |
assertNotNull(sheet.getCellComment(4,0)); |
228 |
|
229 |
comment1_shifted = sheet.getCellComment(0,0).getString().getString(); |
230 |
assertEquals(comment1,comment1_shifted); |
231 |
comment3_shifted = sheet.getCellComment(3,0).getString().getString(); |
232 |
assertEquals(comment3,comment3_shifted); |
233 |
comment4_shifted = sheet.getCellComment(4,0).getString().getString(); |
234 |
assertEquals(comment4,comment4_shifted); |
235 |
} |
173 |
} |
236 |
} |
174 |
|
237 |
|