[Solved] ThisComponent.getText() empty ?

Creating a macro - Writing a Script - Using the API

[Solved] ThisComponent.getText() empty ?

Postby BubikolRamios » Fri Jan 05, 2018 6:44 am

Code: Select all   Expand viewCollapse view
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
BubikolRamios
 
Posts: 39
Joined: Sat Jan 04, 2014 1:28 pm

Re: ThisComponent.getText() empty ?

Postby FJCC » Fri Jan 05, 2018 7:27 am

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   Expand viewCollapse view
MsgBox oDoc.getText().getString()

You should get one of the extensions XRay or MRI so you can inspect the objects in you code.
Windows 10 and Linux Mint, since 2017
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
FJCC
Moderator
 
Posts: 7090
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: ThisComponent.getText() empty ?

Postby BubikolRamios » Fri Jan 05, 2018 8:49 am

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

Re: ThisComponent.getText() empty ?

Postby BubikolRamios » Fri Jan 05, 2018 9:07 am

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
BubikolRamios
 
Posts: 39
Joined: Sat Jan 04, 2014 1:28 pm

Re: ThisComponent.getText() empty ?

Postby Zizi64 » Fri Jan 05, 2018 10:07 am

Code: Select all   Expand viewCollapse view
'further on trying to replace some strings, with no effect obviously


It works for me:

Code: Select all   Expand viewCollapse view
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:
https://forum.openoffice.org/en/forum/v ... 20&t=69107
Tibor Kovacs, Hungary; LO4.4.7, LO6.1.5 on Win7-10 x64Prof.
PortableApps, winPenPack: LO3.3.0-6.2.2; AOO4.1.5
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
Zizi64
Volunteer
 
Posts: 7827
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: ThisComponent.getText() empty ?

Postby Villeroy » Fri Jan 05, 2018 12:56 pm

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, OpenOffice 4.x & LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 26555
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: ThisComponent.getText() empty ?

Postby BubikolRamios » Wed Feb 28, 2018 9:43 am

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

Code: Select all   Expand viewCollapse view
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 40 times
OPen office 4.1.5/ win 7
BubikolRamios
 
Posts: 39
Joined: Sat Jan 04, 2014 1:28 pm

Re: ThisComponent.getText() empty ?

Postby Zizi64 » Wed Feb 28, 2018 10:45 am

Here are two lines from your code.

Code: Select all   Expand viewCollapse view
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; LO4.4.7, LO6.1.5 on Win7-10 x64Prof.
PortableApps, winPenPack: LO3.3.0-6.2.2; AOO4.1.5
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
Zizi64
Volunteer
 
Posts: 7827
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: ThisComponent.getText() empty ?

Postby Lupp » Wed Feb 28, 2018 6:54 pm

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 6.2 and older versions, PortableOpenOffice 4.1.5 and older, StarOffice 5.2
---
Lupp from München
User avatar
Lupp
Volunteer
 
Posts: 2369
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: ThisComponent.getText() empty ?

Postby BubikolRamios » Wed Feb 28, 2018 8:04 pm

Thanks.
Lost that inbetween hunting zillion other things.
OPen office 4.1.5/ win 7
BubikolRamios
 
Posts: 39
Joined: Sat Jan 04, 2014 1:28 pm

Re: ThisComponent.getText() empty ?

Postby Hagar Delest » Wed Feb 28, 2018 10:19 pm

Should the topic be tagged solved?
AOO 4.1.6 on Xubuntu 18.10 and 4.1.5 on Windows 7 (with winPenPack port).
User avatar
Hagar Delest
Moderator
 
Posts: 28431
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: ThisComponent.getText() empty ?

Postby BubikolRamios » Wed Feb 28, 2018 11:07 pm

OK. Solved, with note.

Code: Select all   Expand viewCollapse view
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
BubikolRamios
 
Posts: 39
Joined: Sat Jan 04, 2014 1:28 pm

Re: ThisComponent.getText() empty ?

Postby Hagar Delest » Wed Feb 28, 2018 11:10 pm

But it seemed to work with Lupp, didn't it?
If there is still an issue then keep the discussion open.
AOO 4.1.6 on Xubuntu 18.10 and 4.1.5 on Windows 7 (with winPenPack port).
User avatar
Hagar Delest
Moderator
 
Posts: 28431
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

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

Postby Zizi64 » Wed Feb 28, 2018 11:20 pm

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; LO4.4.7, LO6.1.5 on Win7-10 x64Prof.
PortableApps, winPenPack: LO3.3.0-6.2.2; AOO4.1.5
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
Zizi64
Volunteer
 
Posts: 7827
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

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

Postby BubikolRamios » Thu Mar 01, 2018 9:06 am

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
BubikolRamios
 
Posts: 39
Joined: Sat Jan 04, 2014 1:28 pm

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

Postby Zizi64 » Thu Mar 01, 2018 11:19 am

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; LO4.4.7, LO6.1.5 on Win7-10 x64Prof.
PortableApps, winPenPack: LO3.3.0-6.2.2; AOO4.1.5
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
Zizi64
Volunteer
 
Posts: 7827
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

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

Postby Lupp » Thu Mar 01, 2018 4:44 pm

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 6.2 and older versions, PortableOpenOffice 4.1.5 and older, StarOffice 5.2
---
Lupp from München
User avatar
Lupp
Volunteer
 
Posts: 2369
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 2 guests