How to duplicate the information contained in range to prese

Java, C++, C#, Delphi... - Using the UNO bridges
Post Reply
User avatar
GeorgeB
Posts: 2
Joined: Fri May 20, 2011 4:05 am
Location: Russia, Irkutsk

How to duplicate the information contained in range to prese

Post by GeorgeB »

Hello everybody.
I'm using OpenOffice Writer to generate reports. I work in Delphi 2010 and use OLE to communicate with the Writer.
I have a problem with handling text. The text contains tags that I find with FindFirst / FindNext and replaced by data from the database. Tags can be nested (between the opening and closing tag can have other tags, and within a selected range may be a text with different formatting, and also table data).
The database can return multiple values, so I need to duplicate the content inside the opening / closing tags.
How to duplicate the information contained between the opening and closing tags to preserve formatting? And how to run recursively processing within a selected range (FindFirst / FindNext only within the selected range)?

Code: Select all

TextDocument.insertString (SelectedRange, SelectedRange.getString, NotReplace) 
does not preserve the formatting. Using the Clipboard (

Code: Select all

dispatcher.executeDispatch (document, ". Uno: Copy", "", 0, Array ())
) is highly undesirable, because subqueries in the long term is not limited. And is there a Writer function similar Range.Duplicate in Microsoft Office?
Also I think that I will have problems like this http://user.services.openoffice.org/en/ ... 91#p180530, because, I too use MSOffice documents as a basis. Any ideas?

P.S. Sorry for my bad English.
OpenOffice 3.3 on Windows 7, Embarcadero Rad Studio 2010 (Delphi 2010)
FJCC
Moderator
Posts: 9623
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: How to duplicate the information contained in range to p

Post by FJCC »

I don't understand everything you are trying to do, but I think I can help with some aspects of it. I don't know how to limit a search to a selected region, but one can test if a found string is within a given range. The following code starts searching for the string "he was" at the beginning of whatever text is highlighted. If the string is found, the code then tests whether the found string is within the selected range. If it is, the text is replace with "new inserted text". If the found string is uniformly formatted, say all in bold, the inserted text preserves that formatting, at least it seems to in the few tests I have done.

Code: Select all

oText = ThisComponent.getText()
S_Desc = ThisComponent.createSearchDescriptor()
S_Desc.SearchString = "he was"
S_Desc.SearchWords = True
oSelContainer = ThisComponent.getCurrentSelection()
oSel = oSelContainer.getByIndex(0)
oFoundStr = ThisComponent.findNext(oSel.Start, S_Desc)
If IsNull(oFoundStr)Then
	Print "No match found"
	Else
	Position = oText.compareRegionStarts(oSel.End, oFoundStr)
	If Position = -1 Then  '-1 means oSel.End is behind oFoundStr in the text
		Print "String is in selection"
		oFoundStr.string = "new inserted text"
	Else 
		Print "String is beyond selection"
	End If
End If
Of course, this isn't exactly what you want to do. It is just meant as an illustration of the methods.
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
GeorgeB
Posts: 2
Joined: Fri May 20, 2011 4:05 am
Location: Russia, Irkutsk

Re: How to duplicate the information contained in range to p

Post by GeorgeB »

My primary question was about copying all the contents (with formatting, tables, images, and so on) of a text range into some other position in the document. I don't like to use clipboard, and it is not enough for me to copy the text only without formatting (using GetString / insertString). In VBA the problem is solved very easy by Dest.FormattedText := Src , where Dest and Src are text ranges. Is there something analogous in OO?
OpenOffice 3.3 on Windows 7, Embarcadero Rad Studio 2010 (Delphi 2010)
Post Reply