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

Ooowriter+delphi: how to insert text after bookmarks

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Code Snippets
View previous topic :: View next topic  
Author Message
blackbird_dream
Newbie
Newbie


Joined: 25 Jun 2006
Posts: 4

PostPosted: Wed Jul 12, 2006 8:52 am    Post subject: Ooowriter+delphi: how to insert text after bookmarks Reply with quote

The following example needs the OOoconstants unit implemented by Mr Marcelly (thanks to him).
It opens the file named "test.odt" which is a Ooowriter document that contains a table with two bookmarks positioned in different cells (of course this document must be created first). the bookmarks are named "ici" and "la".
The programs writes down "hello world" at "ici" bookmark and "I am here now" at "la" bookmark.
Here is the full code :

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,Comobj ,StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Déclarations privées }
public
{ Déclarations publiques }
end;

var
Form1: TForm1;

implementation

uses OOoconstants;
{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
OpenDesktop : Variant;
LoadParams : Variant;
NomFichier : AnsiString; OpenOffice : Variant;
Document,text,cursor,xtable,cellule,tableborder,HelpLine,marks,anchor: Variant;
begin
OpenOffice:=CreateOleObject('com.sun.star.ServiceManager');
OpenDesktop := OpenOffice.createInstance('com.sun.star.frame.Desktop');
NomFichier := 'file:///'+StringReplace(extractFilePath(application.exename)+'test.odt', '\', '/', [rfReplaceAll, rfIgnoreCase]);
Document:=OpenDesktop.LoadComponentFromURL( NomFichier, '_blank',0, VarArrayCreate([0, - 1], varVariant));
Marks := Document.getBookmarks;
Anchor := Marks.getByName('ici').getAnchor;
Text := Anchor.getText;
Cursor := Text.createTextCursorByRange(Anchor.getStart);
Text.insertString(Cursor, 'hello world', False);
Anchor := Marks.getByName('la').getAnchor;
Text := Anchor.getText;
Cursor := Text.createTextCursorByRange(Anchor.getStart);
Text.insertString(Cursor, 'I am here now', False);
end;

end.
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 Code Snippets 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