The line that raises a "CannotConvertException" is :
Code: Select all
args = (PropertyValue('InputStream', oIn, "FilterName", "writer_Rich_Text_Format"),)
Code: Select all
def python_bal(*args):
"""
Main function launched from toolbar button.
"""
desktop = XSCRIPTCONTEXT.getDesktop()
ctx = XSCRIPTCONTEXT.getComponentContext()
document = XSCRIPTCONTEXT.getDocument()
# Position a cursor at the very beginning of the doc
oVC = document.getCurrentController().getViewCursor()
oVC.jumpToFirstPage()
# Select text to copy with style (bold or not)
oVC.gotoEnd(True)
# Get transferable
oTransferable = document.getCurrentController().getTransferable()
dataFlavors = oTransferable.getTransferDataFlavors()
# Get specific DataFlavor
sType = "text/richtext"
for flavor in dataFlavors:
if flavor.MimeType == sType:
aMtype = flavor
if oTransferable.isDataFlavorSupported(aMtype):
nData = oTransferable.getTransferData(aMtype)
# Dark part of the trick
oTemp = createUnoService("com.sun.star.io.TempFile")
oOut = oTemp.getOutputStream()
oOut.writeBytes(nData)
oOut.flush()
oIn = oTemp.getInputStream()
# Create a new doc
args = (PropertyValue('Hidden', 0, False, 0),)
newDoc = desktop.loadComponentFromURL(
get_template_url(), "_default", 0, args
)
# Position the cursor at the end of the new doc
oText = newDoc.getText()
oCursor = oText.createTextCursor()
oCursor.gotoEnd(False)
# Insert transferable data at the cursor's position
args = (PropertyValue('InputStream', oIn, "FilterName", "writer_Rich_Text_Format"),)
oCursor.insertDocumentFromURL("", args)
return None