Recent

Author Topic: Operating on OpenOffice.org  (Read 251 times)

egsuh

  • Full Member
  • ***
  • Posts: 212
Operating on OpenOffice.org
« on: May 10, 2019, 02:09:23 pm »
Hi, I'm trying to opeate on OpenOffice.org text document. Here's my quick code.


Code: Pascal  [Select]
  1. uses
  2.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
  3.   Variants, ComObj;
  4.  
  5. const
  6.    ServerName = 'com.sun.star.ServiceManager';
  7.  
  8. type
  9.  
  10.   { TForm1 }
  11.  
  12.   TForm1 = class(TForm)
  13.     Button1: TButton;
  14.     Memo1: TMemo;
  15.     procedure Button1Click(Sender: TObject);
  16.   private
  17.  
  18.   public
  19.     Server     : Variant;
  20.     Desktop    : Variant;
  21.     LoadParams : Variant;
  22.     Document   : Variant;
  23.     TextCursor : Variant;
  24.   end;
  25.  
  26. const
  27.    fn = 'C:\Users\SEG\Projects\ZZZ-Others\FirstStepsBasic.odt';
  28.  
  29. var
  30.   Form1: TForm1;
  31.  
  32.  
  33. implementation
  34.  
  35. {$R *.lfm}
  36.  
  37.  
  38. { TForm1 }
  39.  
  40. procedure TForm1.Button1Click(Sender: TObject);
  41. var
  42.   enum1, enum2,
  43.     TextElement : Variant;
  44. begin
  45.   try
  46.     Server := CreateOleObject(ServerName);
  47.   except
  48.     WriteLn('Unable to start OO.');
  49.     Exit;
  50.   end;
  51.  
  52.   Desktop := Server.CreateInstance('com.sun.star.frame.Desktop');
  53.   LoadParams := VarArrayCreate([0, -1], varVariant);
  54.  
  55.   Document := Desktop.LoadComponentFromURL('file:///C:/Users/SEG/Documents/ZZZ-Others/FirstStepsBasic.odt',
  56.                '_blank', 0, LoadParams);
  57.  
  58.   enum1 := Document.Text.CreateEnumeration;
  59.  
  60.   while enum1.HasMoreElements do begin
  61.      TextElement := enum1.NextElement;
  62.      if TextElement.SupportsService('com.sun.star.text.Paragraph') then
  63.         memo1.lines.add (TextElement.ParaStyleName); // I need  "TextElement.String"
  64.   end;
  65. end;
  66.  

This codes work fine, but what I want is to use 'textelement.string'.

Problem is "string" is a property of an OpenOffice object Paragraph, but it is a reserved word in Object Pascal.

Document, enum1, etc. are defined as object in the OpenOffice.org Basic. 

Regards,
 

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 7354
Re: Operating on OpenOffice.org
« Reply #1 on: May 10, 2019, 02:13:47 pm »
Try    textelement.&string

& is an escape for such purposes.

egsuh

  • Full Member
  • ***
  • Posts: 212
Re: Operating on OpenOffice.org
« Reply #2 on: May 10, 2019, 02:21:14 pm »
Oh Yes !!!!!   This works.

Really thank you.

But, just before I saw your replay, I found  "TextElement.getString ()" also works. It's like that "string" is property name in Pascal, and  getString() is its method name. It seems there are no private methods in OOs ^^.

But anyway your comment is really helpful. Thank you again.