Hi Oliver,

is there a possibility to copy a textsection from a source document to a
destination document using the api ?

At the moment i am using copy & paste but this has the disadvantage
of loosing the paragraph format ...

any hints ?

the following macro will copy the first section of the current document into a new document. It doesn't handle TextTables, TextFrames of TextSections that might be in the given section.

Hope that helps

Regards

Stephan

---------- The Macro ----------
Sub Main
xSection = ThisComponent.TextSections(0)

xDoc = StarDesktop.loadComponentFromURL("private:factory/ swriter","_blank",0,dimarray())
xText = xDoc.getText()
xTextCursor = xText.createTextCursor
xSecondSection = xDoc.createInstance("com.sun.star.text.TextSection")
xText.insertTextContent(xTextCursor, xSecondSection, false)
cloneProperties(xSection, xSecondSection)

xorgCursor = xSection.getAnchor
xnewCursor = xSecondSection.getAnchor
xnewText = xnewCursor.getText()

xDoc.lockControllers
On Error resume next    
xEnum = xorgCursor.createEnumeration
while xEnum.hasMoreElements
        xPara = xEnum.nextElement
        xPortions = xPara.createEnumeration
        while xPortions.hasMoreElements
                xPortion = xPortions.nextElement()
                xnewText.insertString(xnewCursor,xPortion.getString(),true)
                cloneProperties(xPortion,xnewCursor)
                xnewCursor = xnewCursor.getEnd()
        wend

wend

xDoc.unlockControllers

End Sub

function cloneProperties(original, clone)
On Error resume next
properties = original.getPropertySetInfo.getProperties
for i=0 to UBound(properties)
        aName = properties(i).Name
        aValue = original.getPropertyValue(aName)
        if (NOT isNull(aValue)) AND (NOT isEmpty(aValue)) then
                clone.setPropertyValue(aName,aValue)
        endif
next
end function
------------------------------------

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

Reply via email to