Sub Main
'get the images in ThisComponent.GraphicObjects
sMes = "pictures contained in GraphicObjects: " & ThisComponent.GraphicObjects.Count
for k=0 to ThisComponent.GraphicObjects.Count-1
sMes = sMes & Chr(13) & Chr(10) & ThisComponent.GraphicObjects.getByIndex(k).graphicUrl
next
msgbox sMes
'get the images in ThisComponent.DocumentStorage
asElementNames = ThisComponent.DocumentStorage.getByName("Pictures").ElementNames
sMes = "pictures contained in DocumentStorage: " & (UBound(asElementNames)+1)
for k=0 to UBound(asElementNames)
sMes = sMes & Chr(13) & Chr(10) & asElementNames(k)
next
msgbox sMes
oPicGraphicObjects = ThisComponent.GraphicObjects.getByIndex(0)
xray oPicGraphicObjects
oPicStorage = ThisComponent.DocumentStorage.getByName("Pictures").getByName(asElementNames(0))
xray oPicStorage
'Example: insert the first image into an ImageControl. The ImageControl must already be present, on the first form, and must be named "ImageControl".
oImageControl = ThisComponent.DrawPage.Forms.getByIndex(0).getByName("ImageControl")
oProvider = createUnoService("com.sun.star.graphic.GraphicProvider")
Dim oPropsIN(1)as new com.sun.star.beans.PropertyValue
oPropsIN(0).Name = "InputStream"
oPropsIN(0).Value = oPicStorage.InputStream
oImageControl.Graphic = oProvider.queryGraphic(oPropsIN())
End Sub
#…<snip>…
sfa = createUnoService( "com.sun.star.ucb.SimpleFileAccess")
pythonfolder = ('vnd.sun.star.tdoc:/'
'{}/Scripts/python'.format(doc.RuntimeUID))
fileuri = "{}/{}".format(pythonfolder, filename)
if sfa.exists(fileuri):
if mode == 'a':
message = ("Appending to %s in doc: %s" % (filename , doc.Title))
else:
print("Overwriting %s in doc: %s" % (filename, doc.Title))
else:
print("Writing to %s in doc: %s" %(filename, doc.Title))
sfa.createFolder(pythonfolder)
tempfile = NamedTemporaryFile(mode=mode)
temppath = tempfile.name
tempuri = uno.systemPathToFileUrl(temppath)
if sfa.exists(fileuri) and mode=='a':
sfa.copy(fileuri, tempuri)
with open(temppath) as t:
t = t.read()
doublefuncs = test_unique_func_names(t, content)
if doublefuncs:
tempfile.delete
print('Interrupt appending to {} @ {}, '
'because double Functionnames: ``{}´'
''.format(filename, doc.Title, ', '.join(doublefuncs)))
return
print(message)
with io.open(temppath, mode, encoding='utf-8') as f:
f.write(content)
sfa.copy(tempuri, fileuri)
tempfile.delete
oDoc = ThisComponent
oStorageFac = createUnoService("com.sun.star.embed.StorageFactory")
oStorage = oStorageFac.createInstance
oStream = oStorage.openStreamElement("ms777", com.sun.star.embed.ElementModes.READWRITE)
Dim storeProps(0) as new com.sun.star.beans.PropertyValue
storeProps(0).Name = "OutputStream"
storeProps(0).Value = oStream
oDoc.storeToUrl("private:stream", storeProps())
"All documents that have been loaded – regardless of their persistent document format--- or that have been created but not yet saved to any storage medium, are supported.[...] The document contents provided by the [Transient Document Content Provider] represent live data, which may differ from any persistent representation of the document, for instance, because the user modified the document after loading, but did not yet save it."
Users browsing this forum: No registered users and 5 guests