https://issues.apache.org/bugzilla/show_bug.cgi?id=45633


Yegor Kozlov <[EMAIL PROTECTED]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |WONTFIX




--- Comment #2 from Yegor Kozlov <[EMAIL PROTECTED]>  2008-08-18 11:24:23 PST 
---
I would say it's a feature of HSLF, not a bug.
In PowerPoint table is a special group of shapes that must be tightly packed
and follow certain layout constraints. When you call Table.setAnchor then only
the Table's anchor is updated. The anchors of child table cells remain the same
and that is why PowerPoint displays it incorrectly.

Below is a workaround:

    public static void main(String[] args) {


        SlideShow ppt = null;

        try {
            ppt = new SlideShow(new FileInputStream("PST.ppt"));
        } catch (FileNotFoundException e) {
        } catch (IOException e) {
        }

        Slide slide = ppt.getSlides()[0];
        Shape shape = slide.getShapes()[2];
        Rectangle anchor = shape.getAnchor();

        // Create table data array

        String[] row1 = new String[3];
        row1[0] = "Project Name";
        row1[1] = "ProjectID";
        row1[2] = "Priority";

        String[] row2 = new String[3];
        row2[0] = "Test Work";
        row2[1] = "-";
        row2[2] = "-";

        String[][] tableData = new String[2][3];
        tableData[0] = row1;
        tableData[1] = row2;

        Table pptTable = new Table(2, 3);

        for (int i = 0; i < pptTable.getNumberOfRows(); i++) {
            String[] rowData = tableData[i];
            for (int j = 0; j < pptTable.getNumberOfColumns(); j++) {
                TableCell pptCell = pptTable.getCell(i, j);
                String cellData = rowData[j];
                if (cellData != null) {
                    pptCell.setText(cellData);
                    RichTextRun rt =
                            pptCell.getTextRun().getRichTextRuns()[0];
                    rt.setFontName("Arial");
                    rt.setFontSize(10);
                }
            }
        }

        slide.removeShape(shape);

        pptTable.setAllBorders(new Line());

        //HSLF "feature": resizing columns / rows works AFTER the table is
added to the slide
        slide.addShape(pptTable);

        int rowHeight = anchor.height/pptTable.getNumberOfRows();
        int colWidth = anchor.width/pptTable.getNumberOfColumns();

        //evenly distribute columns and rows
        for (int i = 0; i < pptTable.getNumberOfRows(); i++) {
            pptTable.setRowHeight(i, rowHeight);
            for (int j = 0; j < pptTable.getNumberOfColumns(); j++) {
                pptTable.setColumnWidth(j, colWidth);
            }
        }

        //set top-left corner of the table
        pptTable.moveTo(anchor.x, anchor.y);

        try {
            ppt.write(new FileOutputStream("PST_out.ppt"));
        } catch (FileNotFoundException e) {
        } catch (IOException e) {
        }


    }

Summary: Set the table dimensions using Table.setRowHeight and
Table.setColumnWidth and then set the Table's top-left corner. Don't use
Table.setAnchor.

Yegor


-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to