Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Here is additional information (I hope it is not too much...):

The following code is from

This code is VB.Net It shows how to open a Writer doc from VB.Net, add text, add a table and do other items. It does not show how to create and apply styles. Below is the portion that opens and connects to a new Writer doc.

    Dim xContext As XComponentContext
    xContext = Bootstrap.bootstrap()

    Dim xFactory As XMultiServiceFactory
    xFactory = DirectCast(xContext.getServiceManager(), XMultiServiceFactory)

    'Create the Desktop
    Dim xDesktop As
    xDesktop = DirectCast(xFactory.createInstance(""),  _

    'Open a new empty writer document
    Dim xComponentLoader As
    xComponentLoader = DirectCast(xDesktop,

    Dim arProps() As = New {}
    Dim xComponent As
    xComponent = xComponentLoader.loadComponentFromURL("private:factory/swriter", "_blank", 0, arProps)

    Dim xTextDocument As
    xTextDocument = DirectCast(xComponent,

    'Create a text object
    Dim xText As
    xText = xTextDocument.getText()

    Dim xSimpleText As
    xSimpleText = DirectCast(xText,

    'Create a cursor object
    Dim xCursor As
    xCursor = xSimpleText.createTextCursor()

I also have a code snippet in Java that creates styles in Writer, but I do not know Java and I have not been able to translate from Java to VB.Net. This is from

   // Create a new style from the document's factory
        XStyle xStyle = (XStyle) UnoRuntime.queryInterface(
            XStyle.class, mxDocFactory.createInstance(
                "" ) );

        // Access the XPropertySet interface of the new style
        XPropertySet xStyleProps = (XPropertySet) UnoRuntime.queryInterface(
            XPropertySet.class, xStyle );

        // Give the new style a light blue background
        xStyleProps.setPropertyValue ( "ParaBackColor", new Integer (13421823));

        // Get the StyleFamiliesSupplier interface of the document
        XStyleFamiliesSupplier xSupplier = (XStyleFamiliesSupplier)
            UnoRuntime.queryInterface(XStyleFamiliesSupplier.class, mxDoc);

        // Use the StyleFamiliesSupplier interface to get the XNameAccess
        // interface of the actual style families
        XNameAccess xFamilies = ( XNameAccess ) UnoRuntime.queryInterface (
            XNameAccess.class, xSupplier.getStyleFamilies() );

        // Access the 'ParagraphStyles' Family
        XNameContainer xFamily = (XNameContainer ) UnoRuntime.queryInterface (
                    xFamilies.getByName ( "ParagraphStyles" ) );

        // Insert the newly created style into the ParagraphStyles family
        xFamily.insertByName ( "All-Singing All-Dancing Style", xStyle );

        // Get the XParagraphCursor interface of the document cursor
        XParagraphCursor xParaCursor = (XParagraphCursor)
            UnoRuntime.queryInterface( XParagraphCursor.class, mxDocCursor );

        // Select the first paragraph inserted
        xParaCursor.gotoPreviousParagraph ( false );
        xParaCursor.gotoPreviousParagraph ( true );

        // Access the property set of the cursor selection
        XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(
            XPropertySet.class, mxDocCursor );

        // Set the style of the cursor selection to our newly created style
        xCursorProps.setPropertyValue ( "ParaStyleName",
                                        "All-Singing All-Dancing Style" );

This is what I have so far. If anyone could help me port the Java code to VB.Net or show how to create and apply Writer styles in VB.Net it would really help get me over this hump. Thanks....