[Solved] ThisComponent.getText() empty ?

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
BubikolRamios
Posts: 91
Joined: Sat Jan 04, 2014 1:28 pm

[Solved] ThisComponent.getText() empty ?

Post by BubikolRamios »

Code: Select all

Option Explicit
sub Main
rem ----------------------------------------------------------------------

   Dim oDoc As Object
   Dim oText As Object
   
   oDoc = ThisComponent
   MsgBox oDoc.getText() '--> EMPTY STRING
   'further on trying to replace some strings, with no effect obviously
Macro is part of alpenflora.odt and that is not empty.
tmp.jpg
Last edited by BubikolRamios on Wed Feb 28, 2018 11:14 pm, edited 5 times in total.
OPen office 4.1.5/ win 7
FJCC
Moderator
Posts: 9248
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: ThisComponent.getText() empty ?

Post by FJCC »

The Text property of a Writer document it not simply the words in the document. It is a complex object with methods for adding and deleting text, inserting images etc. It does have a String property so you can get what you were expecting in the message box with

Code: Select all

MsgBox oDoc.getText().getString()
You should get one of the extensions XRay or MRI so you can inspect the objects in you code.
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.
BubikolRamios
Posts: 91
Joined: Sat Jan 04, 2014 1:28 pm

Re: ThisComponent.getText() empty ?

Post by BubikolRamios »

Empty string
Attachments
tmp.jpg
tmp.jpg (11.68 KiB) Viewed 4712 times
OPen office 4.1.5/ win 7
BubikolRamios
Posts: 91
Joined: Sat Jan 04, 2014 1:28 pm

Re: ThisComponent.getText() empty ?

Post by BubikolRamios »

Xray oDoc.getText()
StartRedline []struct <empty> read-only, may be void
EndRedline []struct <empty> read-only, may be void
ImplementationName string "SwXBodyText" (get), read-only
SupportedServiceNames []string (get), read-only
ElementType type (get), read-only
Types []type (get), read-only
ImplementationId []byte (get), read-only
Delegator object (set), write-only
Text object (get), read-only
Start object (get), read-only
End object (get), read-only
String string "" (get,set)
PropertySetInfo object (get), read-only
OPen office 4.1.5/ win 7
User avatar
Zizi64
Volunteer
Posts: 11353
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: ThisComponent.getText() empty ?

Post by Zizi64 »

Code: Select all

'further on trying to replace some strings, with no effect obviously
It works for me:

Code: Select all

Option Explicit

sub Main
rem ----------------------------------------------------------------------

 Dim oDoc As Object
 Dim oText As Object
 Dim sTheString As String
 	
	oDoc = ThisComponent
	Xray oDoc
	oText = oDoc.getText()
	sTheString = oText.getString
	MsgBox(sTheString)
	oText.setString("Hello World!")	

	'MsgBox oDoc.getText().getString()'further on trying to replace some strings, with no effect obviously
	
End sub
If you want to modify a part of the text content, then you need get/set/modify a specific Paragraph, but not the whole text content. A similar topic:
viewtopic.php?f=20&t=69107
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.
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: ThisComponent.getText() empty ?

Post by Villeroy »

There is no text in the text body. Your document consists of frames, pictures and other shapes.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
BubikolRamios
Posts: 91
Joined: Sat Jan 04, 2014 1:28 pm

Re: ThisComponent.getText() empty ?

Post by BubikolRamios »

Bringing this up.
I think probably at original file which is 'enormous' maybe :

Code: Select all

 msgbox (oDoc.getText().getString())
produces empty string because otherwise msgbox would crash ?

Attached top portion of original odt.
Anyway, attached macro does not replace anything, added extra
Blü.
Frkn.
to top, to be outside of table & to exclude possible not ordinary char problem.
And it does not replace anything.
Any tip ?
Attachments
alpenflora1.odt
(20.49 KiB) Downloaded 140 times
OPen office 4.1.5/ win 7
User avatar
Zizi64
Volunteer
Posts: 11353
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: ThisComponent.getText() empty ?

Post by Zizi64 »

Here are two lines from your code.

Code: Select all

oReplace.SearchString = matrix(i)(0) + " "  
oReplace.ReplaceString =  matrix(i)(1) + " " 
The Text of your document do not contain any space characters after the abbreviations. The function will not found the strings with the added (but non-existing) space.
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.
User avatar
Lupp
Volunteer
Posts: 3542
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: ThisComponent.getText() empty ?

Post by Lupp »

Anyway: If I execute the first three statements of the BASIC code contained in the attached .odt, I get the string created from the text as expected.
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
BubikolRamios
Posts: 91
Joined: Sat Jan 04, 2014 1:28 pm

Re: ThisComponent.getText() empty ?

Post by BubikolRamios »

Thanks.
Lost that inbetween hunting zillion other things.
OPen office 4.1.5/ win 7
User avatar
Hagar Delest
Moderator
Posts: 32627
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: ThisComponent.getText() empty ?

Post by Hagar Delest »

Should the topic be tagged solved?
LibreOffice 7.6.2.1 on Xubuntu 23.10 and 7.6.4.1 portable on Windows 10
BubikolRamios
Posts: 91
Joined: Sat Jan 04, 2014 1:28 pm

Re: ThisComponent.getText() empty ?

Post by BubikolRamios »

OK. Solved, with note.

Code: Select all

msgbox (oDoc.getText().getString())
shows as empty box for some reason.
See above.

Edit: Cant figure how to make it solved, topic icons shows no hints ...
Last edited by BubikolRamios on Wed Feb 28, 2018 11:12 pm, edited 2 times in total.
OPen office 4.1.5/ win 7
User avatar
Hagar Delest
Moderator
Posts: 32627
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: ThisComponent.getText() empty ?

Post by Hagar Delest »

But it seemed to work with Lupp, didn't it?
If there is still an issue then keep the discussion open.
LibreOffice 7.6.2.1 on Xubuntu 23.10 and 7.6.4.1 portable on Windows 10
User avatar
Zizi64
Volunteer
Posts: 11353
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: [Solved] ThisComponent.getText() empty ?

Post by Zizi64 »

OK. Solved, with note.

Code: Select all Expand view
msgbox (oDoc.getText().getString())


shows as empty box for some reason.
See above.
It works for me (with your sample file) in AOO 4.1.5 portable on Win7x64pro:
getText_macro_MsgBox.png
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.
BubikolRamios
Posts: 91
Joined: Sat Jan 04, 2014 1:28 pm

Re: [Solved] ThisComponent.getText() empty ?

Post by BubikolRamios »

it does for me to, on sample file.
I think probably at original file which is 'enormous' maybe :

Code: Select all Expand view
msgbox (oDoc.getText().getString())

produces empty string because otherwise msgbox would crash ?
OPen office 4.1.5/ win 7
User avatar
Zizi64
Volunteer
Posts: 11353
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: [Solved] ThisComponent.getText() empty ?

Post by Zizi64 »

OPen office 4.0.1/ win 7
Maybe it is a bug in your old version...

Code: Select all Expand view
What is it?
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.
User avatar
Lupp
Volunteer
Posts: 3542
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: [Solved] ThisComponent.getText() empty ?

Post by Lupp »

I remembered https://wiki.documentfoundation.org/Rel ... paragraphs: Since V4.3.0 LibO raised the limit of he number of characters per paragraph to 2^31-1 while it remained 2^16-1 in AOO. As I mostly test with LibO I even got (after waiting about 15 s) the sting of the complete text of a document with more than 135000 characters. For the same document AOO presents an empty string. It seems not only the paragraph length remainede limited by 65535, but string length generally. Not applicable string properties are generally set empty (as viewable inspecting the objects).
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
Post Reply