More ideas…
While spinning the ideas I got while recoding my tuning I realized that I could extract data from .xml files stored into my LO project’s package and store the extracted data to string variables on the fly. This gives me ability to manipulate the data the way I want and then save the manipulated data either back to the project package or to some other target like a single file or a package archive.
The first step on this was to create a macro to read data:
There are no easy to find examples available how this could be done, and it took a while until I came across Andrew Pitonyak’s documentation which handled among many other things TextInputStream object. Andrew’s explanation of how to extract the data into a string wasn’t the easiest to understand, in the case you want to read the data into string at once instead of doing it line by line in a do-while-loop.
But finally I got it:
Sub BasicMain
ExtractSpecificFileFromProjectAchiveAsText "Dialogs/Standard/", "MultiPageTemp.xml"
End Sub
Sub ExtractSpecificFileFromProjectAchiveAsText(sFolder As String, sFile As String)
Dim oZipHandler As Object
Dim args(0)
Dim args1()
Dim entries() As String
Dim xmlContent As Variant
Dim fileToRead As String
fileToRead = sFolder & sFile
oZipHandler = CreateUnoService("com.sun.star.packages.zip.ZipFileAccess")
args(0) = thisComponent.URL
oZipHandler.initialize(args)
entries = oZipHandler.getElementNames()
Dim textStream As Object
textStream = CreateUnoService("com.sun.star.io.TextInputStream")
Dim stream As Object, line As String
For i = LBound(entries) To UBound(entries)
If entries(i) = fileToRead Then
stream = oZipHandler.getByName(entries(i))
textStream.setEncoding("UTF-8")
textStream.setInputStream(stream)
xmlContent = textStream.readString(args1, true)
textStream.closeInput()
textStream = Nothing
stream = Nothing
Erase entries
args = ""
Erase args1
oZipHandler = Nothing
Exit For
End If
Next
MsgBox "Extracted content: " & chr(10) & xmlContent
End Sub
This offers an opportunity to extremely expand what can be done just using pure Basic.