[Solved] Put ODT content into variable (VB6)

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
User avatar
AccessShell
Posts: 47
Joined: Tue Apr 05, 2022 2:17 am

[Solved] Put ODT content into variable (VB6)

Post by AccessShell »

I am using Windows 10 home, VB6, and LO 7.3.2.2 (x64)

I have written some code that needs one more line. I need to open a Writer file (.odt) as hidden for read only. I need to place the contents of this file into a variable for further processing (parsing).

Code: Select all

Option Explicit

Dim oSM          As Object    'Root object for accessing OpenOffice from VB --> (ServiceManager)
Dim oDesk        As Object    'First objects from the API
Dim oDoc         As Object    'First objects from the API
Dim strFileName  As String

Sub main()
Dim OpenParam(1) As Object    'Parameters to open the doc
Dim SaveParam(1) As Object    'Parameters to save the doc
Dim vartest      As Variant
Dim strtest      As String
Dim NF           As String

    Set oSM = CreateObject("com.sun.star.ServiceManager")

    Set oDesk = oSM.createInstance("com.sun.star.frame.Desktop")

    'Open existing doc
    Set OpenParam(0) = mAkePropertyValue("Hidden", True)  ' Open the file hidden
    Set oDoc = oDesk.loadComponentFromURL("file:///C:/LibreOffice workspace/VB6 on Writer/Test Writer.odt", "_blank", 0, OpenParam)
    
    '**************************************************************************
    'NEED SOME CODE HERE TO Place the contents of the .odt file into a variable
    ' believe it is only two lones of code
    '**************************************************************************
    
    'Close
    oDoc.Close (True)
    Set oDoc = Nothing
    'Set oDesk = Nothing
    oDesk.Terminate
    Set oSM = Nothing

End Sub

Private Function mAkePropertyValue(cName, uValue)
Dim oStruct

    Set oStruct = oSM.Bridge_getStruct("com.sun.star.beans.PropertyValue")
    oStruct.Name = cName
    oStruct.Value = uValue
    Set mAkePropertyValue = oStruct
    
    'Set oStruct = Nothing     'Do I need this statement?
    
End Function
Thanks
 Edit: Changed subject, was VB6 on LO Writer 
Make your post understandable by others 
-- MrProgrammer, forum moderator 
Last edited by AccessShell on Tue Apr 12, 2022 5:23 pm, edited 1 time in total.
LibreOffice 7.3.3.2 (x64) on Windows 10 Home
JeJe
Volunteer
Posts: 2763
Joined: Wed Mar 09, 2016 2:40 pm

Re: Put ODT content into variable (VB6)

Post by JeJe »

An odt file is a zip file with a lot of xml files within it. OO/LO have the tools to parse these - there's an example of using the XML parser from Basic here:

https://wiki.openoffice.org/wiki/XML_and_Filter

Why would you want to load the whole zip file into a variable?
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
AccessShell
Posts: 47
Joined: Tue Apr 05, 2022 2:17 am

Re: Put ODT content into variable (VB6)

Post by AccessShell »

I need to parse the contents of an LO Writer file. The data I need is scattered throughout the file. I thought .odt is a Writer file, just as .doc is an MS Word file.
LibreOffice 7.3.3.2 (x64) on Windows 10 Home
JeJe
Volunteer
Posts: 2763
Joined: Wed Mar 09, 2016 2:40 pm

Re: Put ODT content into variable (VB6)

Post by JeJe »

If you unzip one of your Writer files you can take a look at the contents - and for more information look up the open document file format specification.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
AccessShell
Posts: 47
Joined: Tue Apr 05, 2022 2:17 am

Re: Put ODT content into variable (VB6)

Post by AccessShell »

OK, so I a bit confused. Using similar code (see previous thread by me) I opened a LO CALC (.ods) file to modify. Is the CALC file also a zip file?
LibreOffice 7.3.3.2 (x64) on Windows 10 Home
JeJe
Volunteer
Posts: 2763
Joined: Wed Mar 09, 2016 2:40 pm

Re: Put ODT content into variable (VB6)

Post by JeJe »

You can answer that yourself by trying to unzip it.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
AccessShell
Posts: 47
Joined: Tue Apr 05, 2022 2:17 am

Re: Put ODT content into variable (VB6)

Post by AccessShell »

I don't know how to do that
LibreOffice 7.3.3.2 (x64) on Windows 10 Home
FJCC
Moderator
Posts: 9248
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Put ODT content into variable (VB6)

Post by FJCC »

Getting the content of a Writer file, in OpenOffice Basic, might be as simple as

Code: Select all

  oText = ThisComponent.getText()
  sString = oText.getString()
It depends on how complex the file content is. ThisComponent refers to the document. Translate the above into VB6 and see if sString contains what you need.
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
User avatar
AccessShell
Posts: 47
Joined: Tue Apr 05, 2022 2:17 am

Re: Put ODT content into variable (VB6)

Post by AccessShell »

FJCC, thanks. It worked just as I needed it.
LibreOffice 7.3.3.2 (x64) on Windows 10 Home
JeJe
Volunteer
Posts: 2763
Joined: Wed Mar 09, 2016 2:40 pm

Re: [Solved] Put ODT content into variable (VB6)

Post by JeJe »

Be aware that that gets the main document text. If there's a text frame - it has its own separate text. If there's a table each cell has its own separate text etc. Getstring lacks any formatting information and there's a string size limit meaning it will fail if the document is large.

A search for Window 10 unzip will show you how to unzip a file... right click on the file etc...
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
AccessShell
Posts: 47
Joined: Tue Apr 05, 2022 2:17 am

Re: [Solved] Put ODT content into variable (VB6)

Post by AccessShell »

What is the definition here for a large file. Is 900 kb too large. I'll try it. I am not sue about frames and tables.
In the past I have been using MS Word for parsing. Trying to wean off of MS Office.

I tried to right click on an LO office file. I found nothing that will "unzip"
LibreOffice 7.3.3.2 (x64) on Windows 10 Home
JeJe
Volunteer
Posts: 2763
Joined: Wed Mar 09, 2016 2:40 pm

Re: [Solved] Put ODT content into variable (VB6)

Post by JeJe »

The maximum string size might be 65536 or 32768 - like you say you try it and find out. But like I said the text and the string above isn't the file itself.

The first google return for a windows 10 unzip file search says
Right-click the ZIP file. In the drop-down menu, click "Extract All…" The zip wizard will appear. ...
Edit:

You have to able to do a simple search like that.

Edit2:
And likewise a search of - what is an ods file? - would answer your earlier question. You can find these things out yourself with basic searches.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
AccessShell
Posts: 47
Joined: Tue Apr 05, 2022 2:17 am

Re: [Solved] Put ODT content into variable (VB6)

Post by AccessShell »

Yes, when I right click on a .zip file I get 'Extract All".

One of the previous posts said to right click on an .ods or a .odt and there would be option to "Extract All" option. NOT TRUE

I'll keep searching for what is an .ods and .odt files
LibreOffice 7.3.3.2 (x64) on Windows 10 Home
JeJe
Volunteer
Posts: 2763
Joined: Wed Mar 09, 2016 2:40 pm

Re: [Solved] Put ODT content into variable (VB6)

Post by JeJe »

I put:
A search for Window 10 unzip will show you how to unzip a file... right click on the file etc...
But you didn't do the search though did you? You can help yourself by doing simple searches - quicker that asking.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
robleyd
Moderator
Posts: 5055
Joined: Mon Aug 19, 2013 3:47 am
Location: Murbko, Australia

Re: [Solved] Put ODT content into variable (VB6)

Post by robleyd »

You could of course copy the file and rename the copy as .zip
Cheers
David
OS - Slackware 15 64 bit
Apache OpenOffice 4.1.15
LibreOffice 24.2.1.2; SlackBuild for 24.2.1 by Eric Hameleers
User avatar
AccessShell
Posts: 47
Joined: Tue Apr 05, 2022 2:17 am

Re: [Solved] Put ODT content into variable (VB6)

Post by AccessShell »

I did that. The "Extract All" did not show up.
LibreOffice 7.3.3.2 (x64) on Windows 10 Home
User avatar
Zizi64
Volunteer
Posts: 11352
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: [Solved] Put ODT content into variable (VB6)

Post by Zizi64 »

I did that. The "Extract All" did not show up.
I am using some old fashioned (two panels) file manager softwares for this task (like the Total Commander or the Double Commander).
I just rename a copy of the .ods, .odt file, to same file name but .zip extension, and then a double click on the name of the .zip file (in the Commander list), and the inside directories and files will be extracted. Then I can examine the content of an ODF file.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
JeJe
Volunteer
Posts: 2763
Joined: Wed Mar 09, 2016 2:40 pm

Re: [Solved] Put ODT content into variable (VB6)

Post by JeJe »

I use Peazip but there are a lot of other free (and not free) unzip managers. If you install that there will be a Peazip entry when right clicking the file in Windows explorer and you can unzip a .odt file without having to change the extension if Windows 10 doesn't do it natively.

https://peazip.github.io/
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Post Reply