Search in sources :

Example 1 with DrawTableShape

use of org.apache.poi.sl.draw.DrawTableShape in project poi by apache.

the class ApacheconEU08 method slide4.

public static void slide4(SlideShow<?, ?> ppt) throws IOException {
    Slide<?, ?> slide = ppt.createSlide();
    String[][] txt1 = { { "Note" }, { "This presentation was created programmatically using POI HSLF" } };
    TableShape<?, ?> table1 = slide.createTable(2, 1);
    for (int i = 0; i < txt1.length; i++) {
        for (int j = 0; j < txt1[i].length; j++) {
            TableCell<?, ?> cell = table1.getCell(i, j);
            cell.setText(txt1[i][j]);
            TextRun rt = cell.getTextParagraphs().get(0).getTextRuns().get(0);
            rt.setFontSize(10d);
            rt.setFontFamily("Arial");
            rt.setBold(true);
            if (i == 0) {
                rt.setFontSize(32d);
                rt.setFontColor(Color.white);
                cell.setFillColor(new Color(0, 153, 204));
            } else {
                rt.setFontSize(28d);
                cell.setFillColor(new Color(235, 239, 241));
            }
            cell.setVerticalAlignment(VerticalAlignment.MIDDLE);
        }
    }
    DrawTableShape dts = new DrawTableShape(table1);
    dts.setAllBorders(1.0, Color.black);
    dts.setOutsideBorders(4.0);
    table1.setColumnWidth(0, 450);
    table1.setRowHeight(0, 50);
    table1.setRowHeight(1, 80);
    Dimension dim = ppt.getPageSize();
    Rectangle2D oldAnchor = table1.getAnchor();
    table1.setAnchor(new Rectangle2D.Double((dim.width - 450) / 2d, 100, oldAnchor.getWidth(), oldAnchor.getHeight()));
    TextBox<?, ?> box1 = slide.createTextBox();
    box1.setHorizontalCentered(true);
    box1.getTextParagraphs().get(0).getTextRuns().get(0).setFontSize(24d);
    box1.setText("The source code is available at\r" + "http://people.apache.org/~yegor/apachecon_eu08/");
    box1.setAnchor(new Rectangle(80, 356, 553, 65));
}
Also used : Color(java.awt.Color) Rectangle2D(java.awt.geom.Rectangle2D) Rectangle(java.awt.Rectangle) TextRun(org.apache.poi.sl.usermodel.TextRun) Dimension(java.awt.Dimension) DrawTableShape(org.apache.poi.sl.draw.DrawTableShape)

Example 2 with DrawTableShape

use of org.apache.poi.sl.draw.DrawTableShape in project poi by apache.

the class TestTable method moveTable.

@Test
public void moveTable() throws IOException {
    HSLFSlideShow ppt = new HSLFSlideShow();
    HSLFSlide slide = ppt.createSlide();
    int rows = 3, cols = 5;
    HSLFTable table = slide.createTable(rows, cols);
    for (int row = 0; row < rows; row++) {
        for (int col = 0; col < cols; col++) {
            HSLFTableCell c = table.getCell(row, col);
            c.setText("r" + row + "c" + col);
        }
    }
    new DrawTableShape(table).setAllBorders(1.0, Color.black, StrokeStyle.LineDash.DASH_DOT);
    table.setAnchor(new Rectangle2D.Double(100, 100, 400, 400));
    Rectangle2D rectExp = new Rectangle2D.Double(420, 366.625, 80, 133.375);
    Rectangle2D rectAct = table.getCell(rows - 1, cols - 1).getAnchor();
    assertEquals(rectExp, rectAct);
    ppt.close();
}
Also used : Rectangle2D(java.awt.geom.Rectangle2D) DrawTableShape(org.apache.poi.sl.draw.DrawTableShape) Test(org.junit.Test)

Example 3 with DrawTableShape

use of org.apache.poi.sl.draw.DrawTableShape 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);
}
Also used : HSLFTextRun(org.apache.poi.hslf.usermodel.HSLFTextRun) HSLFTable(org.apache.poi.hslf.usermodel.HSLFTable) Color(java.awt.Color) HSLFTableCell(org.apache.poi.hslf.usermodel.HSLFTableCell) DrawTableShape(org.apache.poi.sl.draw.DrawTableShape)

Example 4 with DrawTableShape

use of org.apache.poi.sl.draw.DrawTableShape 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.);
}
Also used : HSLFTextRun(org.apache.poi.hslf.usermodel.HSLFTextRun) HSLFTable(org.apache.poi.hslf.usermodel.HSLFTable) Color(java.awt.Color) HSLFTableCell(org.apache.poi.hslf.usermodel.HSLFTableCell) DrawTableShape(org.apache.poi.sl.draw.DrawTableShape)

Aggregations

DrawTableShape (org.apache.poi.sl.draw.DrawTableShape)4 Color (java.awt.Color)3 Rectangle2D (java.awt.geom.Rectangle2D)2 HSLFTable (org.apache.poi.hslf.usermodel.HSLFTable)2 HSLFTableCell (org.apache.poi.hslf.usermodel.HSLFTableCell)2 HSLFTextRun (org.apache.poi.hslf.usermodel.HSLFTextRun)2 Dimension (java.awt.Dimension)1 Rectangle (java.awt.Rectangle)1 TextRun (org.apache.poi.sl.usermodel.TextRun)1 Test (org.junit.Test)1