This is just a convenient way to quickly have a look at a "content.xml" file.
Code: Select all
rem---extract content.xml into same folder and open in default app (or in Open/LibreOffice)
sub extract_content_xml
dim args(0)
dim args1(0) As New com.sun.star.beans.PropertyValue
oDoc=ThisComponent
if len(oDoc.getURL())=0 then
msgbox "Save document first!"
exit sub
end if
If (Not GlobalScope.BasicLibraries.isLibraryLoaded("Tools")) Then GlobalScope.BasicLibraries.LoadLibrary("Tools")
workdirfull = DirectoryNameoutofPath(oDoc.getURL(),"/")
rem otmp_url = CreateUnoService("com.sun.star.util.PathSettings")
rem stmp_url = otmp_url.temp
stmp_url = workdirfull
z = CreateUnoService("com.sun.star.packages.Package")
args(0)= oDoc.URL
z.initialize(args())
oInputstream=z.getByHierarchicalName("content.xml").GetInputStream
oSimpleFileAccess = createUnoService("com.sun.star.ucb.SimpleFileAccess")
oSimpleFileAccess.WriteFile(stmp_url & "/" & "content.xml", oInputstream)
oSyShell = CreateUnoService("com.sun.star.system.SystemShellExecute")
rem---open Folder with content.xml:
oSyShell.execute(workdirfull, "", 0)
rem---open content.xml in external editor
oSyShell.execute(workdirfull & "/" & "content.xml", "", 0)
rem--- or instead open content.xml in Open/LibreOffice:
' newoDoc = StarDesktop.loadComponentFromURL(workdirfull & "/" & "content.xml","_default", 0, args1())
end sub
Code: Select all
rem--- create a copy of the current document and insert the content.xml (lying in the same folder, created by the first macro) into it, open the new doc
sub replace_content_xml
Dim args1(0) As New com.sun.star.beans.PropertyValue
oDoc=ThisComponent
if len(oDoc.getURL())=0 then
msgbox "Save document first!"
exit sub
end if
If (Not GlobalScope.BasicLibraries.isLibraryLoaded("Tools")) Then GlobalScope.BasicLibraries.LoadLibrary("Tools")
workdirfull = DirectoryNameoutofPath(oDoc.getURL(),"/")
docname = GetFileNameWithoutExtension(oDoc.getURL(),"/")
Doc_ext = GetFileNameExtension(oDoc.getURL(),"/")
DateiNeu = workdirfull & "/" & docname & "(new)." & Doc_ext
oDoc.storeToURL(DateiNeu, Array())
service_manager = CreateObject("com.sun.star.ServiceManager")
ooo_zipper = service_manager.createinstance("com.sun.star.packages.Package")
Dim argsx(0)
argsx(0) = ConvertToUrl(DateiNeu)
ooo_zipper.Initialize(argsx())
Dim argsx2(0)
argsx2(0) = False
InputStream = ooo_zipper.createInstanceWithArguments(argsx2())
oUcb = service_manager.createinstance("com.sun.star.ucb.SimpleFileAccess")
x1Datei = oUcb.OpenFileRead(workdirfull & "/" & "content.xml")
InputStream.setInputStream(x1Datei)
ParentFolder = ooo_zipper.getByHierarchicalName("")
ParentFolder.replaceByName("content.xml", InputStream)
ooo_zipper.commitChanges
rem--- open new doc
newoDoc = StarDesktop.loadComponentFromURL(DateiNeu,"_default", 0, args1())
end sub