#55955 - Filling an existing ppt table stopped working with 3.9

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1714715 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andreas Beeker 2015-11-16 23:56:19 +00:00
parent a0e06add7a
commit e2bc07e9d1

View File

@ -26,6 +26,9 @@ import static org.junit.Assert.assertTrue;
import java.awt.Color; import java.awt.Color;
import java.awt.Rectangle; import java.awt.Rectangle;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.List; import java.util.List;
import org.apache.poi.POIDataSamples; import org.apache.poi.POIDataSamples;
@ -41,7 +44,7 @@ public class TestTable {
private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance(); private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
@Test @Test
public void moveTable() throws Exception { public void moveTable() throws IOException {
HSLFSlideShow ppt = new HSLFSlideShow(); HSLFSlideShow ppt = new HSLFSlideShow();
HSLFSlide slide = ppt.createSlide(); HSLFSlide slide = ppt.createSlide();
int rows = 3, cols = 5; int rows = 3, cols = 5;
@ -60,16 +63,18 @@ public class TestTable {
Rectangle rectExp = new Rectangle(420,367,80,133); Rectangle rectExp = new Rectangle(420,367,80,133);
Rectangle rectAct = table.getCell(rows-1, cols-1).getAnchor(); Rectangle rectAct = table.getCell(rows-1, cols-1).getAnchor();
assertEquals(rectExp, rectAct); assertEquals(rectExp, rectAct);
ppt.close();
} }
@Test @Test
public void testTable() throws Exception { public void testTable() throws IOException {
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("54111.ppt")); HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("54111.ppt"));
assertTrue("No Exceptions while reading file", true); assertTrue("No Exceptions while reading file", true);
List<HSLFSlide> slides = ppt.getSlides(); List<HSLFSlide> slides = ppt.getSlides();
assertEquals(1, slides.size()); assertEquals(1, slides.size());
checkSlide(slides.get(0)); checkSlide(slides.get(0));
ppt.close();
} }
private void checkSlide(final HSLFSlide s) { private void checkSlide(final HSLFSlide s) {
@ -97,4 +102,58 @@ public class TestTable {
} }
} }
} }
@Test
public void testAddText() throws IOException {
HSLFSlideShow ppt1 = new HSLFSlideShow();
HSLFSlide slide = ppt1.createSlide();
HSLFTable tab = slide.createTable(4, 5);
int rows = tab.getNumberOfRows();
int cols = tab.getNumberOfColumns();
for (int row=0; row<rows; row++) {
for (int col=0; col<cols; col++) {
HSLFTableCell c = tab.getCell(row, col);
c.setText("r"+(row+1)+"c"+(col+1));
}
}
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ppt1.write(bos);
ppt1.close();
ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
HSLFSlideShow ppt2 = new HSLFSlideShow(bis);
slide = ppt2.getSlides().get(0);
tab = (HSLFTable)slide.getShapes().get(0);
rows = tab.getNumberOfRows();
cols = tab.getNumberOfColumns();
for (int row=0; row<rows; row++) {
for (int col=0; col<cols; col++) {
HSLFTableCell c = tab.getCell(row, col);
c.setText(c.getText()+"...");
}
}
bos.reset();
ppt2.write(bos);
ppt2.close();
bis = new ByteArrayInputStream(bos.toByteArray());
HSLFSlideShow ppt3 = new HSLFSlideShow(bis);
slide = ppt3.getSlides().get(0);
tab = (HSLFTable)slide.getShapes().get(0);
rows = tab.getNumberOfRows();
cols = tab.getNumberOfColumns();
for (int row=0; row<rows; row++) {
for (int col=0; col<cols; col++) {
HSLFTableCell c = tab.getCell(row, col);
assertEquals("r"+(row+1)+"c"+(col+1)+"...", c.getText());
}
}
ppt3.close();
}
} }