use of org.apache.poi.hslf.usermodel.HSLFTable in project poi by apache.
the class TestTable method test45889.
/**
* Error constructing Table when rownum=1
*/
@Test
public void test45889() throws IOException {
HSLFSlideShow ppt = new HSLFSlideShow();
HSLFSlide slide = ppt.createSlide();
List<HSLFShape> shapes;
HSLFTable tbl1 = slide.createTable(1, 5);
assertEquals(5, tbl1.getNumberOfColumns());
assertEquals(1, tbl1.getNumberOfRows());
shapes = slide.getShapes();
assertEquals(1, shapes.size());
HSLFTable tbl2 = (HSLFTable) shapes.get(0);
assertSame(tbl1.getSpContainer(), tbl2.getSpContainer());
assertEquals(tbl1.getNumberOfColumns(), tbl2.getNumberOfColumns());
assertEquals(tbl1.getNumberOfRows(), tbl2.getNumberOfRows());
ppt.close();
}
use of org.apache.poi.hslf.usermodel.HSLFTable in project poi by apache.
the class TableDemo method create2ndTable.
static void create2ndTable(HSLFSlide slide) {
//two rows, one column
HSLFTable table2 = slide.createTable(2, 1);
for (int i = 0; i < txt2.length; i++) {
for (int j = 0; j < txt2[i].length; j++) {
HSLFTableCell cell = table2.getCell(i, j);
HSLFTextRun rt = cell.getTextParagraphs().get(0).getTextRuns().get(0);
rt.setFontSize(10d);
rt.setFontFamily("Arial");
if (i == 0) {
cell.getFill().setForegroundColor(new Color(0, 51, 102));
rt.setFontColor(Color.white);
rt.setBold(true);
rt.setFontSize(14d);
cell.setHorizontalCentered(true);
} else {
rt.getTextParagraph().setBullet(true);
rt.setFontSize(12d);
rt.getTextParagraph().setTextAlign(TextAlign.LEFT);
cell.setHorizontalCentered(false);
}
cell.setVerticalAlignment(VerticalAlignment.MIDDLE);
cell.setText(txt2[i][j]);
}
}
table2.setColumnWidth(0, 300);
table2.setRowHeight(0, 30);
table2.setRowHeight(1, 70);
DrawTableShape dts2 = new DrawTableShape(table2);
dts2.setOutsideBorders(Color.black, 1.0);
table2.moveTo(200, 400);
}
use of org.apache.poi.hslf.usermodel.HSLFTable in project poi by apache.
the class TableDemo method create1stTable.
static void create1stTable(HSLFSlide slide) {
//six rows, two columns
HSLFTable table1 = slide.createTable(6, 2);
for (int i = 0; i < txt1.length; i++) {
for (int j = 0; j < txt1[i].length; j++) {
HSLFTableCell cell = table1.getCell(i, j);
HSLFTextRun rt = cell.getTextParagraphs().get(0).getTextRuns().get(0);
rt.setFontFamily("Arial");
rt.setFontSize(10d);
if (i == 0) {
cell.getFill().setForegroundColor(new Color(227, 227, 227));
} else {
rt.setBold(true);
}
cell.setVerticalAlignment(VerticalAlignment.MIDDLE);
cell.setHorizontalCentered(true);
cell.setText(txt1[i][j]);
}
}
DrawTableShape dts1 = new DrawTableShape(table1);
dts1.setAllBorders(1.0, Color.black);
table1.setColumnWidth(0, 300);
table1.setColumnWidth(1, 150);
int pgWidth = slide.getSlideShow().getPageSize().width;
table1.moveTo((pgWidth - table1.getAnchor().getWidth()) / 2., 100.);
}
use of org.apache.poi.hslf.usermodel.HSLFTable in project tika by apache.
the class HSLFExtractor method parse.
protected void parse(DirectoryNode root, XHTMLContentHandler xhtml) throws IOException, SAXException, TikaException {
HSLFSlideShow ss = new HSLFSlideShow(root);
List<HSLFSlide> _slides = ss.getSlides();
xhtml.startElement("div", "class", "slideShow");
/* Iterate over slides and extract text */
for (HSLFSlide slide : _slides) {
xhtml.startElement("div", "class", "slide");
// Slide header, if present
HeadersFooters hf = slide.getHeadersFooters();
if (hf != null && hf.isHeaderVisible() && hf.getHeaderText() != null) {
xhtml.startElement("p", "class", "slide-header");
xhtml.characters(hf.getHeaderText());
xhtml.endElement("p");
}
// Slide master, if present
extractMaster(xhtml, slide.getMasterSheet());
// Slide text
{
xhtml.startElement("div", "class", "slide-content");
textRunsToText(xhtml, slide.getTextParagraphs());
xhtml.endElement("div");
}
// Table text
for (HSLFShape shape : slide.getShapes()) {
if (shape instanceof HSLFTable) {
extractTableText(xhtml, (HSLFTable) shape);
}
}
// Slide footer, if present
if (hf != null && hf.isFooterVisible() && hf.getFooterText() != null) {
xhtml.startElement("p", "class", "slide-footer");
xhtml.characters(hf.getFooterText());
xhtml.endElement("p");
}
// Comments, if present
StringBuilder authorStringBuilder = new StringBuilder();
for (Comment comment : slide.getComments()) {
authorStringBuilder.setLength(0);
xhtml.startElement("p", "class", "slide-comment");
if (comment.getAuthor() != null) {
authorStringBuilder.append(comment.getAuthor());
}
if (comment.getAuthorInitials() != null) {
if (authorStringBuilder.length() > 0) {
authorStringBuilder.append(" ");
}
authorStringBuilder.append("(" + comment.getAuthorInitials() + ")");
}
if (authorStringBuilder.length() > 0) {
if (comment.getText() != null) {
authorStringBuilder.append(" - ");
}
xhtml.startElement("b");
xhtml.characters(authorStringBuilder.toString());
xhtml.endElement("b");
}
if (comment.getText() != null) {
xhtml.characters(comment.getText());
}
xhtml.endElement("p");
}
// Now any embedded resources
handleSlideEmbeddedResources(slide, xhtml);
// Find the Notes for this slide and extract inline
HSLFNotes notes = slide.getNotes();
if (notes != null) {
xhtml.startElement("div", "class", "slide-notes");
textRunsToText(xhtml, notes.getTextParagraphs());
xhtml.endElement("div");
}
// Slide complete
xhtml.endElement("div");
}
// All slides done
xhtml.endElement("div");
/* notes */
xhtml.startElement("div", "class", "slide-notes");
HashSet<Integer> seenNotes = new HashSet<>();
HeadersFooters hf = ss.getNotesHeadersFooters();
for (HSLFSlide slide : _slides) {
HSLFNotes notes = slide.getNotes();
if (notes == null) {
continue;
}
Integer id = notes._getSheetNumber();
if (seenNotes.contains(id)) {
continue;
}
seenNotes.add(id);
// Repeat the Notes header, if set
if (hf != null && hf.isHeaderVisible() && hf.getHeaderText() != null) {
xhtml.startElement("p", "class", "slide-note-header");
xhtml.characters(hf.getHeaderText());
xhtml.endElement("p");
}
// Notes text
textRunsToText(xhtml, notes.getTextParagraphs());
// Repeat the notes footer, if set
if (hf != null && hf.isFooterVisible() && hf.getFooterText() != null) {
xhtml.startElement("p", "class", "slide-note-footer");
xhtml.characters(hf.getFooterText());
xhtml.endElement("p");
}
}
handleSlideEmbeddedPictures(ss, xhtml);
xhtml.endElement("div");
}
use of org.apache.poi.hslf.usermodel.HSLFTable in project poi by apache.
the class TestTable method testShapeFactory.
/**
* Test that ShapeFactory works properly and returns <code>Table</code>
*/
@Test
public void testShapeFactory() throws IOException {
HSLFSlideShow ppt = new HSLFSlideShow();
HSLFSlide slide = ppt.createSlide();
HSLFTable tbl = slide.createTable(2, 5);
HSLFTableCell cell = tbl.getCell(0, 0);
//table cells have type=TextHeaderAtom.OTHER_TYPE, see bug #46033
assertEquals(TextHeaderAtom.OTHER_TYPE, cell.getTextParagraphs().get(0).getRunType());
HSLFShape tblSh = slide.getShapes().get(0);
assertTrue(tblSh instanceof HSLFTable);
HSLFTable tbl2 = (HSLFTable) tblSh;
assertEquals(tbl.getNumberOfColumns(), tbl2.getNumberOfColumns());
assertEquals(tbl.getNumberOfRows(), tbl2.getNumberOfRows());
ByteArrayOutputStream out = new ByteArrayOutputStream();
ppt.write(out);
out.close();
ppt.close();
ppt = new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray()));
slide = ppt.getSlides().get(0);
assertTrue(slide.getShapes().get(0) instanceof HSLFTable);
HSLFTable tbl3 = (HSLFTable) slide.getShapes().get(0);
assertEquals(tbl.getNumberOfColumns(), tbl3.getNumberOfColumns());
assertEquals(tbl.getNumberOfRows(), tbl3.getNumberOfRows());
ppt.close();
}
Aggregations