https://issues.apache.org/ooo/show_bug.cgi?id=55575

mjmb <[email protected]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |[email protected]

--- Comment #13 from mjmb <[email protected]> ---
Hi, 

tableColumnSeperator works inconsistent. tested version aoo 3.4.1 linux i686

below program show correctly changed tables with 2,4,5,8 and 16 columns while
tables with 3,6,7,9,10-15 columns do not:

/**
 * ************************************************************
 *
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements. See the NOTICE file distributed with this
 * work for additional information regarding copyright ownership. The ASF
 * licenses this file to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
under
 * the License.
 *
 ************************************************************
 */
/*
 * TestOfficeUNOClientApp.java
 *
 * Created on 2013.08.28 - 07:27:15
 *
 */
package com.example;

import com.sun.star.beans.PropertyValue;
import com.sun.star.beans.XPropertySet;
import com.sun.star.uno.XComponentContext;
import com.sun.star.comp.helper.Bootstrap;
import com.sun.star.comp.helper.BootstrapException;
import com.sun.star.frame.XComponentLoader;
import com.sun.star.lang.XComponent;
import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.table.XCellRange;
import com.sun.star.table.XTableRows;
import com.sun.star.text.TableColumnSeparator;
import com.sun.star.text.XText;
import com.sun.star.text.XTextCursor;
import com.sun.star.text.XTextDocument;
import com.sun.star.text.XTextTable;
import com.sun.star.uno.UnoRuntime;

/**
 *
 * @author martin
 */
public class TestOfficeUNOClientApp {

    final static boolean DEBUG = true;

    /**
     * Creates a new instance of TestOfficeUNOClientApp
     */
    public TestOfficeUNOClientApp() {
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

        XComponentContext xComponentContext = null;
        XMultiComponentFactory xMCF = null;
        Object desktop = null;
        XComponentLoader xComponentLoader = null;
        XComponent xWriterComponent = null;
        XTextDocument xTextDocument = null;
        XMultiServiceFactory docServiceFactory = null; // textcontent creator
        // get the remote office component context
        try {
            xComponentContext = Bootstrap.bootstrap();
            if (xComponentContext == null) {
                System.err.println("ERROR: Could not bootstrap default
Office.");
            }
            try {
                xMCF = xComponentContext.getServiceManager();
                desktop =
xMCF.createInstanceWithContext("com.sun.star.frame.Desktop",
xComponentContext);
                xComponentLoader = (XComponentLoader)
UnoRuntime.queryInterface(XComponentLoader.class, desktop);
                PropertyValue[] loadProps = new PropertyValue[0];
                // verkrijg een leeg document
                xWriterComponent =
xComponentLoader.loadComponentFromURL("private:factory/swriter", "_blank", 0,
loadProps);
                xTextDocument = (XTextDocument)
UnoRuntime.queryInterface(XTextDocument.class, xWriterComponent);
                // verkrijg een pointer naar de bij document horende "Service
Manager"
                docServiceFactory = (XMultiServiceFactory)
UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument);


                XText xText = xTextDocument.getText();

                for (int x = 2; x < 17; ++x) {
                    Object textTable =
docServiceFactory.createInstance("com.sun.star.text.TextTable");
                    XTextTable xTextTable = (XTextTable)
UnoRuntime.queryInterface(XTextTable.class, textTable);

                    xTextTable.initialize(3, x);

                    // Getting Doc cursor
                    XTextCursor xTextCursor = xText.createTextCursor();
                    xTextCursor.collapseToEnd();
                    xTextCursor.gotoEnd(false);
                    // Insert the table into the document
                    xText.insertTextContent(xTextCursor, xTextTable, false);

                    // set some id
                    XCellRange xCellRange = (XCellRange)
UnoRuntime.queryInterface(XCellRange.class, xTextTable);

                    XText xCellText = (XText)
UnoRuntime.queryInterface(XText.class, xCellRange.getCellByPosition(0, 0));
                    xCellText.setString(""+x);

                    // rel width of table
                    XPropertySet tableProps = (XPropertySet)
UnoRuntime.queryInterface(XPropertySet.class, xTextTable);
                    String ss =
tableProps.getPropertyValue("TableColumnRelativeSum").toString();
                    short tabelRelWidth = Integer.decode("" + ss).shortValue();
                    // get the rows
                    XTableRows xTableRows = xTextTable.getRows();
// only change row 1
                    XPropertySet xPropertySet1 = (XPropertySet)
UnoRuntime.queryInterface(XPropertySet.class, xTableRows.getByIndex(1));
                    // get Property TableColumnSeparators
                    TableColumnSeparator[] xTableColumnSeparator =
(TableColumnSeparator[])
xPropertySet1.getPropertyValue("TableColumnSeparators");

                    if (DEBUG) {
                        for (int y = 0; y < xTableColumnSeparator.length; ++y)
{
                            System.out.print("" +
xTableColumnSeparator[y].Position + ",");
                        }
                        System.out.println("orginal");

                    }
// make last smaller by half a box size
                    short sTemp;
                    sTemp = xTableColumnSeparator[xTableColumnSeparator.length
- 1].Position;
                    sTemp = (short) (sTemp + (tabelRelWidth - sTemp) / 2); 
//stupid shorts :(
                    xTableColumnSeparator[xTableColumnSeparator.length -
1].Position = sTemp;
                    xPropertySet1.setPropertyValue("TableColumnSeparators",
(Object) xTableColumnSeparator);

                    if (DEBUG) {
                        // show them
                        TableColumnSeparator[] xTableColumnSeparator2 =
(TableColumnSeparator[])
xPropertySet1.getPropertyValue("TableColumnSeparators");
                        for (int yy = 0; yy < xTableColumnSeparator2.length;
++yy) {
                            System.out.print("" +
xTableColumnSeparator2[yy].Position + ",");
                        }
                        System.out.println("newly read");
                    }
                }
            } catch (Exception ex) {
                System.out.println("startOpenOffice:" + ex.getMessage());
            }

        } catch (BootstrapException e) {
            e.printStackTrace();
        } finally {
            System.exit(0);
        }
    }
}

-- 
You are receiving this mail because:
You are on the CC list for the bug.
You are the assignee for the bug.
You are watching all bug changes.

Reply via email to