OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

How to copy complex content in C++ or Java?

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
Augur
Newbie
Newbie


Joined: 18 Apr 2005
Posts: 4
Location: France

PostPosted: Mon Apr 18, 2005 11:45 pm    Post subject: How to copy complex content in C++ or Java? Reply with quote

Hi,

I'm new to OOo dev. I've searched during days on OOoForum and dev mailing list archives. I found pieces of answer, but these elements were not alway very clear.

I need to integrate OOo into my application, and be able to generate OWriter documents from data of my software. The thing is that I want to let the user create its own template, in order that it is not hard coded in my app.

I will give to the user the opportunity of inserting predefined user text field in the template. I'll then replace those fields automatically with the corresponding values.

My problems come with data repetition. For example, let's say that my application manages a contact list. The user creates a new template in order to generate a full address book. To be more readable, each field beginning by a $ is a user TextField (even if it isn't valid to put a $ in a field name). So, he designes a template like this:

----------------------MY ADDRESS BOOK ---------------------

$BEGIN_REPEAT
---------------------------------------------------------------------
| $LASTNAME $FIRSTNAME
---------------------------------------------------------------------
| $ADDRESS
|
| phone : $PHONE
| email : $EMAIL
---------------------------------------------------------------------
$END_REPEAT

---------------------------------------------------------------------

Then, I want to load the template, detect the content between the BEGIN/END _REPEAT markup, and copy it as many times that I have contact entries in my app.

So here are my questions:

1) How to copy a range of document (including both text, table, and any other content like picture) ? By the creation of a TextRange and the insertion of TextRange.getText()? Using the dispatcher and ".uno.copy"?

2) Is it possible to modify a copied content before pasting it? Here I need to replace the text field with the correct values before inserting it in the final document.

3) Do you think there is a simpler notation for my notion of template? I know that what I want to do is a kind of XSLT, but I must allow those fonctionnality for users that really don't care of what it is.

Thanks in advance for any answer or advice.
--
Augur
Back to top
View user's profile Send private message
DaRtY
General User
General User


Joined: 25 Mar 2005
Posts: 18

PostPosted: Tue Apr 19, 2005 12:13 am    Post subject: Reply with quote

Hi,

I have got the exact same problem.
I tried to copy the text with the following code:
Code:

String document = xText.getString();
for(int i = 0; i<v.size() ; i++){
xText.insertString(xCursor.getStart(), document, true);
}

where v is a Vector with all the adresses.
It worked, but the layout got lost.
So if I had some text that was bold or underlined, then after pasting it, it wasn't bold or underlined anymore, or worse, everthing was bold or underlined.

So maybe if someone knows how to copy the layout, ... .

Currently I've solved the problem by opening the template file, make the changes, save it, close it, reopen it, make the second change, save it, close it, etc
It works perfectly, but the result is that you have multiple files instead of 1 big file.

Quote:
2) Is it possible to modify a copied content before pasting it? Here I need to replace the text field with the correct values before inserting it in the final document.


Say you have the following file:

$BEGIN_REPEAT
Name: $name
Adress: $adress
$END_REPEAT

I would copy the content, then paste it once, make some changes, paste it for a second time make some changes, ...

Result:

Name: Me
Adress: here

Name: $name
Adress: $adress

So when you replace all instances of $name, Java would only change 1 instance, because you've allready changed the previous one, and there is only one left.

I hope this could help a bit.
Sorry for my awfull english, I hope I made some scence Very Happy

Thnx and Greetz
Back to top
View user's profile Send private message
pitonyak
Administrator
Administrator


Joined: 09 Mar 2004
Posts: 3655
Location: Columbus, Ohio, USA

PostPosted: Tue Apr 19, 2005 5:23 am    Post subject: Reply with quote

I expect that you must...

Use the current controller to select the range that you want to copy.
Copy the selected text using a dispatch.
Move the view cursor to the desired "paste" location.
Use the current controller to paste the copied text.

This is the easiest way to copy formatted text content and text tables. Of course, you will have issues with the text fields. I assume that you will end up removing the text field and replacing it with your specific text. You can not easily replace this before pasting back into the document.
_________________
--
Andrew Pitonyak
http://www.pitonyak.org/oo.php
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
Augur
Newbie
Newbie


Joined: 18 Apr 2005
Posts: 4
Location: France

PostPosted: Tue Apr 19, 2005 7:00 am    Post subject: Reply with quote

pitonyak wrote:
I expect that you must...

Use the current controller to select the range that you want to copy.
Copy the selected text using a dispatch.
Move the view cursor to the desired "paste" location.
Use the current controller to paste the copied text.


Ok, this is what I thought. Is there a document which collects all the URL working with dispatcher? I didn't found one, that's why I'm a bit lost with Dispatcher.

Quote:
This is the easiest way to copy formatted text content and text tables. Of course, you will have issues with the text fields. I assume that you will end up removing the text field and replacing it with your specific text. You can not easily replace this before pasting back into the document.


Ok thank you, I'll try it. You confirm what I thought. It's cool to know that I'm not on the wrong way.
--
Augur[/quote]
Back to top
View user's profile Send private message
Augur
Newbie
Newbie


Joined: 18 Apr 2005
Posts: 4
Location: France

PostPosted: Tue Apr 19, 2005 7:08 am    Post subject: Reply with quote

DaRtY wrote:
Hi,
I have got the exact same problem.

Yeah, I saw your thread. I was disappointed that you didn't get a clear answer to your questions.

Quote:

Currently I've solved the problem by opening the template file, make the changes, save it, close it, reopen it, make the second change, save it, close it, etc
It works perfectly, but the result is that you have multiple files instead of 1 big file.

Yes why not, it's a solution but your true, this is not very pretty Very Happy

Quote:

I would copy the content, then paste it once, make some changes, paste it for a second time make some changes, ...

I thought about this solution after posting. It's true that if the fields are replaced since the beginning, it's no more a problem.

Quote:

I hope this could help a bit.
Sorry for my awfull english, I hope I made some scence Very Happy

Thank you for your answers. And don't care, my english isn't very good too Very Happy
--
Augur
Back to top
View user's profile Send private message
pitonyak
Administrator
Administrator


Joined: 09 Mar 2004
Posts: 3655
Location: Columbus, Ohio, USA

PostPosted: Wed Apr 20, 2005 7:04 am    Post subject: Reply with quote

I list all of the dispatches on page 192 of my book Smile
I also indicate how to find the latest list.... go here
http://api.openoffice.org/servlets/ProjectDownloadList
And download the slots document.
_________________
--
Andrew Pitonyak
http://www.pitonyak.org/oo.php
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
Akhorahil
General User
General User


Joined: 30 May 2005
Posts: 11

PostPosted: Wed Jun 01, 2005 1:03 am    Post subject: Reply with quote

Hi,

I do have the same problem you have, could you post some code snippet that shows how you solved it?

I've got the copying working, but only for simple text. I can't get it to copy complex data.

TiA,

Alexander
Back to top
View user's profile Send private message
Augur
Newbie
Newbie


Joined: 18 Apr 2005
Posts: 4
Location: France

PostPosted: Wed Jun 01, 2005 1:25 am    Post subject: Reply with quote

It still doesn't work, because I've got problem to make dispatch work without crashing ooffice. So I gave up for a moment.
_________________
--
Augur
Back to top
View user's profile Send private message
Akhorahil
General User
General User


Joined: 30 May 2005
Posts: 11

PostPosted: Mon Jun 06, 2005 12:06 am    Post subject: Reply with quote

Augur wrote:
It still doesn't work, because I've got problem to make dispatch work without crashing ooffice. So I gave up for a moment.


Could you post the code you made? I would like to take a look at it and try to get it working.

Does someone else perhaps have any hints/clues on how to get this working?

TiA

Alexander
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group