Open Office Macros Rus

Embed Size (px)

Citation preview

OpenOffice - ( , . buhcia2006 dog yandex dot ru. BuhCIA. "", "" Andrew Pitonyak) Useful Macro Information For OpenOffice By () Andrew Pitonyak Andrew Pitonyak: OpenOffice.org Macros Explained. . , , . : July 22, 2007 at 23:0413:07:00 PM Document Revision: 1012 http://www.pitonyak.org/AndrewMacro.odt :

Michelle Pitonyak u . Laurent Godard ( ) . Hermann-Josef Beckers . , Robert Black Eagle, , Howto ( ). , Kelvin Eldridge . Jean Hollis Weber Solveig Haugland , . , Sasa Kelecevic Hermann Kienlein, , . Andreas Bregas , . Mathias Bauer , . Open Source , . Jean Hollis Weber C Robert Pearsall 2004. Christian Junker . , . . , () , , - . Andrew Pitonyak 6888 Bowerman Street West Worthington, OH 43085 USA

: [email protected] : : 614-438-0190 : 614-937-4641 : , . , . (Oakland) , . (Ohio State University) , , , . (Public Documentation License) 1.0 (Public Documentation License Version 1.0), , . http://www.openoffice.org/licenses/pdl.pdf http://www.pitonyak.org/AndrewMacro.odt

:Contribution Original author French translation German Translation Macros Macros Contributor Andrew Pitonyak Contact [email protected] Copyright 2002-2007 2003 2003 2002-2003 2002-2003 2004 2007

The French Native-lang [email protected] documentation project Hermann-Josef Beckers Hermann Kienlein Sasa Kelecevic [email protected] [email protected] [email protected] [email protected] http://buhcia.narod.ru

Editing and additions Christian Junker Russian translation BuhCIA

1 .............................................................................................................................................25 1.1 .....................................................................................................27 1.2 BuhCIA........................................................................................27 2 ............................................................................................................................29 2.1 .............................................................................................................29 2.2 .......................................................................................................................29

2.3 ...........................................................................................33 3 : ............................................................................................................................35 3.1 : Hello World........................................................................................35 3.2 ................................................................................................37 3.3 .......................................................................................................................................37 3.4 , , ..............................................................37 3.5 (Objects) OpenOffice.................................39 3.6 UNO?...................................................................................................................41 3.6.1 ..........................................................................................................................43 3.6.2 .......................................................................................................................43 3.6.3 (Services).............................................................................................................45 3.6.4 (services)....................................................................................45 3.6.5 ?............................................................................................45 3.6.6 , , ?...................51 3.6.7 , Basic................................................................................................51 3.6.7.1 CreateUnoService...........................................................................................51 3.6.7.2 ThisComponent.................................................................53 3.6.7.3 StarDesktop............................................................................53 3.6.8 .........................55 3.7 ...........................................................................................................................................57 4 .............................................................................................................................................57 4.1 .................................................................................................57 4.1.1 ..............................................................................................57 4.1.2 , ...............................................61 4.2 X-Ray.........................................................................................................................63 4.3 OOo (Dispatch): Universal Network Objects (UNO).....................................................................................................................63 4.3.1 (Dispatcher - ) 1.1 OOo............67 4.3.2 (dispatcher - ) (UI).........................................................................................67 4.3.2.1 - (dispatcher - ). . .69 4.4 Basic...........................................71 5 ................................................................................................................................73 5.1 ...........................................................................................73 5.2 ...............................................................................75 5.3 ......................................................................................77 5.4 ..............................................................77 5.4.1 .....................................................................................79 5.5 ConfigurationProvider.......................79 5.6 ....................................................................................................81 5.6.1 ...............................................................................................83 5.6.2 ................................................................................................83 5.6.3 ........................................................................................................83 5.7 .................................................................................................85 5.7.1 OOo........................................................................................................................85 5.7.2 () OOo............................................................................................................85 5.8 ( ).................................................................87 5.8.1 OpenOffice / ............................................................................87

5.8.1.1 , () ?.....................................................................89 5.8.2 URL.........................................................................89 5.8.2.1 .........................................................................................................93 5.8.3 ......................................................................................95 5.8.4 ..........................................................95 5.8.5 LoadComponentFromURL.................................97 5.8.6 .................................................................97 5.8.7 Mail Merge .....99 5.9 / .................................................................................103 5.9.1 ..........................................................................................................................................105 5.9.2 Danny Brewer .......................................107 5.9.3 , (dispatcher - )...............................................................................................................................109 5.9.4 .......................................................109 5.10 ....................................................................................................................111 5.10.1 ...........................................................................................113 5.11 (Internet Explorer) OLE..................................115 5.12 Shell , ...................................115 5.13 ............................................................................................115 5.14 ......................................................................................117 5.14.1 ............................................119 5.15 ...............................................................................121 5.16 (Bookmark)..................................................................123 5.17 .......................................................................................123 5.18 ................................................................................................................125 5.18.1 ............................................................................................125 5.18.2 ..............................................................................................................129 5.18.3 - (Master)....................................................................................................131 5.18.4 ..........................................................................................139 5.18.5 URL OOo Calc ..................................................................141 5.18.6 - (SetExpression TextField)........................143 5.19 , ...................................................................145 5.20 , - .................................145 5.21 ................................................................................................149 5.22 (Page Background)...................................................................151 5.23 (clipboard)...............................................................................................151 5.23.1 Clipboard ......................................................................................................................................................151 5.23.2 ......................................................................................................................................................153 5.23.3 (content-type) Clipboard..............155 5.23.4 clipboard........................................................157 5.23.5 clipboard .....................................................159 5.23.6 clipboard (transferable content)...................................................................................................................161 5.24 ()....................................................................................................161 5.25 .......................................................................163

5.26 (Auto Text)...........................................................................................................167 5.27 ...................................................................................................173 5.27.1 ......................................................................................181 5.28 .......................................................................191 5.29 ...........................................................................................................195 5.29.1 ...........................................................................................................................195 5.29.1.1 .........................................................................195 5.29.1.2 .............................................................................................................195 5.29.1.3 ...................................................................................................................195 5.29.2 ?...........................................................................................197 5.29.3 ...................................................................................................197 5.29.4 .....................................................199 5.29.5 (load) ?...............................................................199 5.29.6 .......................................................201 5.30 (Bitmap)............................................................203 5.30.1 , , OOo Calc..............................................................................................................................................205 5.30.2 , .....................................................207 5.30.3 OOo Calc...............................................................211 5.31 Zip..........................................................................................................211 5.31.1 Zip-............................................................................................213 5.31.2 Zip ........................................................................217 5.32 ......................................................................223 5.32.1 ..................................................................225 5.32.2 ..............................................................225 5.33 " " ..............................227 5.34 .................................................................................................227 5.35 : URL, ..............................................229 5.36 (directory)..........................................................229 5.37 ..........................................................................................................................233 5.38 (Parsing) XML.................................................................235 5.39 Dates...........................................................................................................241 5.40 OpenOffice -?..............................................................................245 5.41 ( ) .....................................245 5.42 ( URL).......................................................245 5.43 OOo Basic..............................247 5.44 ...........................................................................................................249 5.44.1 .........................................253 5.44.1.1 (toolbar).......................................................253 6 Calc.............................................................................................261 6.1 ?.........................................................261 6.2 (value), (string) (formula).......................................................................................................................263 6.3 (value), (format), (string) (formula).......................................................................265 6.3.1 ........................................................................265 6.4 .......................................................................................................................265 6.5 (Selected) - ?...............................................................................267

6.5.1 ..........................................................269 6.5.2 ..............................................271 6.5.3 (Select) ..............................................................................................273 6.6 (Human readable) .........................................................275 6.7 .........................................................................277 6.7.1 ....................................................................................277 6.8 (selected range) ......................279 6.9 .............................................281 6.10 .................................281 6.11 () ..................................................................283 6.11.1 () ........................................................................................................................................285 6.11.2 () ...........................................285 6.12 ..................................................................................................................285 6.13 ..........................................................................................287 6.14 ...............................................................................................291 6.15 (Outline, Grouping)..............................................291 6.16 ......................................................................................................................293 6.17 ........................................................293 6.18 ........................................................................295 6.18.1 ......................................................295 6.19 (named range)...................................................297 6.19.1 .........................................................................................301 6.19.2 ...........................................................................................301 6.20 .................................301 6.21 / ............................................................305 6.22 ?...................................................................................305 6.23 Calc...................................................................................307 6.24 ..........................................................313 6.25 ( )?............................................................................315 6.26 Calc.....................................................317 6.26.1 Calc, ...........................................................317 6.26.2 ...................................................................................319 6.26.3 ...........................................................................319 6.26.4 .................................323 7 (Writer) ....................................................................................323 7.1 ?...............................................................................................323 7.1.1 ?................................................................323 7.1.2 (TextTable) (Cell)?...........................................................................................................................325 7.2 (Text Cursors)?.....................................................................327 7.2.1 "" (anchor) TextTable.......................................329 7.2.2 - ( ) ........................................331 7.2.3 (Bookmark anchor)....................................333 7.2.4 ..................................................................................333 7.3 (Andrew's Selected Text Framework)........................................................335 7.3.1 ?...........................................................................................................335 7.3.2 (Selection)...........................................................337

7.3.3 : - , - .........................................339 7.3.4 (Selected Text Framework Macro)..............341 7.3.4.1 (Rejected Framework).........................................................341 7.3.4.2 (Framework).........................................................................343 7.3.4.3 .....................................................................................345 7.3.5 .........................................................................................347 7.3.6 , ......................................................................................................................................................347 7.3.6.1 (White Space).....................................................................349 7.3.6.2 .....................................................349 7.3.6.3 .........................................351 7.3.6.4 "" ....................................................................................................353 7.3.7 , ...........................................................355 7.3.8 , , .........................357 7.3.8.1 ..................................................357 7.3.8.2 (Strings) ...................................357 7.3.8.3 (Character Cursor) ..............361 7.3.8.4 (Word Cursor) ............365 7.3.8.5 .......365 7.3.9 : !................................................367 7.4 (Strings).....................................373 7.4.1 , , , (String).........................................................................................................377 7.5 ..................................................................................................397 7.6 .........................................................................................................................399 7.6.1 (paragraph)..........................................................................399 7.7 ..........................................................................................................................................401 7.7.1 OOo Writer...............................401 7.7.2 ().................................................................................403 7.8 ........................................................................................................403 7.8.1 ..........................................................................................405 7.9 ............................................................................407 7.10 .............................................407 7.11 OLE-...........................................................................................................409 7.12 (Paragraph).............................................................................409 7.13 ........................................................................................411 7.14 ......................................................................................................................411 7.14.1 .................................................................................................................413 7.14.2 .........................................................................................413 7.14.3 .............................................................................................415 7.14.4 (Regular Expressions) ......................................................................................................................................................417 7.14.5 ...............................................................419 7.15 (Case) ..........................423 7.16 ( )....................................................425 7.16.1 ()..............................................427 7.16.2 ..........................................................433 7.16.3 ?...........................................................433

7.16.4 (content)....................................437 7.16.5 .........................................................441 7.16.6 , ?................................441 7.17 (Display Cursor)?..............................................................447 7.17.1 .............451 7.17.2 ........................................................................................453 7.18 (table of contents).........................................................453 7.19 URL OOo Writer.....................................................................455 7.20 ................................................................................................................457 7.21 (Outline).............................................................................................457 7.22 (table of contents =TOC) .................................461 7.23 (sections).................................................................................................463 7.23.1 , ..............465 7.24 (Footnotes) (Endnotes).............................467 8 .........................................................................................................................469 8.1 ........................................................................................................469 8.1.1 .................................................................................471 8.1.2 (Enumerating) ...........................................................473 8.2 .....................................................................................475 8.2.1 .........................................................................................477 8.2.2 ............................................................479 8.2.3 .........................................................................483 8.2.4 .................................................................485 8.3 ..........................................................487 8.4 ..................................................................................487 8.5 (Cell ranges)...............................................................................................489 8.5.1 ..................................................489 8.6 (Chart data)............................................................................................489 8.7 ....................................................................................................................491 8.8 ..........................................................................491 8.9 ?...............................................................................493 8.10 ................................................................................................493 8.10.1 ..........................................................497 8.11 ..............................................................................................499 8.12 (borders).................................................................................501 9 ..............................................................................................................503 9.1 .............................................................................................503 9.1.1 ...................................................................507 9.1.2 .................................................................................................................517 9.2 / ...............................................519 9.3 .....................................................................................................521 9.3.1 .................................................................................................525 9.3.2 .............................................................................................529 10 .............................................................................................................................................535 10.1 .................................................................................................................................535 10.2 ...................................................................................................................................537 10.2.1 ..................................................................................................539 10.2.2 / (Control Label)....................................................539

10.2.3 (Button)....................................................................................539 10.2.4 (Text Box).................................................................................................539 10.2.5 (List Box)..................................................................................................541 10.2.6 : (Combo Box)............541 10.2.7 (Check Box)............................................................................................543 10.2.8 "" (/) (Option/Radio Button)..............................543 10.2.9 (Progress Bar).......................................................................543 10.3 (Controls)....................................................................543 10.3.1 545 10.3.2 ?...................547 10.4 (File Dialog).....................................................549 10.5 ..........................................................................................551 10.6 (event listener) ...............553 10.7 ......................................................................................555 10.7.1 ..........................................................................................................555 10.7.2 ( Andrew)..............................................561 10.7.3 (Options) ........................................567 10.7.4 ........................................................................571 10.7.5 ..................................................................................................573 10.7.6 ( ms777)..........................................575 11 (Database).................................................................................................................583 12 (Investment)........................................................................................583 12.1 (Internal Rate of Return = IRR) ............................583 12.1.1 ..............................................................585 12.1.2 .......................................................................................................587 13 (Handlers) (Listeners)................................................................589 13.1 xKeyHandler ..............................................................................................................589 13.2 (Listener), Paolo Mantovani........................................595 13.2.1 CreateUnoListener ( )..................................................595 13.2.2 , ?..........................................................................595 13.2.3 , ?........................................................................597 13.2.4 1: com.sun.star.view.XSelectionChangeListener............................................599 13.2.5 2: com.sun.star.view.XPrintJobListener..........................................................601 13.2.6 3: com.sun.star.awt.XKeyHandler...................................................................605 13.2.6.1 Andrew........................................................607 13.2.6.2 (Ctrl Alt).............................................609 13.2.7 4: com.sun.star.awt.XMouseClickHandler......................................................609 13.2.8 5: ....................................................................611 13.3 ActiveSheet?.......................................................613 14 (Language)............................................................................................................................615 14.1 .........................................................................................................................615 14.2 ...........................................................................................................................617 14.2.1 ..............................................................................................................................617 14.2.2 / (Declaration)..................................................617 14.2.3 (Global) (Statics)....................619 14.2.4 ................................................................................................................................621 14.2.4.1 .........................................................................................625 14.2.4.2 (Integer)................................................................................625

14.2.4.3 (Long)................................................................627 14.2.4.4 (Currency).........................................................627 14.2.4.5 (Single)...................................627 14.2.4.6 (Double).....................627 14.2.4.7 (String)..........................................................................627 14.2.5 (Object), (Variant), (Empty), (Null) ............................................................................................................629 14.2.6 Object Variant...................................................629 14.2.7 (Constants)..................................................................................................631 14.2.8 (Arrays)...........................................................................................................631 14.2.8.1 Option Base.................................................631 14.2.8.2 Lbound([,]).....................................631 14.2.8.3 UBound([,])....................................633 14.2.8.4 .............................................................................633 14.2.9 DimArray.............................................................................633 14.2.10 ReDim..........................................................633 14.2.11 ......................................................................................................637 14.2.12 .................................................................................................637 14.3 (Functions) (SubProcedures)..........................................................639 14.3.1 .........................................................................................639 14.3.2 (By Reference) (Value)...........643 14.3.3 (Recursion) ....................................................................................................643 14.4 (Flow Control)................645 14.4.1 If Then Else.................................................................................................645 14.4.2 IIF.....................................................................................................................................647 14.4.3 Choose...........................................................................................................647 14.4.4 For....Next........................................................................................................................647 14.4.5 Do Loop...........................................................................................................................649 14.4.6 Select Case.....................................................................................................651 14.4.6.1 Case............................................................................651 14.4.6.2 , ....................................................................653 14.4.6.3 .........................................................................653 14.4.6.4 .........................................................................653 14.4.6.5 , .........................................................................653 14.4.7 While...Wend.........................................................................................................655 14.4.8 GoSub........................................................................................657 14.4.9 GoTo..............................................................................................................657 14.4.10 On ... GoTo............................................................................................659 14.4.11 Exit............................................................................................................659 14.4.12 ......................................................................................................661 14.4.12.1 , ..........................................................661 14.4.12.2 ...........................................................................663 14.4.12.3 ................................................................................665 14.5 ......................................................................................................................................667 15 Operators Precedence..............................................................669 16 ..................................................................................................................671 16.1 ................................................................................................673 16.2 ......................................................................................................675

16.3 ASCII ...............................................................................677 16.4 ..............................677 17 ...........................................................................................................................677 18 .............................................................................................................................681 19 ..........................................................................................................................683 20 , , .................................................685 20.1 (-).......................................................................................................685 20.2 (*)......................................................................................................685 20.3 (+).........................................................................................................687 20.4 (^).....................................................................................687 20.5 (/).............................................................................................................689 20.6 AND ......................................................................................................................689 20.7 Abs..........................................................................................................................691 20.8 Array ......................................................................................693 20.9 Asc..........................................................................................................................695 20.10 ATN () ..............................................................................................695 20.11 Beep.....................................................................................................................697 20.12 Blue ......................................................................................................................697 20.13 ByVal ......................................................................................................697 20.14 Call ..........................................................................................................699 20.15 CBool ...................................................................................................................701 20.16 CByte....................................................................................................................701 20.17 CDate ...................................................................................................................703 20.18 CDateFromIso .....................................................................................................703 20.19 CDateToIso ..........................................................................................................705 20.20 CDbl .....................................................................................................................705 20.21 ChDir - ..........................................................................................705 20.22 ChDrive - .....................................................................................707 20.23 Choose .................................................................................................................707 20.24 Chr .......................................................................................................................709 20.25 CInt ......................................................................................................................711 20.26 CLng ....................................................................................................................711 20.27 Close ...................................................................................................................713 20.28 Const ...............................................................................................713 20.29 ConvertFromURL ................................................................................................715 20.30 ConvertToURL ....................................................................................................715 20.31 Cos ......................................................................................................717 20.32 CreateUnoDialog .................................................................717 20.33 CreateUnoService ................................................................................................719 20.34 CreateUnoStruct .................................................................................................721 20.35 CSng ....................................................................................................................723 20.36 CStr ......................................................................................................................723 20.37 CurDir ..................................................................................................................725 20.38 Date ......................................................................................................................725 20.39 DateSerial ............................................................................................................727 20.40 DateValue ............................................................................................................727 20.41 Day........................................................................................................................729 20.42 Declare ..........................................................................................731

20.43 DefBool ...............................................................................................................731 20.44 DefDate ...............................................................................................................733 20.45 DefDbl ................................................................................................................733 20.46 DefInt ..................................................................................................................735 20.47 DefLng Statement..................................................................................................................735 20.48 DefObj ................................................................................................................737 20.49 DefVar ................................................................................................................737 20.50 Dim......................................................................................................................737 20.51 DimArray .............................................................................................................739 20.52 Dir.........................................................................................................................741 20.53 Do...Loop .........................................................................................................745 20.54 End ......................................................................................................................745 20.55 Environ ................................................................................................................747 20.56 EOF ......................................................................................................................749 20.57 EqualUnoObjects .................................................................................................749 20.58 EQV ....................................................................................................................751 20.59 Erl .........................................................................................................................753 20.60 Err ........................................................................................................................755 20.61 Error , .................................................................755 20.62 Error .....................................................................................................................755 20.63 Exit ......................................................................................................................757 20.64 Exp.......................................................................................................................759 20.65 FileAttr .................................................................................................................761 20.66 FileCopy .............................................................................................................763 20.67 FileDateTime .......................................................................................................763 20.68 FileExists .............................................................................................................765 20.69 FileLen .................................................................................................................765 20.70 FindObject ...........................................................................................................767 20.71 FindPropertyObject .............................................................................................769 20.72 Fix ......................................................................................................................771 20.73 For...Next ......................................................................................................771 20.74 Format ..................................................................................................................771 20.75 FreeFile ................................................................................................................777 20.76 FreeLibrary ..........................................................................................................777 20.77 Function ..............................................................................................................777 20.78 Get .......................................................................................................................779 20.79 GetAttr .................................................................................................................781 20.80 GetProcessServiceManager .................................................................................783 20.81 GetSolarVersion ..................................................................................................785 20.82 GetSystemTicks ...................................................................................................787 20.83 GlobalScope ............................................................................................787 20.84 GoSub .................................................................................................................787 20.85 GoTo ...................................................................................................................789 20.86 Green ....................................................................................................................791 20.87 HasUnoInterfaces ................................................................................................791 20.88 Hex .......................................................................................................................793 20.89 Hour .....................................................................................................................795 20.90 If ..........................................................................................................................795

20.91 IIF .........................................................................................................................797 20.92 Imp ......................................................................................................................797 20.93 Input ..................................................................................................................801 20.94 InputBox ..............................................................................................................801 20.95 InStr .....................................................................................................................803 20.96 Int .........................................................................................................................805 20.97 IsArray .................................................................................................................805 20.98 IsDate ...................................................................................................................807 20.99 IsEmpty ................................................................................................................807 20.100 IsMissing ...........................................................................................................809 20.101 IsNull .................................................................................................................809 20.102 IsNumeric ..........................................................................................................811 20.103 IsObject ..............................................................................................................811 20.104 IsUnoStruct ........................................................................................................813 20.105 Kill .....................................................................................................................813 20.106 LBound ..............................................................................................................815 20.107 LCase .................................................................................................................815 20.108 Left .....................................................................................................................817 20.109 Len .....................................................................................................................817 20.110 Let .........................................................................................................819 20.111 Line Input .........................................................................................................819 20.112 Loc .....................................................................................................................821 20.113 Lof ......................................................................................................................821 20.114 Log .....................................................................................................................823 20.115 Loop ..................................................................................................................823 20.116 LSet ...................................................................................................................825 20.117 LTrim .................................................................................................................827 20.118 Private ...................................................................................................827 20.119 Public ....................................................................................................829 20.120 Red .....................................................................................................................829 20.121 RSet ...................................................................................................................831 20.122 Shell ...................................................................................................................831 20.123 UBound ..............................................................................................................837 20.124 UCase..................................................................................................................839 20.125 URL...........................................................................................839 20.125.1 URL ...............................................................................................................839 20.125.2 ...................................839 20.125.3 (Home Directory) Unix....................................................................................................................................839 21 .................................................................................................................................841 21.1 C#.............................................................................................................................................841 21.2 Visual Basic ...........................................................................................843 21.2.1 ActiveWorkbook..................................................................845 21.2.2 (ActiveSheet ActiveCell)................................845 22 BuhCIA..............................................................................................847 22.1 VBA Excel Basic OOo...............................................847 22.2 , . ................................................................849 23 (Index)....................................................................................................851

1 BuhCIA http://buhcia.narod.ru BuhCIA () . "", "" .. - Andrew Pitonyak. Andrew's Macro Document, , , . , , . Basic. , , . , OpenOffice.org Macros Explained (. http://www.pitonyak.org/book/). OpenOffice, . , . , . OOo . http://www.pitonyak.org/AndrewMacro.odt :

, . - . , , , .

1.1 OpenOffice.org OOo. OOo Basic - -, OpenOffice. OOo Basic Visual Basic Visual Basic . 1. AbbreviationGUI IDE UNO IDL SDK OLE COM OOo

Definition (Graphical User Interface) (Integrated Development Environment) (Universal Network Objects) (Interface Definition Language) (Software Development Kit) (Object Linking and Embedding) (Component Object Model) OpenOffice.org

1.2 BuhCIA , OpenOffice . , , , . , , , , . OpenOffice 2.3.0 , BuhCIA http://buhcia.narod.ru

2 2.1 Help - OpenOffice.org Help OOo. OOo Writer, Calc, Base, Basic, Draw, Math, Impress. OOo , , . Basic, Help about OpenOffice.org Basic.

Figure 1: OOo help pages for Basic. OOo. , , . , . Tools () | Macros () | Organize Macros ( ) | OpenOffice.org Basic ( Basic) ( 2.0 Tools | Macros | Macro) Macro. Tools OpenOffice.org library. Debug , WritedbgInfo() printdbgInfo().

, . , , http://www.pitonyak.org/book/. , .

2.2 :

http://www.openoffice.org () http://www.oooforum.org ( , , , , ) http://api.openoffice.org/docs/common/ref/com/sun/star/module-ix.html IDL , ) (

http://api.openoffice.org/DevelopersGuide/DevelopersGuide.html ( , 1000 !) http://www.pitonyak.org/AndrewMacro.odt ( )

http://www.pitonyak.org/book/ ( , !) http://docs.sun.com/app/docs ( Sun . StarOffice) http://api.openoffice.org/basic/man/tutorial/tutorial.pdf ( ) http://docs.sun.com/ ( Sun. StarOffice StarBasic) http://api.openoffice.org (, ) http://documentation.openoffice.org How To : http://udk.openoffice.org ( UNO) http://udk.openoffice.org/common/man/tutorial/office_automation.html ( OLE) http://ooextras.sourceforge.net/ () http://disemia.com/software/openoffice/ (, Calculator) http://kienlein.com/pages/oo.html () http://www.darwinwars.com/lunatic/bugs/oo_macros.html () http://sourceforge.net/project/showfiles.php?group_id=43716 () http://www.kargs.net/openoffice.html () http://www.8daysaweek.co.uk/ ( ) http://ooo.ximian.com/lxr/ ( ) http://homepages.paradise.net.nz/hillview/OOo/ ( , , MS Office)

http://documentation.openoffice.org/HOW_TO/various_topics/How_to_use_basic_macros.sxw

Developer's Guide - cursor OpenOffice. : site:api.openoffice.org cursor. , . API : http://api.openoffice.org/docs/common/ref/com/sun/module-ix.html

2.3 2. .Linkhttp://www.pitonyak.org/AndrewMacro.odt http://fr.openoffice.org/Documentation/Guides/Indexguide.html* http://www.pitonyak.org/AndrewMacroGerman.sxw* http://buhcia.narod.ru

LanguageEnglish French German Russian

* ,

3 : , , . : http://www.pitonyak.org/book/. OpenOffice.org. , . OOo Basic. 2 OOo , Basic . OOo Basic OOo:

COM (ActiveX) GUI OpenOffice (Linux, Windows ...)

OpenOffice.org Basic StarBasic.

3.1 : Hello World OOo . - - - OpenOffice.org , Macro. , . , , untitled1 1. ( ) untitled1 standard. (New) . Module1, , . Module1, . MyFirstModule. OOo Basic IDE . ( ) , 3.1. 3.1: , Hello world.Sub Main Print "Hello World" End Sub

(" Basic") OOo Basic.

3.2 OOo Basic , Sub Function (procedures, routines, subroutines) . . Sub Function , , . 3.2 HellowWorldString. 3.2: Hello world .Sub HelloWorld Dim s As String s = HelloWorldString() MsgBox s End Sub Function HelloWorldString() As String HelloWorldString = "Hello World" End Function

(module) (). (Library) . (document) . (application level), OOo Writer.

3.3 IDE , . , . , , .

3.4 , , , - . , . , . , - Exception. . : 3.3: .Dim as Dim i as integer

, . , . , . , , . , , . , , . Global ( - ), Public ( - ), and Private ( - ) . , , . , , (Constant). Const. 3.4: .Const = const pi=3.14159265358

OOo Basic . , . , , . . 615 () OOo. OpenOffice.org Macros Explained.

3.5 (Objects) OpenOfficeOpenOffice.org (Services, Objects); . ThisComponent StarDesktop . , (. 5). 3.5: .Sub Example Dim oDoc As Variant ' Dim oText As Variant ' Text oDoc = ThisComponent ' oText = oDoc.getText() ' - TextDocument End Sub

, createUnoService() 6. , demonstrates how to create a structure. 3.6: dispatch.Sub PerformDispatch(vObj, uno$) Dim vParser ' URLTransformer. Dim vDisp ' . Dim oUrl As New com.sun.star.util.URL ' oUrl.Complete = uno$

vParser = createUnoService("com.sun.star.util.URLTransformer") vParser.parseStrict(oUrl) vDisp = vObj.queryDispatch(oUrl,"",0) If (Not IsNull(vDisp)) Then vDisp.dispatch(oUrl,noargs()) End Sub

Developer's Guide , Variant object. y .629. Desktop, , StarDesktop . Desktop , StarBasic.

createUnoService("com.sun.star.frame.Desktop")

3.6 UNO?UNO (Universal Network Object, ) , () environment () . ? () . , , .

UNO , , .. ( ). UNO ( ). UNO . UNO . (). UNO ( ) Interface Definition Language (UNO IDL). UNO IDL, , . , UNO Basic, Java. , UNO , , UNOIDL. . OOo. API

OOo API :

UNO , .. - , , . , , com.sun.star.awt.FontWeight.NORMAL, 100.0.

, com.sun.star.awt.FontSlant.ITALIC, , . - , . , , , . . UNO () .

3.6.1 , OpenOffice.org, IsUNOStruct(). 3.7: UNO.Sub ExamineStructures Dim oProperty As New com.sun.star.beans.PropertyValue With oProperty .name = "Joe" .value = 17 End With Print oProperty.Name & " is " & oProperty.Value If IsUNOStruct(oProperty) Then Print "oProperty is an UNO Structure" End If End Sub

, IsUNOStruct() .

3.6.2 OOo (, services) (interface). "", - , , . , com.sun.star.frame.XStorable XStorable, , 3. 3. , XStorable.hasLocation

true , , , , . URL , . ( ) true, store(). URL , . URL. store URL. URL,

getLocation isReadonly store storeAsURL storeToURL

URL .

57 , XStorable. , hasLocation() getLocation(). , , , XStorable , .

3.6.3 (Services) "" , , , . http://api.openoffice.org. , . , TextRange CharacterProperties, , CharFontName. , TextRange CharFontName, ; , , , .

3.6.4 (services) , , , . BASIC IDE . , , Xray. , OpenOffice.org Macros Explained. XserviceInfo, , (. http://api.openoffice.org/docs/common/ref/com/sun/star/lang/XServiceInfo.html). , . 3.8: , t.Dim s As String s = "com.sun.star.text.TextDocument" If ThisComponent.supportsService(s) Then Print " " Else Print " " End If

3.6.5 ? , , . :

4: , .MethodIsArray IsEmpty IsNull IsObject IsUnoStruct TypeName

Description ? variant? ? OLE? UNO? ?

. 5: , TypeName()Variant Object regular type array

TypeName()Empty Object, . , String () , ()

9 4, 3.9: .Sub TypeTest Dim oSFA Dim aProperty As New com.sun.star.beans.Property oSFA = CreateUnoService( "com.sun.star.ucb.SimpleFileAccess" ) Dim v, o As Object, s As String, ss$, a(4) As String ss = "Empty Variant: " & GetSomeObjInfo(v) & chr(10) &_ "Empty Object: " & GetSomeObjInfo(o) & chr(10) &_ "Empty String: " & GetSomeObjInfo(s) & chr(10) v=4 ss = ss & "int Variant: " & GetSomeObjInfo(v) & chr(10) v=o ss = ss & "null obj Variant: " & GetSomeObjInfo(v) & chr(10) &_ "struct: " & GetSomeObjInfo(aProperty) & chr(10) &_ "service: " & GetSomeObjInfo(oSFA) & chr(10) &_ "array: " & GetSomeObjInfo(a()) MsgBox ss, 64, "Type Info" End Sub REM REM . Function GetSomeObjInfo(vObj) As String Dim s As String s = "TypeName = " & TypeName(vObj) & CHR$(10) &_ "VarType = " & VarType(vObj) & CHR$(10) If IsNull(vObj) Then

s = s & "IsNull = True" ElseIf IsEmpty(vObj) Then s = s & "IsEmpty = True" Else If IsObject(vObj) Then On Local Error GoTo DebugNoSet s = s & "Implementation = " & _ NotSafeGetImplementationName(vObj) & CHR$(10) DebugNoSet: On Local Error Goto 0 s = s & "IsObject = True" & CHR$(10) End If If IsUnoStruct(vObj) Then s = s & "IsUnoStruct = True" & CHR$(10) If IsDate(vObj) Then s = s & "IsDate = True" & CHR$(10) If IsNumeric(vObj) Then s = s & "IsNumeric = True" & CHR$(10) If IsArray(vObj) Then On Local Error Goto DebugBoundsError: Dim i%, sTemp$ s = s & "IsArray = True" & CHR$(10) & "range = (" Do While (i% >= 0) i% = i% + 1 sTemp$ = LBound(vObj, i%) & " To " & UBound(vObj, i%) If i% > 1 Then s = s & ", " s = s & sTemp$ Loop DebugBoundsError: On Local Error Goto 0 s = s & ")" & CHR$(10) End If End If GetSomeObjInfo = s End Function REM , REM -! Function SafeGetImplementationName(vObj) As String On Local Error GoTo ThisErrorHere: SafeGetImplementationName = NotSafeGetImplementationName(vObj) Exit Function ThisErrorHere: On Local Error GoTo 0 SafeGetImplementationName = "*** Unknown ***" End Function REM , , vObj REM getImplementationName(), REM "Object variable not set" REM . Function NotSafeGetImplementationName(vObj) As String NotSafeGetImplementationName = vObj.getImplementationName() End Function

3.6.6 , , ? , Object. , - - API IDL. UNO, , ServiceInfo, . getImplementationName() ( ) . . getSupportedServiceNames() , . , , - : 3.10: ?MsgBox vObj.dbg_methods ' MsgBox vObj.dbg_supportedInterfaces ', MsgBox vObj.dbg_properties '

OOo . PrintdbgInfo() ShowArray(). WritedbgInfo() OOo Writer.

3.6.7 , BasicStarBasic , . .

3.6.7.1 CreateUnoService CreateUnoService() - (global service manager) createInstance() . 3.11: .oManager = GetProcessServiceManager() oDesk = oManager.createInstance("com.sun.star.frame.Desktop")

StarBasic - createInstanceWithArguments(). 3.12: CreateUnoService , .oDesk = CreateUnoService("com.sun.star.frame.Desktop")

, Visual Basic, CreateUnoService(). 3.13: UNO Visual Basic.Rem Visual Basic CreateUnoService(). Rem REM Visual Basic. Rem OOo ,

Set oManager = CreateObject("com.sun.star.ServiceManager") Rem desktop Set oDesk = oManager.createInstance("com.sun.star.frame.Desktop")

3.6.7.2 ThisComponent StarBasic, ThisComponent , . ThisComponent , , , - ThisComponent. ThisComponent . , Basic, getCurrentComponent() (desktop). , , Basic IDE , , . StarDesktop.getCurrentComponent() , ThisComponent, , Basic IDE.

3.6.7.3 StarDesktop OOo Basic . StarDesktop (desktop object), , , OOo. , StarOffice, , . , , , BASIC Integrated Development Environment (IDE), (. 2).

2: StarDesctop . 13, StarDesktop . getCurrentComponent() , . BASIC IDE, BASIC IDE. , , - , oComp .

TIP

ThisComponent , . , , ThisComponent . OOo 2.01 Basic IDE, , (Base documents) ThisComponent .

3.6.8 StarBasic , , , . . , , , (extracted) (. 14). 3.14: Java , .XDesktop xDesk; xDesk = (XDesktop) UnoRuntime.queryInterface(XDesktop.class, desktop); XFrame xFrame = (XFrame) xDesk.getCurrentFrame();XDispatchProvider oProvider = (XDispatchProvider) UnoRuntime.queryInterface(XDispatchProvider.class, xFrame);

, TextSection . TextSection null. StarBasic : 3.15: OOo Basic .If IsNull(oDoc.CurrentController.getViewCursor().TextSection) Then

( StarBasic) CurrentController TextSection . get, . 3.16: get.oVCurs = oDoc.getCurrentController().getViewCursor() If IsNull(oVCurs.getPropertyValue("TextSection")) Then

, get set, . StarBasic , . Sheets Calc ( ). Calc , StarBasic. 3.17: OOo Basic .oDoc.sheets(1) oDoc.getSheets().getByIndex(1)

3.7 OpenOffice.org (OOo) , . , OOo API. , OOo. 3.18: , OOo API.Sub SimpleExample() Dim i As Integer i=4 Print "The value of i = " & i End Sub

OOo OOo API. API . 3.19: , OOo API .Sub ExamineCurrentComponent Dim oComp oComp = StarDesktop.getCurrentComponent() If HasUnoInterfaces(oComp, "com.sun.star.frame.XStorable") Then If oComp.hasLocation() Then Print " OOo URL: " & oComp.getLocation() Else Print " " End If Else Print " " End If End Sub

3.19 , , . oComp, Variant, .

4 4.1 , . , .

4.1.1 OOo . , . . , getImplementationName().

4.1: OpenOffice.org'Author: Included with OpenOffice 'Modified by Andrew Pitonyak Function GetDocumentType(oDoc) Dim sImpress$ Dim sCalc$ Dim sDraw$ Dim sBase$ Dim sMath$ Dim sWrite$ sCalc = "com.sun.star.sheet.SpreadsheetDocument" sImpress = "com.sun.star.presentation.PresentationDocument" sDraw = "com.sun.star.drawing.DrawingDocument" sBase = "com.sun.star.sdb.DatabaseDocument" sMath = "com.sun.star.formula.FormulaProperties" sWrite = "com.sun.star.text.TextDocument" On Local Error GoTo NODOCUMENTTYPE If oDoc.SupportsService(sCalc) Then GetDocumentType() = "sCalc" ElseIf oDoc.SupportsService(sWrite) Then GetDocumentType() = "sWriter" ElseIf oDoc.SupportsService(sDraw) Then GetDocumentType() = "sDraw" ElseIf oDoc.SupportsService(sMath) Then GetDocumentType() = "sMath" ElseIf oDoc.SupportsService(sImpress) Then GetDocumentType() = "sImpress" ElseIf oDoc.SupportsService(sBase) Then GetDocumentType() = "sBase" End If NODOCUMENTTYPE: If Err 0 Then GetDocumentType = "" Resume GOON GOON: End If End Function

4.2 PDF, . 4.2: PDFFunction GetPDFFilter(oDoc) REM Author: Alain Viret [[email protected]] REM Modified by Andrew Pitonyak On Local Error GoTo NODOCUMENTTYPE Dim sImpress$ Dim sCalc$ Dim sDraw$ Dim sBase$ Dim sMath$

Dim sWrite$ sCalc = "com.sun.star.sheet.SpreadsheetDocument" sImpress = "com.sun.star.presentation.PresentationDocument" sDraw = "com.sun.star.drawing.DrawingDocument" sBase = "com.sun.star.sdb.DatabaseDocument" sMath = "com.sun.star.formula.FormulaProperties" sWrite = "com.sun.star.text.TextDocument" On Local Error GoTo NODOCUMENTTYPE If oDoc.SupportsService(sCalc) Then GetPDFFilter() = "calc_pdf_Export" ElseIf oDoc.SupportsService(sWrite) Then GetPDFFilter() = "writer_pdf_Export" ElseIf oDoc.SupportsService(sDraw) Then GetPDFFilter() = "draw_pdf_Export" ElseIf oDoc.SupportsService(sMath) Then GetPDFFilter() = "math_pdf_Export" ElseIf oDoc.SupportsService(sImpress) Then GetPDFFilter() = "impress_pdf_Export" End If NODOCUMENTTYPE: If Err 0 Then GetPDFFilter() = "" Resume GOON GOON: End If End Function

4.1.2 , , , . , . . , ( 16 ), . 4.3: , .' , ' - ; - : m - , s - , p - 'Author: Tony Bloomfield [[email protected]] 'Modified: [email protected] support services and verify obj. 'Modified: A Pitonyak to fix declaration errors Sub DisplayMethods(oObj As Object, sWhat As String) Dim sMethodLIst As String, sMsgBox As String Dim fs As Integer, ep As Integer Dim i As Integer Dim EOL As Boolean If IsNull(oObj) Then Print " !" Else If sWhat = "m" Then sMethodList = oObj.DBG_Methods

ElseIf sWhat = "s" Then sMethodList = oObj.DBG_SupportedInterfaces ElseIf sWhat = "p" Then sMethodLIst = oObj.DBG_Properties End If fs = 1 EOL = FALSE While fs , . , , .

5.6.3 5.9: ( ).Sub PrintLandscape() Dim oOpt(1) as new com.sun.star.beans.PropertyValue oOpt(0).Name = "Name" oOpt(0).Value = "" oOpt(1).Name = "PaperOrientation" oOpt(1).Value = com.sun.star.view.PaperOrientation.LANDSCAPE ThisComponent.Printer = oOpt() End Sub

5.7 5.7.1 OOo , GetSolarVersion , OOo. OOo 1.0.3.1 641, 1.1RC3 645, 2.01 RC2 680, - . OOo. ( OOo 2.3.0 "2.3" - BuhCIA) 5.10: OpenOffice.orgFunction OOoVersion() As String ' OOo 'Author : Laurent Godard 'e-mail : [email protected] ' Dim oSet, oConfigProvider Dim oParm(0) As New com.sun.star.beans.PropertyValue Dim sProvider$, sAccess$ sProvider = "com.sun.star.configuration.ConfigurationProvider" sAccess = "com.sun.star.configuration.ConfigurationAccess" oConfigProvider = createUnoService(sProvider) oParm(0).Name = "nodepath" oParm(0).Value = "/org.openoffice.Setup/Product" oSet = oConfigProvider.createInstanceWithArguments(sAccess, oParm()) OOOVersion=oSet.getByName("ooSetupVersion") End Function

5.7.2 () OOo 5.11: OpenOffice.orgFunction OOoLang() as string 'Author : Laurent Godard 'e-mail : [email protected] Dim oSet, oConfigProvider Dim oParm(0) As New com.sun.star.beans.PropertyValue Dim sProvider$, sAccess$ sProvider = "com.sun.star.configuration.ConfigurationProvider" sAccess = "com.sun.star.configuration.ConfigurationAccess" oConfigProvider = createUnoService(sProvider) oParm(0).Name = "nodepath" oParm(0).Value = "/org.openoffice.Setup/L10N" oSet = oConfigProvider.createInstanceWithArguments(sAccess, oParm()) Dim OOLangue as string OOLangue= oSet.getbyname("ooLocale") ' ru EN-en OOLang=lcase(Left(trim(OOLangue),2)) ' ru End Function

5.8 ( ) 5.8.1 OpenOffice / - () OpenOffice.org Xcloseable. , close(bForce As Boolean). , bForce false, , . " " , - () , . , , . , OOo, , . . Xclosable, , , close(True). Xcloseable (legacy). terminate(). queryTermination, . TerminationVetoException , notifyTermination true. abortTermination false. Mathias Bauer, terminate() , , . , XCloseable .[Bauer001] 5.12: OpenOffice.orgIf oDoc.supportsService("com.sun.star.frame.XModel") If HasUnoInterfaces(oDoc, "com.sun.star.util.XCloseable") Then oDoc.close(true) Else oDoc.dispose() End If End If

Christian Junker : soffice. StarDesktop.terminate() !). oDoc.close(true), . oDoc.dispose()! disposed , - . ThisComponent , (Document's Model) . OOo 2.0 Framework, .

5.8.1.1 , () ? , close. , OpenOffice.org. , , . , . 5.13: ( ) , oDoc = ThisComponent If (oDoc.isModified) Then If (oDoc.hasLocation AND (Not oDoc.isReadOnly)) Then oDoc.store() Else oDoc.setModified(False) End If End If oDoc.close(True)

5.8.2 URL URL, LoadComponentFromURL() (desktop). , . :loadComponentFromURL( string aURL, string aTargetFrameName, long nSearchFlags, sequence< com::sun::star::beans::PropertyValue > aArgs)

: com::sun::star::lang::XComponent : aURL: URL , . , "private:factory/scalc", "private:factory/swriter", .. aTargetFrameName: , . , , . "_blank" , "_self" , "_parent" , "_top" (current path in the tree). nSearchFlags: FrameSearchFlag , aTargetFrameName. , 0. . http://api.openoffice.org/docs/common/ref/com/sun/star/frame/FrameSearchFlag.html 6: .0 1

Auto PARENT

SELF+CHILDREN

2 4 8 16 32 23

SELF CHILDREN CREATE SIBLINGS TASKS ALL GLOBAL

() , ( ) , . 23 = 1+2+4+16 = PARENT + SELF + CHILDREN + SIBLINGS. . 55 = 1+2+4+16+32 = PARENT + SELF + CHILDREN + SIBLINGS + TASKS. GLOBAL + CREATE

55 63

aArgs: . "ReadOnly" , . "FilterName" , , , , : "scalc: Text csv". . http://api.openoffice.org/docs/common/ref/com/sun/star/document/MediaDescriptor.html 5.14: given URL.REM "MyName" , REM "CREATE" ( 63) oDoc1 = StarDesktop.LoadComponentFromUrl(sUrl1, "MyName", 63, Array()) REM "MyName" oDoc2 = StarDesktop.LoadComponentFromUrl(sUrl2, "MyName", 55, Array())

Tip

OOo 1.1 loadComponentFromURL, :

oDoc = oDesk.LoadComponentFromUrl(sUrl_1, "_blank", 0, Noargs()) oFrame = oDoc.CurrentController.Frame oDoc = oFrame.LoadComponentFromUrl(sUrl_2, "", 2, Noargs()) . OOo 1.1 , .

Warning

5.15: .Sub insertDocumentAtCursor(sFileUrl$, oDoc) Dim oCur ' Dim oVC : oDoc.getCurrentController().getViewCursor() Dim oText : oText = oVC.getText() oCur=oText.createTextCursorByRange(oVC.getStart()) oCur.insertDocumentFromURL(sFileURL, Array()) End Sub

, OOo 2. . (NULL).

5.16: .'------------- OOo Writer -------------------Dim s$ : s = "private:factory/swriter" oDoc=StarDesktop.loadComponentFromURL(s,"_blank",0,Array()) '------------- --------------oDoc=StarDesktop.loadComponentFromURL(sUrl,"_blank",0,Array())

5.8.2.1 - one, two three. . 5.17: .Sub open_new_doc Dim mArgs(2) as New com.sun.star.beans.PropertyValue Dim oDoc Dim oFrame Dim s As String If (ThisComponent.isModified) Then If (ThisComponent.hasLocation AND (Not ThisComponent.isReadOnly)) Then ThisComponent.store() Else ThisComponent.setModified(False) End If End If mArgs(0).Name = "ReadOnly" mArgs(0).Value = True mArgs(1).Name = "MacroExecutionMode" mArgs(1).Value = 4 mArgs(2).Name = "AsTemplate" mArgs(2).Value = FALSE REM If ThisComponent.hasLocation Then s = ThisComponent.getURL() If InStr(s, "one") 0 Then s = "file:///C:/tmp/two.oxt" ElseIf InStr(s, "two") 0 Then s = "file:///C:/tmp/three.oxt" Else s = "file:///C:/tmp/one.oxt" End If Else s = "file:///C:/tmp/one.oxt" End If

REM REM ! oFrame = ThisComponent.getCurrentController().getFrame() oDoc = oFrame.LoadComponentFromUrl(s, "", 2, mArgs()) If IsNull(oDoc) OR IsEmpty(oDoc) Then Print "Unable to load " & s End If End Sub

5.8.3 , Password. 5.18: .Sub SaveDocumentWithPassword Dim args(0) As New com.sun.star.beans.PropertyValue Dim sURL$ args(0).Name ="Password" args(0).Value = "test" sURL=ConvertToURL("/andrew0/home/andy/test.odt") ThisComponent.storeToURL(sURL, args()) End Sub

!!! , password !!!

5.8.4 , : 5.19: .Sub NewDoc Dim oDoc Dim sPath$ Dim a(0) As New com.sun.star.beans.PropertyValue a(0).Name = "AsTemplate" a(0).Value = true sPath$ = "file://~/Documents/DocTemplate.stw" oDoc = StarDesktop.LoadComponentFromUrl(sPath$, "_blank" , 0, a()) End Sub

(to edit the template as a template), AsTemplate False.

Warning

, , . OOo. , OOo 2.0 .

5.8.5 LoadComponentFromURL , . . OOo 1.1, , . MacroExecutionMode 2 4 . Mikhail Voitenko : http://www.openoffice.org/servlets/ReadMsg?msgId=782516&listName=dev : MacroExecutionMode MediaDescriptor com.sun.star.document.MacroExecMode. , . : NEVER_EXECUTE ( ), FROM_LIST ( ), ALWAYS_EXECUTE ( ), USE_CONFIG ( ), ALWAYS_EXECUTE_NO_WARN ( ), USE_CONFIG_REJECT_CONFIRMATION ( , ) USE_CONFIG_APPROVE_CONFIRMATION ( , ). , . "AsTemplate", , . , (create document), (open document). , . 5.20: .Dim oProp(1) As New com.sun.star.beans.PropertyValue oProp(0).Name="AsTemplate" oProp(0).Value=True oProp(1).Name="MacroExecutionMode" oProp(1).Value=4

, "OnNew" ( ), (template) sxw ( ). "OnLoad" ( ), "AsTemplate" False ( sxw, False, stw True). OOo 2.0 .

5.8.6 , . C++, , , , .

Mathias Bauer , XcomponentLoader , Interaction Handler. loadComponentFromURL, InteractionHandler ( ). GUI UI , , ( Developer's Guede). , . , loadComponentFromURL. Basic , .

5.8.7 Mail Merge mail merge . OpenOffice Writer , , . , , , OpenOffice Write. 5.21: .'author: Laurent Godard 'Modified by: Andrew Pitonyak Sub MergeDocumentsInDirectory() ' On Error Resume Next Dim DestDirectory As String Dim FileName As String Dim SrcFile As String, DstFile As String Dim oDesktop, oDoc, oCursor, oText Dim argsInsert() Dim args() ' , "" 'Dim args(0) As New com.sun.star.beans.PropertyValue 'args(0).name="Hidden" 'args(0).value=true ' () ? DestDirectory=Trim(GetFolderName()) If DestDirectory = "" Then MsgBox " , ",16," " Exit Sub End If REM REM \ , URL

If Right(DestDirectory,1) "/" Then DestDirectory=DestDirectory & "/" End If oDeskTop=CreateUnoService("com.sun.star.frame.Desktop") REM ! FileName=Dir(DestDirectory) DstFile = ConvertToURL(DestDirectory & "ResultatFusion.sxw") Do While FileName "" If lcase(right(FileName,3))="sxw" Then SrcFile = ConvertToURL(DestDirectory & FileName) If IsNull(oDoc) OR IsEmpty(oDoc) Then FileCopy( SrcFile, DstFile ) oDoc=oDeskTop.Loadcomponentfromurl(DstFile, _ "_blank", 0, Args()) oText = oDoc.getText oCursor = oText.createTextCursor() Else oCursor.gotoEnd(false) oCursor.BreakType = com.sun.star.style.BreakType.PAGE_BEFORE oCursor.insertDocumentFromUrl(SrcFile, argsInsert()) End If End If FileName=dir() Loop If IsNull(oDoc) OR IsEmpty(oDoc) Then MsgBox " !",16," " Exit Sub End If ' Dim args2() oDoc.StoreAsURL(DestDirectory & "ResultatFusion.sxw",args2()) If HasUnoInterfaces(oDoc, "com.sun.star.util.XCloseable") Then oDoc.close(true) Else oDoc.dispose() End If ' ! oDoc=oDeskTop.Loadcomponentfromurl(DstFile,"_blank",0,Args2()) End Sub

5.9 / , , createInstance(object) . . . , . , . 5.22: GraphicsObject ( ) .Sub InsertGraphicObject(oDoc, sURL$) REM Author: Andrew Pitonyak Dim oCursor Dim oGraph Dim oText oText = oDoc.getText() oCursor = oText.createTextCursor() oCursor.goToStart(FALSE) oGraph = oDoc.createInstance("com.sun.star.text.GraphicObject") With oGraph .GraphicURL = sURL .AnchorType = com.sun.star.text.TextContentAnchorType.AS_CHARACTER .Width = 6000 .Height = 8000 End With ' oText.insertTextContent( oCursor, oGraph, False ) End Sub

(graphics object shape), (draw page), . , . 5.23: GraphicsObjectShape (draw page).Sub InsertGraphicObjectShape(oDoc, sURL$) REM Author: Andrew Pitonyak Dim oSize As New com.sun.star.awt.Size Dim oPos As New com.sun.star.awt.Point Dim oGraph REM (graphic object shape) oGraph = oDoc.createInstance("com.sun.star.drawing.GraphicObjectShape") REM oSize.width=6000 oSize.height=8000 oGraph.setSize(oSize) oPos.X = 2540

oPos.Y = 2540 oGraph.setposition(oPos) REM , , (draw page) oDoc.getDrawpage().add(oGraph) REM URL oGraph.GraphicURL = sURL End Sub

Tip

, . GraphicURL . , URL (stars with the text) vnd.sun.star.GraphiObject: , API, . Danny Brewer, , , , .

5.9.1 . , . , , , . , OpenOffice Writer, ( ) (). , " " . 5.24: GraphicsObjectShape .Sub EmbedLinkedGraphic(oGraph) REM Author: Andrew Pitonyak Dim sGraphURL As String Dim oGraph_2 Dim oCurs Dim oText Dim oAnchor Dim s$ If InStr(oGraph.GraphicURL, "vnd.sun") 0 Then REM , Exit Sub End If s = "com.sun.star.drawing.GraphicObjectShape" If oGraph.supportsService(s) Then REM , GraphicObjectShape. REM , TextGraphicObject, REM , , ImageMap.

oAnchor = oGraph.getAnchor() oText = oAnchor.getText() oGraph_2 = ThisComponent.createInstance(s) oGraph_2.GraphicObjectFillBitmap = oGraph.GraphicObjectFillBitmap oGraph_2.Size = oGraph.Size oGraph_2.Position = oGraph.Position oText.insertTextContent(oAnchor, oGraph_2, False) oText.removeTextContent(oGraph) End If End Sub

5.9.2 Danny Brewer Danny Brewer , URL . com.sun.star.drawing.BitmapTable . 5.25: (internal bitmap table).REM URL , REM (drawing document), REM URL . REM URL URL. Function LoadGraphicIntoDocument( oDoc As Object, cUrl$, cInternalName$ ) As String Dim oBitmaps Dim cNewUrl As String ' (BitmapTable) ' (drawing document) , ' , . oBitmaps = oDoc.createInstance( "com.sun.star.drawing.BitmapTable" ) ' ' (BitmapTable) oBitmaps.insertByName( cInternalName, cUrl ) ' Now ask for it back. ' Url, ' , cNewUrl = oBitmaps.getByName( cInternalName ) LoadGraphicIntoDocument = cNewUrl End Function

. 5.26 5.27 , .

. , , . , oBitmaps.getByName(DBGif) URL vnd.sun.star.GraphicObject:. 5.26: .Dim sURL$ Dim oBitmaps Dim s$ REM sURL = "file:///andrew0/home/andy/db.gif" InsertGraphicObject(ThisComponent, sURL) REM S = "com.sun.star.drawing.BitmapTable" oBitmaps = ThisComponent.createInstance( s ) LoadGraphicIntoDocument(ThisComponent, sURL, "DBGif") InsertGraphicObject(ThisComponent, oBitMaps.getByName("DBGif"))

5.9.3 , (dispatcher ) . 5.27: .Dim oFrame Dim oDisp Dim oProp(1) as new com.sun.star.beans.PropertyValue oFrame = ThisComponent.CurrentController.Frame oDisp = createUnoService("com.sun.star.frame.DispatchHelper") oProp(0).Name = "FileName" oProp(0).Value = "file:////" oProp(1).Name = "AsLink" oProp(1).Value = False oDisp.executeDispatch(oFrame, ".uno:InsertGraphic", "", 0, oProp())

5.9.4 OOo 2.0 . , , . 5.28: .Sub EmbedGraphic(oDoc, sURL$) REM Author: Stephan Wunderlich Dim oShape

Dim Dim Dim Dim

oGraph oProvider oText s$

' ' GraphicProvider

s = "com.sun.star.drawing.GraphicObjectShape" oShape = oDoc.createInstance(s) oGraph = oDoc.createInstance("com.sun.star.text.GraphicObject") oDoc.getDrawPage().add(oShape) oProvider = createUnoService("com.sun.star.graphic.GraphicProvider") Dim oProps(0) as new com.sun.star.beans.PropertyValue oProps(0).Name = "URL" oProps(0).Value = sURL oShape.Graphic = oProvider.queryGraphic(oProps()) oGraph.graphicurl = oShape.graphicurl oText= oDoc.getText() ' Dim oVC : oVC = oDoc.getCurrentController().getViewCursor() oText.insertTextContent(oVC, oGraph, false) ' (shape object) oDoc.getDrawPage().remove(oShape) End Sub

5.10 OOo Writer. Draw Impress BorderLeft (draw page). 5.29: (, ).Sub Margins( ) Dim oStyleFamilies, oFamilies, oPageStyles, oStyle Dim oVCurs, oPageStyleName Dim fromleft%, fromtop%, fromright%, frombottom% Dim oDoc oDoc = ThisComponent REM (view cursor), REM (TextCursor) oVCurs = oDoc.CurrentController.getViewCursor() oPageStyleName = oVCurs.PageStyleName oPageStyles = oDoc.StyleFamilies.getByName("PageStyles") oStyle = oPageStyles.getByName(oPageStyleName) REM fromleft, fromtop, fromright, frombottom = ,

oStyle.LeftMargin = fromleft oStyle.TopMargin = fromtop oStyle.RightMargin = fromright oStyle.BottomMargin = frombottom End Sub

, , ParaFirstLineIndent ParaLeftMargin .

5.10.1 . 5.30: Width Height.Sub SetThePageStyle() Dim oStyle Dim sPageStyleName$ Dim oDoc Dim s$ Dim oVC oDoc = ThisComponent REM , oVC = oDoc.getCurrentController().getViewCursor() sPageStyleName = oVC.PageStyleName DIM oPageStyles oPageStyles = oDoc.StyleFamilies.getByName("PageStyles") oStyle = oPageStyles.getByName(sPageStyleName) REM , Letter, A4 If oStyle.Width = 27940 Then Print " A4" oStyle.Width = 21000 oStyle.Height = 29700 Else Print " Letter" oStyle.Width = 21590 oStyle.Height = 27940 End If REM , Width Height , REM Size . , ... REM width height ... s="Width = " & CStr(oStyle.Width / 2540) & " inches" & CHR$(10) s=s&"Height = "&CStr(oStyle.Height / 2540)&" inches" & CHR$(10) s=s&"Width = "&CStr(oStyle.Size.Width / 2540) & " inches"&CHR$(10) s=s&"Height = "&CStr(oStyle.Size.Height / 2540)&" inches" & CHR$(10) MsgBox s, 0, "Page Style " & sPageStyleName End Sub

5.11 (Internet Explorer) OLE Shell OleObjectFactory ( Windows). 5.31: OleObjectFactory .Sub using_IE( ) Dim oleService Dim IE Dim s$ s = "com.sun.star.bridge.OleObjectFactory" oleService = createUnoService(s) IE = oleService.createInstance("InternetExplorer.Application.1") IE.Visible = 1 IE.Navigate("http://www.openoffice.org") End Sub

5.12 Shell , URL! , %20 , . 5.32: URL shell.Sub ExampleShell Shell("file:///C|/Andy/My%20Documents/oo/tmp/h.bat",2) Shell("C:\Andy\My%20Documents\oo\tmp\h.bat",2) End Sub

ConvertToUrl ConvertFromUrl URL . Shell , . , bSync, , shell , (bSync = True) (bSync = False). False. Shell bSync True, Shell , .

5.13 , . . . 5.33: