-
Notifications
You must be signed in to change notification settings - Fork 1
/
LibreOfficeWriter_Doc.au3
4268 lines (3737 loc) · 274 KB
/
LibreOfficeWriter_Doc.au3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7
;~ #Tidy_Parameters=/sf
#include-once
; Main LibreOffice Includes
#include "LibreOffice_Constants.au3"
; Common includes for Writer
#include "LibreOfficeWriter_Constants.au3"
#include "LibreOfficeWriter_Helper.au3"
#include "LibreOfficeWriter_Internal.au3"
; Other includes for Writer
#include "LibreOfficeWriter_Par.au3"
; #INDEX# =======================================================================================================================
; Title .........: LibreOffice UDF
; AutoIt Version : v3.3.16.1
; Description ...: Provides basic functionality through AutoIt for Creating, Modifying, Closing, Saving, Searching, etc. L.O. Writer documents.
; Author(s) .....: donnyh13, mLipok
; Dll ...........:
;
; ===============================================================================================================================
; #CURRENT# =====================================================================================================================
; _LOWriter_DocBookmarkDelete
; _LOWriter_DocBookmarkExists
; _LOWriter_DocBookmarkGetAnchor
; _LOWriter_DocBookmarkGetObj
; _LOWriter_DocBookmarkInsert
; _LOWriter_DocBookmarkModify
; _LOWriter_DocBookmarksGetNames
; _LOWriter_DocClose
; _LOWriter_DocConnect
; _LOWriter_DocConvertTableToText
; _LOWriter_DocConvertTextToTable
; _LOWriter_DocCreate
; _LOWriter_DocCreateTextCursor
; _LOWriter_DocDescription
; _LOWriter_DocExecuteDispatch
; _LOWriter_DocExport
; _LOWriter_DocFindAll
; _LOWriter_DocFindAllInRange
; _LOWriter_DocFindNext
; _LOWriter_DocFooterGetTextCursor
; _LOWriter_DocGenProp
; _LOWriter_DocGenPropCreation
; _LOWriter_DocGenPropModification
; _LOWriter_DocGenPropPrint
; _LOWriter_DocGenPropTemplate
; _LOWriter_DocGetCounts
; _LOWriter_DocGetName
; _LOWriter_DocGetPath
; _LOWriter_DocGetString
; _LOWriter_DocGetViewCursor
; _LOWriter_DocHasPath
; _LOWriter_DocHeaderGetTextCursor
; _LOWriter_DocHyperlinkInsert
; _LOWriter_DocInsertControlChar
; _LOWriter_DocInsertString
; _LOWriter_DocIsActive
; _LOWriter_DocIsModified
; _LOWriter_DocIsReadOnly
; _LOWriter_DocMaximize
; _LOWriter_DocMinimize
; _LOWriter_DocOpen
; _LOWriter_DocPosAndSize
; _LOWriter_DocPrint
; _LOWriter_DocPrintersAltGetNames
; _LOWriter_DocPrintersGetNames
; _LOWriter_DocPrintIncludedSettings
; _LOWriter_DocPrintMiscSettings
; _LOWriter_DocPrintPageSettings
; _LOWriter_DocPrintSizeSettings
; _LOWriter_DocRedo
; _LOWriter_DocRedoClear
; _LOWriter_DocRedoCurActionTitle
; _LOWriter_DocRedoGetAllActionTitles
; _LOWriter_DocRedoIsPossible
; _LOWriter_DocReplaceAll
; _LOWriter_DocReplaceAllInRange
; _LOWriter_DocSave
; _LOWriter_DocSaveAs
; _LOWriter_DocToFront
; _LOWriter_DocUndo
; _LOWriter_DocUndoActionBegin
; _LOWriter_DocUndoActionEnd
; _LOWriter_DocUndoClear
; _LOWriter_DocUndoCurActionTitle
; _LOWriter_DocUndoGetAllActionTitles
; _LOWriter_DocUndoIsPossible
; _LOWriter_DocUndoReset
; _LOWriter_DocViewCursorGetPosition
; _LOWriter_DocVisible
; _LOWriter_DocZoom
; ===============================================================================================================================
; #FUNCTION# ====================================================================================================================
; Name ..........: _LOWriter_DocBookmarkDelete
; Description ...: Delete a Bookmark.
; Syntax ........: _LOWriter_DocBookmarkDelete(ByRef $oDoc, ByRef $oBookmark)
; Parameters ....: $oDoc - [in/out] an object. A Document object returned by a previous _LOWriter_DocOpen, _LOWriter_DocConnect, or _LOWriter_DocCreate function.
; $oBookmark - [in/out] an object. A Bookmark Object from a previous _LOWriter_DocBookmarkInsert, or _LOWriter_DocBookmarkGetObj function to delete.
; Return values .: Success: 1
; Failure: 0 and sets the @Error and @Extended flags to non-zero.
; --Input Errors--
; @Error 1 @Extended 1 Return 0 = $oDoc not an Object.
; @Error 1 @Extended 2 Return 0 = $oBookmark not an Object.
; --Processing Errors--
; @Error 3 @Extended 1 Return 0 = Attempted to delete Bookmark, but document still contains a Bookmark by that name.
; --Success--
; @Error 0 @Extended 0 Return 1 = Success. Successfully deleted requested Bookmark.
; Author ........: donnyh13
; Modified ......:
; Remarks .......:
; Related .......: _LOWriter_DocBookmarkInsert, _LOWriter_DocBookmarkGetObj, _LOWriter_DocBookmarksGetNames
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _LOWriter_DocBookmarkDelete(ByRef $oDoc, ByRef $oBookmark)
Local $oCOM_ErrorHandler = ObjEvent("AutoIt.Error", __LOWriter_InternalComErrorHandler)
#forceref $oCOM_ErrorHandler
Local $sBookmarkName
If Not IsObj($oDoc) Then Return SetError($__LO_STATUS_INPUT_ERROR, 1, 0)
If Not IsObj($oBookmark) Then Return SetError($__LO_STATUS_INPUT_ERROR, 2, 0)
$sBookmarkName = $oBookmark.Name()
$oBookmark.dispose()
Return (_LOWriter_DocBookmarkExists($oDoc, $sBookmarkName)) ? (SetError($__LO_STATUS_PROCESSING_ERROR, 1, 0)) : (SetError($__LO_STATUS_SUCCESS, 0, 1))
EndFunc ;==>_LOWriter_DocBookmarkDelete
; #FUNCTION# ====================================================================================================================
; Name ..........: _LOWriter_DocBookmarkExists
; Description ...: Check if a document contains a Bookmark by name.
; Syntax ........: _LOWriter_DocBookmarkExists(ByRef $oDoc, $sBookmarkName)
; Parameters ....: $oDoc - [in/out] an object. A Document object returned by a previous _LOWriter_DocOpen, _LOWriter_DocConnect, or _LOWriter_DocCreate function.
; $sBookmarkName - a string value. The Bookmark name to search for.
; Return values .: Success: Boolean
; Failure: 0 and sets the @Error and @Extended flags to non-zero.
; --Input Errors--
; @Error 1 @Extended 1 Return 0 = $oDoc not an Object.
; @Error 1 @Extended 2 Return 0 = $sBookmarkName not a String.
; --Processing Errors--
; @Error 3 @Extended 1 Return 0 = Failed to retrieve Bookmarks Object.
; --Success--
; @Error 0 @Extended 0 Return Boolean = Success. If the document contains a Bookmark by the called name, then True is returned, Else false.
; Author ........: donnyh13
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _LOWriter_DocBookmarkExists(ByRef $oDoc, $sBookmarkName)
Local $oCOM_ErrorHandler = ObjEvent("AutoIt.Error", __LOWriter_InternalComErrorHandler)
#forceref $oCOM_ErrorHandler
Local $oBookmarks
If Not IsObj($oDoc) Then Return SetError($__LO_STATUS_INPUT_ERROR, 1, 0)
If Not IsString($sBookmarkName) Then Return SetError($__LO_STATUS_INPUT_ERROR, 2, 0)
$oBookmarks = $oDoc.getBookmarks()
If Not IsObj($oBookmarks) Then Return SetError($__LO_STATUS_PROCESSING_ERROR, 1, 0)
Return SetError($__LO_STATUS_SUCCESS, 0, $oBookmarks.hasByName($sBookmarkName))
EndFunc ;==>_LOWriter_DocBookmarkExists
; #FUNCTION# ====================================================================================================================
; Name ..........: _LOWriter_DocBookmarkGetAnchor
; Description ...: Retrieve a Bookmark's Anchor cursor Object.
; Syntax ........: _LOWriter_DocBookmarkGetAnchor(ByRef $oBookmark)
; Parameters ....: $oBookmark - [in/out] an object. A Bookmark Object from a previous _LOWriter_DocBookmarkInsert, or _LOWriter_DocBookmarkGetObj function.
; Return values .: Success: Object
; Failure: 0 and sets the @Error and @Extended flags to non-zero.
; --Input Errors--
; @Error 1 @Extended 1 Return 0 = $oBookmark not an Object.
; --Initialization Errors--
; @Error 2 @Extended 1 Return 0 = Failed to retrieve Bookmark anchor Object.
; --Success--
; @Error 0 @Extended 0 Return Object = Success. Returning requested Bookmark Anchor Cursor Object.
; Author ........: donnyh13
; Modified ......:
; Remarks .......: The Anchor cursor returned is just a Text Cursor placed at the anchor's position.
; Related .......: _LOWriter_DocBookmarkGetObj, _LOWriter_DocBookmarkInsert, _LOWriter_CursorMove, _LOWriter_DocGetString, _LOWriter_DocInsertString
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _LOWriter_DocBookmarkGetAnchor(ByRef $oBookmark)
Local $oCOM_ErrorHandler = ObjEvent("AutoIt.Error", __LOWriter_InternalComErrorHandler)
#forceref $oCOM_ErrorHandler
Local $oBookAnchor
If Not IsObj($oBookmark) Then Return SetError($__LO_STATUS_INPUT_ERROR, 1, 0)
$oBookAnchor = $oBookmark.Anchor.Text.createTextCursorByRange($oBookmark.Anchor())
If Not IsObj($oBookAnchor) Then Return SetError($__LO_STATUS_INIT_ERROR, 1, 0)
Return SetError($__LO_STATUS_SUCCESS, 0, $oBookAnchor)
EndFunc ;==>_LOWriter_DocBookmarkGetAnchor
; #FUNCTION# ====================================================================================================================
; Name ..........: _LOWriter_DocBookmarkGetObj
; Description ...: Retrieve a Bookmark Object by name.
; Syntax ........: _LOWriter_DocBookmarkGetObj(ByRef $oDoc, $sBookmarkName)
; Parameters ....: $oDoc - [in/out] an object. A Document object returned by a previous _LOWriter_DocOpen, _LOWriter_DocConnect, or _LOWriter_DocCreate function.
; $sBookmarkName - a string value. The Bookmark name to retrieve the Object for.
; Return values .: Success: Object
; Failure: 0 and sets the @Error and @Extended flags to non-zero.
; --Input Errors--
; @Error 1 @Extended 1 Return 0 = $oDoc not an Object.
; @Error 1 @Extended 2 Return 0 = $sBookmarkName not a String.
; @Error 1 @Extended 3 Return 0 = Document does not contain a Bookmark named in $sBookmarkName.
; --Processing Errors--
; @Error 3 @Extended 1 Return 0 = Failed to retrieve requested Bookmark Object.
; --Success--
; @Error 0 @Extended 0 Return Object = Success. Successfully retrieved requested Bookmark Object. Returning requested Object.
; Author ........: donnyh13
; Modified ......:
; Remarks .......:
; Related .......: _LOWriter_DocBookmarksGetNames, _LOWriter_DocBookmarkModify, _LOWriter_DocBookmarkDelete
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _LOWriter_DocBookmarkGetObj(ByRef $oDoc, $sBookmarkName)
Local $oCOM_ErrorHandler = ObjEvent("AutoIt.Error", __LOWriter_InternalComErrorHandler)
#forceref $oCOM_ErrorHandler
Local $oBookmark
If Not IsObj($oDoc) Then Return SetError($__LO_STATUS_INPUT_ERROR, 1, 0)
If Not IsString($sBookmarkName) Then Return SetError($__LO_STATUS_INPUT_ERROR, 2, 0)
If Not _LOWriter_DocBookmarkExists($oDoc, $sBookmarkName) Then Return SetError($__LO_STATUS_INPUT_ERROR, 3, 0)
$oBookmark = $oDoc.Bookmarks.getByName($sBookmarkName)
If Not IsObj($oBookmark) Then Return SetError($__LO_STATUS_PROCESSING_ERROR, 1, 0)
Return SetError($__LO_STATUS_SUCCESS, 0, $oBookmark)
EndFunc ;==>_LOWriter_DocBookmarkGetObj
; #FUNCTION# ====================================================================================================================
; Name ..........: _LOWriter_DocBookmarkInsert
; Description ...: Insert a Bookmark into a document.
; Syntax ........: _LOWriter_DocBookmarkInsert(ByRef $oDoc, ByRef $oCursor[, $bOverwrite = False[, $sBookmarkName = Null]])
; Parameters ....: $oDoc - [in/out] an object. A Document object returned by a previous _LOWriter_DocOpen, _LOWriter_DocConnect, or _LOWriter_DocCreate function.
; $oCursor - [in/out] an object. A Cursor Object returned from any Cursor Object creation or retrieval function. Cannot be a Table Cursor.
; $bOverwrite - [optional] a boolean value. Default is False. If True, any content selected by the cursor will be overwritten. If False, content will be inserted to the left of any selection.
; $sBookmarkName - [optional] a string value. Default is Null. The Name of the Bookmark to create. See Remarks.
; Return values .: Success: Object
; Failure: 0 and sets the @Error and @Extended flags to non-zero.
; --Input Errors--
; @Error 1 @Extended 1 Return 0 = $oDoc not an Object.
; @Error 1 @Extended 2 Return 0 = $oCursor not an Object.
; @Error 1 @Extended 3 Return 0 = $oCursor is a Table Cursor, which is not supported.
; @Error 1 @Extended 4 Return 0 = $bOverwrite not a Boolean.
; @Error 1 @Extended 5 Return 0 = $sBookmarkName not a String.
; @Error 1 @Extended 6 Return 0 = $sBookmarkName contains illegal characters, /\@:*?";,.# .
; --Initialization Errors--
; @Error 2 @Extended 1 Return 0 = Failed to create "com.sun.star.text.Bookmark" Object.
; --Success--
; @Error 0 @Extended 0 Return Object = Success. Successfully Inserted a Bookmark into the document. Returning the Bookmark Object.
; Author ........: donnyh13
; Modified ......:
; Remarks .......: If the cursor used to insert a Bookmark has text selected, the Bookmark will envelope the text, else the Bookmark will be inserted at a single point.
; A Bookmark name cannot contain the following characters: / \ @ : * ? " ; , . #
; If the document already contains a Bookmark by the same name, Libre Office adds a digit after the name, such as Bookmark 1, Bookmark 2 etc.
; Related .......: _LOWriter_DocBookmarkModify, _LOWriter_DocBookmarkDelete
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _LOWriter_DocBookmarkInsert(ByRef $oDoc, ByRef $oCursor, $bOverwrite = False, $sBookmarkName = Null)
Local $oCOM_ErrorHandler = ObjEvent("AutoIt.Error", __LOWriter_InternalComErrorHandler)
#forceref $oCOM_ErrorHandler
Local $oBookmark
If Not IsObj($oDoc) Then Return SetError($__LO_STATUS_INPUT_ERROR, 1, 0)
If Not IsObj($oCursor) Then Return SetError($__LO_STATUS_INPUT_ERROR, 2, 0)
If (__LOWriter_Internal_CursorGetType($oCursor) = $LOW_CURTYPE_TABLE_CURSOR) Then Return SetError($__LO_STATUS_INPUT_ERROR, 3, 0)
If Not IsBool($bOverwrite) Then Return SetError($__LO_STATUS_INPUT_ERROR, 4, 0)
$oBookmark = $oDoc.createInstance("com.sun.star.text.Bookmark")
If Not IsObj($oBookmark) Then Return SetError($__LO_STATUS_INIT_ERROR, 1, 0)
If ($sBookmarkName <> Null) Then
If Not IsString($sBookmarkName) Then Return SetError($__LO_STATUS_INPUT_ERROR, 5, 0)
If StringRegExp($sBookmarkName, '[/\@:*?";,.#]') Then Return SetError($__LO_STATUS_INPUT_ERROR, 6, 0) ; Invalid Characters in Name.
$oBookmark.Name = $sBookmarkName
Else
$oBookmark.Name = "Bookmark "
EndIf
$oCursor.Text.insertTextContent($oCursor, $oBookmark, $bOverwrite)
Return SetError($__LO_STATUS_SUCCESS, 0, $oBookmark)
EndFunc ;==>_LOWriter_DocBookmarkInsert
; #FUNCTION# ====================================================================================================================
; Name ..........: _LOWriter_DocBookmarkModify
; Description ...: Set or Retrieve a Bookmark's settings.
; Syntax ........: _LOWriter_DocBookmarkModify(ByRef $oBookmark[, $sBookmarkName = Null])
; Parameters ....: $oBookmark - [in/out] an object. A Bookmark Object from a previous _LOWriter_DocBookmarkInsert, or _LOWriter_DocBookmarkGetObj function.
; $sBookmarkName - [optional] a string value. Default is Null. The new name to rename the bookmark called in $oBookmark.
; Return values .: Success: 1 or String
; Failure: 0 and sets the @Error and @Extended flags to non-zero.
; --Input Errors--
; @Error 1 @Extended 1 Return 0 = $oBookmark not an Object.
; @Error 1 @Extended 2 Return 0 = $sBookmarkName not a String.
; @Error 1 @Extended 3 Return 0 = $sBookmarkName contains illegal characters, /\@:*?";,.# .
; --Property Setting Errors--
; @Error 4 @Extended ? Return 0 = Some settings were not successfully set. Use BitAND to test @Extended for the following values:
; | 1 = Error setting $sBookmarkName
; --Success--
; @Error 0 @Extended 0 Return 1 = Success. Bookmark name successfully modified.
; @Error 0 @Extended 0 Return String = Success. $sBookmarkName set to Null, returning current Bookmark name.
; Author ........: donnyh13
; Modified ......:
; Remarks .......: Call this function with only the required parameters (or with all other parameters set to Null keyword), to get the current settings.
; Call any optional parameter with Null keyword to skip it.
; A Bookmark name cannot contain the following characters: / \ @ : * ? " ; , . #
; If the document already contains a Bookmark by the same name, Libre Office adds a digit after the name, such as Bookmark 1, Bookmark 2 etc.
; Related .......: _LOWriter_DocBookmarkGetObj, _LOWriter_DocBookmarkInsert, _LOWriter_DocBookmarkDelete
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _LOWriter_DocBookmarkModify(ByRef $oBookmark, $sBookmarkName = Null)
Local $oCOM_ErrorHandler = ObjEvent("AutoIt.Error", __LOWriter_InternalComErrorHandler)
#forceref $oCOM_ErrorHandler
Local $iError = 0
If Not IsObj($oBookmark) Then Return SetError($__LO_STATUS_INPUT_ERROR, 1, 0)
If __LOWriter_VarsAreNull($sBookmarkName) Then Return SetError($__LO_STATUS_SUCCESS, 1, $oBookmark.Name())
If Not IsString($sBookmarkName) Then Return SetError($__LO_STATUS_INPUT_ERROR, 2, 0)
If StringRegExp($sBookmarkName, '[/\@:*?";,.#]') Then Return SetError($__LO_STATUS_INPUT_ERROR, 3, 0) ; Invalid Characters in Name.
$oBookmark.Name = $sBookmarkName
$iError = ($oBookmark.Name() = $sBookmarkName) ? ($iError) : (BitOR($iError, 1))
Return ($iError > 0) ? (SetError($__LO_STATUS_PROP_SETTING_ERROR, $iError, 0)) : (SetError($__LO_STATUS_SUCCESS, 0, 1))
EndFunc ;==>_LOWriter_DocBookmarkModify
; #FUNCTION# ====================================================================================================================
; Name ..........: _LOWriter_DocBookmarksGetNames
; Description ...: Retrieve an Array of Bookmark names.
; Syntax ........: _LOWriter_DocBookmarksGetNames(ByRef $oDoc)
; Parameters ....: $oDoc - [in/out] an object. A Document object returned by a previous _LOWriter_DocOpen, _LOWriter_DocConnect, or _LOWriter_DocCreate function.
; Return values .: Success: Array
; Failure: 0 and sets the @Error and @Extended flags to non-zero.
; --Input Errors--
; @Error 1 @Extended 1 Return 0 = $oDoc not an Object.
; --Processing Errors--
; @Error 3 @Extended 1 Return 0 = Failed to retrieve Array of Bookmark Names.
; --Success--
; @Error 0 @Extended ? Return Array = Success. Successfully searched for Bookmarks, returning Array of Bookmark names, @Extended set to number of results.
; Author ........: donnyh13
; Modified ......:
; Remarks .......:
; Related .......: _LOWriter_DocBookmarkGetObj
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _LOWriter_DocBookmarksGetNames(ByRef $oDoc)
Local $oCOM_ErrorHandler = ObjEvent("AutoIt.Error", __LOWriter_InternalComErrorHandler)
#forceref $oCOM_ErrorHandler
Local $asBookmarkNames[0]
If Not IsObj($oDoc) Then Return SetError($__LO_STATUS_INPUT_ERROR, 1, 0)
$asBookmarkNames = $oDoc.Bookmarks.getElementNames()
If Not IsArray($asBookmarkNames) Then Return SetError($__LO_STATUS_PROCESSING_ERROR, 1, 0)
Return SetError($__LO_STATUS_SUCCESS, UBound($asBookmarkNames), $asBookmarkNames)
EndFunc ;==>_LOWriter_DocBookmarksGetNames
; #FUNCTION# ====================================================================================================================
; Name ..........: _LOWriter_DocClose
; Description ...: Close an existing Writer Document, returning its save path if applicable.
; Syntax ........: _LOWriter_DocClose(ByRef $oDoc[, $bSaveChanges = True[, $sSaveName = ""[, $bDeliverOwnership = True]]])
; Parameters ....: $oDoc - [in/out] an object. A Document object returned by a previous _LOWriter_DocOpen, _LOWriter_DocConnect, or _LOWriter_DocCreate function.
; $bSaveChanges - [optional] a boolean value. Default is True. If true, saves changes if any were made before closing. See remarks.
; $sSaveName - [optional] a string value. Default is "". The file name to save the file as, if the file hasn't been saved before. See Remarks.
; $bDeliverOwnership - [optional] a boolean value. Default is True. If True, deliver ownership of the document Object from the script to LibreOffice, recommended is True.
; Return values .: Success: String
; Failure: 0 and sets the @Error and @Extended flags to non-zero.
; --Input Errors--
; @Error 1 @Extended 1 Return 0 = $oDoc not an Object.
; @Error 1 @Extended 2 Return 0 = $bSaveChanges not a Boolean.
; @Error 1 @Extended 3 Return 0 = $sSaveName not a String.
; @Error 1 @Extended 4 Return 0 = $bDeliverOwnership not a Boolean.
; --Processing Errors--
; @Error 3 @Extended 1 Return 0 = Path Conversion to L.O. URL Failed.
; @Error 3 @Extended 2 Return 0 = Error while retrieving FilterName.
; @Error 3 @Extended 3 Return 0 = Error while setting Filter Name properties.
; --Success--
; @Error 0 @Extended 1 Return String = Success, Document was successfully closed, and was saved to the returned file Path.
; @Error 0 @Extended 2 Return String = Success, Document was successfully closed, document's changes were saved to its existing location.
; @Error 0 @Extended 3 Return String = Success, Document was successfully closed, document either had no changes to save, or $bSaveChanges was set to False. If document had a save location, or if document was saved to a location, it is returned, else an empty string is returned.
; Author ........: donnyh13
; Modified ......:
; Remarks .......: If $bSaveChanges is true and the document hasn't been saved yet, the document is saved to the desktop.
; If $sSaveName is undefined, it is saved as an .odt document to the desktop, named Year-Month-Day_Hour-Minute-Second.odt.
; $sSaveName may be a name only without an extension, in which case the file will be saved in .odt format. Or you may define your own format by including an extension, such as "Test.docx"
; Related .......: _LOWriter_DocOpen, _LOWriter_DocConnect, _LOWriter_DocCreate, _LOWriter_DocSaveAs, _LOWriter_DocSave
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _LOWriter_DocClose(ByRef $oDoc, $bSaveChanges = True, $sSaveName = "", $bDeliverOwnership = True)
Local $oCOM_ErrorHandler = ObjEvent("AutoIt.Error", __LOWriter_InternalComErrorHandler)
#forceref $oCOM_ErrorHandler
Local $sDocPath = "", $sSavePath, $sFilterName
Local $aArgs[1]
If Not IsObj($oDoc) Then Return SetError($__LO_STATUS_INPUT_ERROR, 1, 0)
If Not IsBool($bSaveChanges) Then Return SetError($__LO_STATUS_INPUT_ERROR, 2, 0)
If Not IsString($sSaveName) Then Return SetError($__LO_STATUS_INPUT_ERROR, 3, 0)
If Not IsBool($bDeliverOwnership) Then Return SetError($__LO_STATUS_INPUT_ERROR, 4, 0)
If Not $oDoc.hasLocation() And ($bSaveChanges = True) Then
$sSavePath = @DesktopDir & "\"
If ($sSaveName = "") Or ($sSaveName = " ") Then
$sSaveName = @YEAR & "-" & @MON & "-" & @MDAY & "_" & @HOUR & "-" & @MIN & "-" & @SEC & ".odt"
$sFilterName = "writer8"
EndIf
$sSavePath = _LOWriter_PathConvert($sSavePath & $sSaveName, 1)
If @error Then Return SetError($__LO_STATUS_PROCESSING_ERROR, 1, 0)
If $sFilterName = "" Then $sFilterName = __LOWriter_FilterNameGet($sSavePath)
If @error Then Return SetError($__LO_STATUS_PROCESSING_ERROR, 2, 0)
$aArgs[0] = __LOWriter_SetPropertyValue("FilterName", $sFilterName)
If @error Then Return SetError($__LO_STATUS_PROCESSING_ERROR, 3, 0)
EndIf
If ($bSaveChanges = True) Then
If $oDoc.hasLocation() Then
$oDoc.store()
$sDocPath = _LOWriter_PathConvert($oDoc.getURL(), $LOW_PATHCONV_PCPATH_RETURN)
$oDoc.Close($bDeliverOwnership)
Return SetError($__LO_STATUS_SUCCESS, 2, $sDocPath)
Else
$oDoc.storeAsURL($sSavePath, $aArgs)
$oDoc.Close($bDeliverOwnership)
Return SetError($__LO_STATUS_SUCCESS, 1, _LOWriter_PathConvert($sSavePath, $LOW_PATHCONV_PCPATH_RETURN))
EndIf
EndIf
If $oDoc.hasLocation() Then $sDocPath = _LOWriter_PathConvert($oDoc.getURL(), $LOW_PATHCONV_PCPATH_RETURN)
$oDoc.Close($bDeliverOwnership)
Return SetError($__LO_STATUS_SUCCESS, 3, $sDocPath)
EndFunc ;==>_LOWriter_DocClose
; #FUNCTION# ====================================================================================================================
; Name ..........: _LOWriter_DocConnect
; Description ...: Connect to an already opened instance of LibreOffice Writer.
; Syntax ........: _LOWriter_DocConnect($sFile[, $bConnectCurrent = False[, $bConnectAll = False]])
; Parameters ....: $sFile - a string value. A Full or partial file path, or a full or partial file name. See remarks. Can be an empty string if $bConnectAll or $bConnectCurrent is True.
; $bConnectCurrent - [optional] a boolean value. Default is False. If True, returns the currently active, or last active Document, unless it is not a Text Document.
; $bConnectAll - [optional] a boolean value. Default is False. If True, returns an array containing all open LibreOffice Writer Text Documents. See remarks.
; Return values .: Success: Object or Array.
; Failure: 0 and sets the @Error and @Extended flags to non-zero.
; --Input Errors--
; @Error 1 @Extended 1 Return 0 = $sFile not a string.
; @Error 1 @Extended 2 Return 0 = $bConnectCurrent not a Boolean.
; @Error 1 @Extended 3 Return 0 = $bConnectAll not a Boolean.
; --Initialization Errors--
; @Error 2 @Extended 1 Return 0 = Error creating ServiceManager object.
; @Error 2 @Extended 2 Return 0 = Error creating Desktop object.
; @Error 2 @Extended 3 Return 0 = Error creating enumeration of open documents.
; --Processing Errors--
; @Error 3 @Extended 1 Return 0 = Error converting path to Libre Office URL.
; --Document Errors--
; @Error 5 @Extended 1 Return 0 = No matches found.
; @Error 5 @Extended 2 Return 0 = Current Component not a Text Document.
; @Error 5 @Extended 3 Return 0 = No open Libre Office documents found.
; --Success--
; @Error 0 @Extended 1 Return Object = Success, The Object for the current, or last active document is returned.
; @Error 0 @Extended 2 Return Array = Success, An Array of all open LibreOffice Writer Text documents is returned. See remarks.
; @Error 0 @Extended 3 Return Object = Success, The Object for the document with matching URL is returned.
; @Error 0 @Extended 4 Return Object = Success, The Object for the document with matching Title is returned.
; @Error 0 @Extended 5 Return Object = Success, A partial Title or Path search found only one match, returning the Object for the found document.
; @Error 0 @Extended 6 Return Array = Success, An Array of all matching Libre Text documents from a partial Title or Path search. See remarks.
; Author ........: donnyh13
; Modified ......:
; Remarks .......: $sFile can be either the full Path (Name and extension included; e.g: C:\file\Test.odt Or file:///C:/file/Test.odt) of the document, or the full Title with extension, (e.g: Test.odt), or a partial file path (e.g: file1\file2\Test Or file1\file2 Or file1/file2/ etc.), or a partial name (e.g: test, would match Test1.odt, Test2.docx etc.).
; Partial file path searches and file name searches, as well as the connect all option, return arrays with three columns per result. ($aArray[0][3]). each result is stored in a separate row;
; -Row 1, Column 0 contains the Object for that document. e.g. $aArray[0][0] = $oDoc
; -Row 1, Column 1 contains the Document's full title and extension. e.g. $aArray[0][1] = This Test File.docx
; -Row 1, Column 2 contains the document's full file path. e.g. $aArray[0][2] = C:\Folder1\Folder2\This Test File.docx
; -Row 2, Column 0 contains the Object for the next document. And so on. e.g. $aArray[1][0] = $oDoc2
; Related .......: _LOWriter_DocOpen, _LOWriter_DocClose, _LOWriter_DocCreate
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _LOWriter_DocConnect($sFile, $bConnectCurrent = False, $bConnectAll = False)
Local $oCOM_ErrorHandler = ObjEvent("AutoIt.Error", __LOWriter_InternalComErrorHandler)
#forceref $oCOM_ErrorHandler
Local $iCount = 0
Local Const $STR_STRIPLEADING = 1
Local $aoConnectAll[1], $aoPartNameSearch[1]
Local $oEnumDoc, $oDoc, $oServiceManager, $oDesktop
Local $sServiceName = "com.sun.star.text.TextDocument"
If Not IsString($sFile) Then Return SetError($__LO_STATUS_INPUT_ERROR, 1, 0)
If Not IsBool($bConnectCurrent) Then Return SetError($__LO_STATUS_INPUT_ERROR, 2, 0)
If Not IsBool($bConnectAll) Then Return SetError($__LO_STATUS_INPUT_ERROR, 3, 0)
$oServiceManager = ObjCreate("com.sun.star.ServiceManager")
If Not IsObj($oServiceManager) Then Return SetError($__LO_STATUS_INIT_ERROR, 1, 0)
$oDesktop = $oServiceManager.createInstance("com.sun.star.frame.Desktop")
If Not IsObj($oDesktop) Then Return SetError($__LO_STATUS_INIT_ERROR, 2, 0)
If Not $oDesktop.getComponents.hasElements() Then Return SetError($__LO_STATUS_DOC_ERROR, 3, 0) ; no L.O open
$oEnumDoc = $oDesktop.getComponents.createEnumeration()
If Not IsObj($oEnumDoc) Then Return SetError($__LO_STATUS_INIT_ERROR, 3, 0)
If $bConnectCurrent Then
$oDoc = $oDesktop.currentComponent()
Return ($oDoc.supportsService($sServiceName) And Not IsObj($oDoc.Parent())) ? (SetError($__LO_STATUS_SUCCESS, 1, $oDoc)) : (SetError($__LO_STATUS_DOC_ERROR, 2, 0))
EndIf
If $bConnectAll Then
ReDim $aoConnectAll[1][3]
$iCount = 0
While $oEnumDoc.hasMoreElements()
$oDoc = $oEnumDoc.nextElement()
If $oDoc.supportsService($sServiceName) And Not IsObj($oDoc.Parent()) Then ; If Parent is an Object, then Writer doc is a DataBase Form
ReDim $aoConnectAll[$iCount + 1][3]
$aoConnectAll[$iCount][0] = $oDoc
$aoConnectAll[$iCount][1] = $oDoc.Title()
$aoConnectAll[$iCount][2] = _LOWriter_PathConvert($oDoc.getURL(), $LOW_PATHCONV_PCPATH_RETURN)
$iCount += 1
EndIf
Sleep(10)
WEnd
Return SetError($__LO_STATUS_SUCCESS, 2, $aoConnectAll)
EndIf
$sFile = StringStripWS($sFile, $STR_STRIPLEADING)
If StringInStr($sFile, "\") Then $sFile = _LOWriter_PathConvert($sFile, $LOW_PATHCONV_OFFICE_RETURN) ; Convert to L.O File path.
If @error Then Return SetError($__LO_STATUS_PROCESSING_ERROR, 1, 0)
If StringInStr($sFile, "file:///") Then ; URL/Path and Name search
While $oEnumDoc.hasMoreElements()
$oDoc = $oEnumDoc.nextElement()
If ($oDoc.getURL() == $sFile) Then Return SetError($__LO_STATUS_SUCCESS, 3, $oDoc) ; Match
WEnd
Return SetError($__LO_STATUS_DOC_ERROR, 1, 0) ; no match
Else
If Not StringInStr($sFile, "/") And StringInStr($sFile, ".") Then ; Name with extension only search
While $oEnumDoc.hasMoreElements()
$oDoc = $oEnumDoc.nextElement()
If StringInStr($oDoc.Title, $sFile) Then Return SetError($__LO_STATUS_SUCCESS, 4, $oDoc) ; Match
WEnd
Return SetError($__LO_STATUS_DOC_ERROR, 1, 0) ; no match
EndIf
$iCount = 0 ; partial name or partial URL search
ReDim $aoPartNameSearch[$iCount + 1][3]
While $oEnumDoc.hasMoreElements()
$oDoc = $oEnumDoc.nextElement()
If StringInStr($sFile, "/") Then
If StringInStr($oDoc.getURL(), $sFile) Then
ReDim $aoPartNameSearch[$iCount + 1][3]
$aoPartNameSearch[$iCount][0] = $oDoc
$aoPartNameSearch[$iCount][1] = $oDoc.Title
$aoPartNameSearch[$iCount][2] = _LOWriter_PathConvert($oDoc.getURL, $LOW_PATHCONV_PCPATH_RETURN)
$iCount += 1
EndIf
Else
If StringInStr($oDoc.Title, $sFile) Then
ReDim $aoPartNameSearch[$iCount + 1][3]
$aoPartNameSearch[$iCount][0] = $oDoc
$aoPartNameSearch[$iCount][1] = $oDoc.Title
$aoPartNameSearch[$iCount][2] = _LOWriter_PathConvert($oDoc.getURL, $LOW_PATHCONV_PCPATH_RETURN)
$iCount += 1
EndIf
EndIf
WEnd
If IsString($aoPartNameSearch[0][1]) Then
If (UBound($aoPartNameSearch) = 1) Then
Return SetError($__LO_STATUS_SUCCESS, 5, $aoPartNameSearch[0][0]) ; matches
Else
Return SetError($__LO_STATUS_SUCCESS, 6, $aoPartNameSearch) ; matches
EndIf
Else
Return SetError($__LO_STATUS_DOC_ERROR, 1, 0) ; no match
EndIf
EndIf
EndFunc ;==>_LOWriter_DocConnect
; #FUNCTION# ====================================================================================================================
; Name ..........: _LOWriter_DocConvertTableToText
; Description ...: Convert a Table to Text, separated by a delimiter.
; Syntax ........: _LOWriter_DocConvertTableToText(ByRef $oDoc, ByRef $oTable[, $sDelimiter = @TAB])
; Parameters ....: $oDoc - [in/out] an object. A Document object returned by a previous _LOWriter_DocOpen, _LOWriter_DocConnect, or _LOWriter_DocCreate function.
; $oTable - [in/out] an object. A Table Object returned by a previous _LOWriter_TableInsert, _LOWriter_TableGetObjByCursor, or _LOWriter_TableGetObjByName function.
; $sDelimiter - [optional] a string value. Default is @TAB. A character to separate each column by, such as a Tab character, etc.
; Return values .: Success: 1
; Failure: 0 and sets the @Error and @Extended flags to non-zero.
; --Input Errors--
; @Error 1 @Extended 1 Return 0 = $oDoc not an Object.
; @Error 1 @Extended 2 Return 0 = $oTable not an Object.
; @Error 1 @Extended 3 Return 0 = $sDelimiter not a String.
; --Initialization Errors--
; @Error 2 @Extended 1 Return 0 = Failed to create a backup of the ViewCursor's current location.
; @Error 2 @Extended 2 Return 0 = Failed to create a Text Cursor in the first cell.
; @Error 2 @Extended 3 Return 0 = Failed to create "com.sun.star.ServiceManager" Object.
; @Error 2 @Extended 4 Return 0 = Failed to create "com.sun.star.frame.DispatchHelper" Object.
; --Processing Errors--
; @Error 3 @Extended 1 Return 0 = Failed to retrieve array of CellNames.
; @Error 3 @Extended 2 Return 0 = Failed to retrieve ViewCursor object.
; --Success--
; @Error 0 @Extended 0 Return 1 = Success. Table was successfully converted to text.
; Author ........: donnyh13
; Modified ......:
; Remarks .......: This function temporarily moves the Viewcursor to the Table indicated, and then attempts to restore the ViewCursor to its former position.
; This could cause a COM error if the Cursor was presently in the Table.
; Related .......: _LOWriter_DocConvertTextToTable, _LOWriter_TableGetObjByName, _LOWriter_TableGetObjByCursor, _LOWriter_TableInsert
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _LOWriter_DocConvertTableToText(ByRef $oDoc, ByRef $oTable, $sDelimiter = @TAB)
Local $oCOM_ErrorHandler = ObjEvent("AutoIt.Error", __LOWriter_InternalComErrorHandler)
#forceref $oCOM_ErrorHandler
Local $aArgs[1]
Local $asCellNames
Local $oServiceManager, $oDispatcher, $oCellTextCursor, $oViewCursor, $oViewCursorBackup
If Not IsObj($oDoc) Then Return SetError($__LO_STATUS_INPUT_ERROR, 1, 0)
If Not IsObj($oTable) Then Return SetError($__LO_STATUS_INPUT_ERROR, 2, 0)
If Not IsString($sDelimiter) Then Return SetError($__LO_STATUS_INPUT_ERROR, 3, 0)
$aArgs[0] = __LOWriter_SetPropertyValue("Delimiter", $sDelimiter)
$asCellNames = $oTable.getCellNames()
If Not IsArray($asCellNames) Then Return SetError($__LO_STATUS_PROCESSING_ERROR, 1, 0)
; Retrieve the ViewCursor.
$oViewCursor = $oDoc.CurrentController.getViewCursor()
If Not IsObj($oViewCursor) Then Return SetError($__LO_STATUS_PROCESSING_ERROR, 2, 0)
; Create a Text cursor at the current ViewCursor position to move the Viewcursor back to.
$oViewCursorBackup = _LOWriter_DocCreateTextCursor($oDoc, False, True)
If Not IsObj($oViewCursorBackup) Then
$oViewCursorBackup = _LOWriter_DocCreateTextCursor($oDoc, False) ; If That Failed, create a Backup Cursor at the beginning of the document.
If Not IsObj($oViewCursorBackup) Then Return SetError($__LO_STATUS_INIT_ERROR, 1, 0)
EndIf
; Retrieve the first cell in the table and create a text cursor in it to move the ViewCursor to.
$oCellTextCursor = $oTable.getCellByName($asCellNames[0]).Text.createTextCursor()
If Not IsObj($oCellTextCursor) Then Return SetError($__LO_STATUS_INIT_ERROR, 2, 0)
$oViewCursor.gotoRange($oCellTextCursor, False)
$oServiceManager = ObjCreate("com.sun.star.ServiceManager")
If Not IsObj($oServiceManager) Then Return SetError($__LO_STATUS_INIT_ERROR, 3, 0)
$oDispatcher = $oServiceManager.createInstance("com.sun.star.frame.DispatchHelper")
If Not IsObj($oDispatcher) Then Return SetError($__LO_STATUS_INIT_ERROR, 4, 0)
$oDispatcher.executeDispatch($oDoc.CurrentController(), ".uno:ConvertTableToText", "", 0, $aArgs)
; Restore the ViewCursor to its previous location.
$oViewCursor.gotoRange($oViewCursorBackup, False)
Return SetError($__LO_STATUS_SUCCESS, 0, 1)
EndFunc ;==>_LOWriter_DocConvertTableToText
; #FUNCTION# ====================================================================================================================
; Name ..........: _LOWriter_DocConvertTextToTable
; Description ...: Convert some selected text into a Table.
; Syntax ........: _LOWriter_DocConvertTextToTable(ByRef $oDoc, ByRef $oCursor[, $sDelimiter = @TAB[, $bHeader = False[, $iRepeatHeaderLines = 0[, $bBorder = False[, $bDontSplitTable = False]]]]])
; Parameters ....: $oDoc - [in/out] an object. A Document object returned by a previous _LOWriter_DocOpen, _LOWriter_DocConnect, or _LOWriter_DocCreate function.
; $oCursor - [in/out] an object. A Cursor Object returned from any Cursor Object creation or retrieval functions. Default is Null. See Remarks.
; $sDelimiter - [optional] a string value. Default is @TAB. A character to the text into each column by, such as a Tab etc.
; $bHeader - [optional] a boolean value. Default is False. If True, Formats the first row of the new table as a heading.
; $iRepeatHeaderLines - [optional] an integer value. Default is 0. If greater than 0, then Repeats the first n rows as a header.
; $bBorder - [optional] a boolean value. Default is False. If True, Adds a border to the table and the table cells.
; $bDontSplitTable - [optional] a boolean value. Default is False. If True, Does not divide the table across pages.
; Return values .: Success: Object
; Failure: 0 and sets the @Error and @Extended flags to non-zero.
; --Input Errors--
; @Error 1 @Extended 1 Return 0 = $oDoc not an Object.
; @Error 1 @Extended 2 Return 0 = $oCursor not an Object.
; @Error 1 @Extended 3 Return 0 = $sDelimiter not a String.
; @Error 1 @Extended 4 Return 0 = $bHeader not a Boolean.
; @Error 1 @Extended 5 Return 0 = $iRepeatHeaderLines not an Integer.
; @Error 1 @Extended 6 Return 0 = $bBorder not a Boolean.
; @Error 1 @Extended 7 Return 0 = $bDontSplitTable not a Boolean.
; @Error 1 @Extended 8 Return 0 = $oCursor is a Table Cursor and is not supported.
; @Error 1 @Extended 9 Return 0 = $oCursor has no data selected.
; --Initialization Errors--
; @Error 2 @Extended 1 Return 0 = Failed to create "com.sun.star.ServiceManager" Object.
; @Error 2 @Extended 2 Return 0 = Failed to create "com.sun.star.frame.DispatchHelper" Object.
; @Error 2 @Extended 3 Return 0 = Failed to create a backup of the ViewCursor's current location.
; --Processing Errors--
; @Error 3 @Extended 1 Return 0 = Failed to retrieve TextTables Object.
; @Error 3 @Extended 2 Return 0 = Failed to $oCursor's cursor type.
; @Error 3 @Extended 3 Return 0 = Failed to retrieve ViewCursor object.
; @Error 3 @Extended 4 Return 0 = Failed to retrieve new Table's Object.
; --Success--
; @Error 0 @Extended 0 Return Object = Success. Text was successfully converted to a Table, returning the new Table's Object.
; Author ........: donnyh13
; Modified ......:
; Remarks .......: This function temporarily moves the ViewCursor to and selects the Text, and then attempts to restore the ViewCursor to its former position.
; Related .......: _LOWriter_DocGetViewCursor, _LOWriter_DocCreateTextCursor, _LOWriter_CellCreateTextCursor, _LOWriter_FrameCreateTextCursor, _LOWriter_DocHeaderGetTextCursor, _LOWriter_DocFooterGetTextCursor, _LOWriter_ParObjCreateList, _LOWriter_DocConvertTableToText
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _LOWriter_DocConvertTextToTable(ByRef $oDoc, ByRef $oCursor, $sDelimiter = @TAB, $bHeader = False, $iRepeatHeaderLines = 0, $bBorder = False, $bDontSplitTable = False)
Local $oCOM_ErrorHandler = ObjEvent("AutoIt.Error", __LOWriter_InternalComErrorHandler)
#forceref $oCOM_ErrorHandler
Local $asTables[0]
Local $atArgs[5]
Local $oServiceManager, $oDispatcher, $oViewCursor, $oViewCursorBackup, $oTables, $oTable
Local $iCursorType
If Not IsObj($oDoc) Then Return SetError($__LO_STATUS_INPUT_ERROR, 1, 0)
If Not IsObj($oCursor) Then Return SetError($__LO_STATUS_INPUT_ERROR, 2, 0)
If Not IsString($sDelimiter) Then Return SetError($__LO_STATUS_INPUT_ERROR, 3, 0)
If Not IsBool($bHeader) Then Return SetError($__LO_STATUS_INPUT_ERROR, 4, 0)
If Not IsInt($iRepeatHeaderLines) Then Return SetError($__LO_STATUS_INPUT_ERROR, 5, 0)
If Not IsBool($bBorder) Then Return SetError($__LO_STATUS_INPUT_ERROR, 6, 0)
If Not IsBool($bDontSplitTable) Then Return SetError($__LO_STATUS_INPUT_ERROR, 7, 0)
$oTables = $oDoc.TextTables()
If Not IsObj($oTables) Then Return SetError($__LO_STATUS_PROCESSING_ERROR, 1, 0)
ReDim $asTables[$oTables.getCount()]
; Store all current Table Names.
For $i = 0 To $oTables.getCount() - 1
$asTables[$i] = $oTables.getByIndex($i).Name()
Sleep((IsInt($i / $__LOWCONST_SLEEP_DIV) ? (10) : (0))) ;Sleep every x cycles.
Next
$iCursorType = __LOWriter_Internal_CursorGetType($oCursor)
If @error Then Return SetError($__LO_STATUS_PROCESSING_ERROR, 2, 0)
If ($iCursorType = $LOW_CURTYPE_TABLE_CURSOR) Then Return SetError($__LO_STATUS_INPUT_ERROR, 8, 0)
; If Cursor has no data selected, return error.
If $oCursor.isCollapsed() Then Return SetError($__LO_STATUS_INPUT_ERROR, 9, 0)
$oServiceManager = ObjCreate("com.sun.star.ServiceManager")
If Not IsObj($oServiceManager) Then Return SetError($__LO_STATUS_INIT_ERROR, 1, 0)
$oDispatcher = $oServiceManager.createInstance("com.sun.star.frame.DispatchHelper")
If Not IsObj($oDispatcher) Then Return SetError($__LO_STATUS_INIT_ERROR, 2, 0)
$atArgs[0] = __LOWriter_SetPropertyValue("Delimiter", $sDelimiter)
$atArgs[1] = __LOWriter_SetPropertyValue("WithHeader", $bHeader)
$atArgs[2] = __LOWriter_SetPropertyValue("RepeatHeaderLines", $iRepeatHeaderLines)
$atArgs[3] = __LOWriter_SetPropertyValue("WithBorder", $bBorder)
$atArgs[4] = __LOWriter_SetPropertyValue("DontSplitTable", $bDontSplitTable)
If ($iCursorType = $LOW_CURTYPE_TEXT_CURSOR) Then
; Retrieve the ViewCursor.
$oViewCursor = $oDoc.CurrentController.getViewCursor()
If Not IsObj($oViewCursor) Then Return SetError($__LO_STATUS_PROCESSING_ERROR, 3, 0)
; Create a Text cursor at the current ViewCursor position to move the Viewcursor back to.
$oViewCursorBackup = _LOWriter_DocCreateTextCursor($oDoc, False, True)
If Not IsObj($oViewCursorBackup) Then Return SetError($__LO_STATUS_INIT_ERROR, 3, 0)
$oViewCursor.gotoRange($oCursor, False)
$oDispatcher.executeDispatch($oDoc.CurrentController(), ".uno:ConvertTextToTable", "", 0, $atArgs)
; Restore the ViewCursor to its previous location.
$oViewCursor.gotoRange($oViewCursorBackup, False)
Else
$oDispatcher.executeDispatch($oDoc.CurrentController(), ".uno:ConvertTextToTable", "", 0, $atArgs)
EndIf
; Obtain the newly created table object by comparing the original table names to the new list of tables.
; If none match, then it is the new one. Return that Table's Object.
For $i = 0 To $oTables.getCount() - 1
For $j = 0 To UBound($asTables) - 1
If ($asTables[$j] = $oTables.getByIndex($i).Name()) Then ExitLoop
Sleep((IsInt($i / $__LOWCONST_SLEEP_DIV) ? (10) : (0))) ; Sleep every x cycles.
Next
If ($j = UBound($asTables)) Then ; If No matches in the original table names, then set Table Object and exit loop
$oTable = $oTables.getByIndex($i)
ExitLoop
EndIf
Next
Return (IsObj($oTable)) ? (SetError($__LO_STATUS_SUCCESS, 0, $oTable)) : (SetError($__LO_STATUS_PROCESSING_ERROR, 4, 0))
EndFunc ;==>_LOWriter_DocConvertTextToTable
; #FUNCTION# ====================================================================================================================
; Name ..........: _LOWriter_DocCreate
; Description ...: Open a new Libre Office Writer Document or Connect to an existing blank, unsaved, writable document.
; Syntax ........: _LOWriter_DocCreate([$bForceNew = True[, $bHidden = False]])
; Parameters ....: $bForceNew - [optional] a boolean value. Default is True. If True, force opening a new Writer Document instead of checking for a usable blank.
; $bHidden - [optional] a boolean value. Default is False. If True opens the new document invisible or changes the existing document to invisible.
; Return values .: Success: Object
; Failure: 0 and sets the @Error and @Extended flags to non-zero.
; --Input Errors--
; @Error 1 @Extended 1 Return 0 = $bForceNew not a Boolean.
; @Error 1 @Extended 2 Return 0 = $bHidden not a Boolean.
; --Initialization Errors--
; @Error 2 @Extended 1 Return 0 = Failure Creating Object com.sun.star.ServiceManager.
; @Error 2 @Extended 2 Return 0 = Failure Creating Object com.sun.star.frame.Desktop.
; @Error 2 @Extended 3 Return 0 = Failed to enumerate available documents.
; @Error 2 @Extended 4 Return 0 = Failure Creating New Document.
; --Property Setting Errors--
; @Error 4 @Extended ? Return 0 = Some settings were not successfully set. Document Object is still returned. Use BitAND to test @Extended for the following values:
; | 1 = Error setting $bHidden
; --Success--
; @Error 0 @Extended 1 Return Object = Successfully connected to an existing Document. Returning Document's Object
; @Error 0 @Extended 2 Return Object = Successfully created a new document. Returning Document's Object
; Author ........: donnyh13
; Modified ......:
; Remarks .......:
; Related .......: _LOWriter_DocOpen, _LOWriter_DocClose, _LOWriter_DocConnect
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _LOWriter_DocCreate($bForceNew = True, $bHidden = False)
Local $oCOM_ErrorHandler = ObjEvent("AutoIt.Error", __LOWriter_InternalComErrorHandler)
#forceref $oCOM_ErrorHandler
Local Const $iURLFrameCreate = 8 ;frame will be created if not found
Local $aArgs[1]
Local $iError = 0
Local $oServiceManager, $oDesktop, $oDoc, $oEnumDoc
If Not IsBool($bForceNew) Then Return SetError($__LO_STATUS_INPUT_ERROR, 1, 0)
If Not IsBool($bHidden) Then Return SetError($__LO_STATUS_INPUT_ERROR, 2, 0)
$aArgs[0] = __LOWriter_SetPropertyValue("Hidden", $bHidden)
$oServiceManager = ObjCreate("com.sun.star.ServiceManager")
If Not IsObj($oServiceManager) Then Return SetError($__LO_STATUS_INIT_ERROR, 1, 0)
$oDesktop = $oServiceManager.createInstance("com.sun.star.frame.Desktop")
If Not IsObj($oDesktop) Then Return SetError($__LO_STATUS_INIT_ERROR, 2, 0)
; If not force new, and L.O pages exist then see if there are any blank writer documents to use.
If Not $bForceNew And $oDesktop.getComponents.hasElements() Then
$oEnumDoc = $oDesktop.getComponents.createEnumeration()
If Not IsObj($oEnumDoc) Then Return SetError($__LO_STATUS_INIT_ERROR, 3, 0)
While $oEnumDoc.hasMoreElements()
$oDoc = $oEnumDoc.nextElement()
If $oDoc.supportsService("com.sun.star.text.TextDocument") And Not ($oDoc.hasLocation() And $oDoc.isReadOnly()) And ($oDoc.WordCount() = 0) Then
$oDoc.CurrentController.Frame.ContainerWindow.Visible = ($bHidden) ? (False) : (True) ; opposite value of $bHidden.
$iError = ($oDoc.CurrentController.Frame.isHidden() = $bHidden) ? ($iError) : (BitOR($iError, 1))
Return ($iError > 0) ? (SetError($__LO_STATUS_PROP_SETTING_ERROR, $iError, $oDoc)) : (SetError($__LO_STATUS_SUCCESS, 1, $oDoc))
EndIf
WEnd
EndIf
If Not IsObj($aArgs[0]) Then $iError = BitOR($iError, 1)
$oDoc = $oDesktop.loadComponentFromURL("private:factory/swriter", "_blank", $iURLFrameCreate, $aArgs)
If Not IsObj($oDoc) Then Return SetError($__LO_STATUS_INIT_ERROR, 4, 0)
Return ($iError > 0) ? (SetError($__LO_STATUS_PROP_SETTING_ERROR, $iError, $oDoc)) : (SetError($__LO_STATUS_SUCCESS, 2, $oDoc))
EndFunc ;==>_LOWriter_DocCreate
; #FUNCTION# ====================================================================================================================
; Name ..........: _LOWriter_DocCreateTextCursor
; Description ...: Create a TextCursor Object for future Textcursor related functional use.
; Syntax ........: _LOWriter_DocCreateTextCursor(ByRef $oDoc[, $bCreateAtEnd = True[, $bCreateAtViewCursor = False]])
; Parameters ....: $oDoc - [in/out] an object. A Document object returned by a previous _LOWriter_DocOpen, _LOWriter_DocConnect, or_LOWriter_DocCreate function.
; $bCreateAtEnd - [optional] a boolean value. Default is True. If true, creates the new cursor at the end of the Document. Else cursor is created at the beginning.
; $bCreateAtViewCursor - [optional] a boolean value. Default is False. If True, create the Text cursor at the document's View Cursor. See Remarks
; Return values .: Success: Object.
; Failure: 0 and sets the @Error and @Extended flags to non-zero.
; --Input Errors--
; @Error 1 @Extended 1 Return 0 = $oDoc not an Object.
; @Error 1 @Extended 2 Return 0 = $bCreateAtEnd not a Boolean.
; @Error 1 @Extended 3 Return 0 = $bCreateAtViewCursor not a Boolean.
; @Error 1 @Extended 4 Return 0 = $bCreateAtEnd and $bCreateAtViewCursor both set to True, set either one to False.
; --Initialization Errors--
; @Error 2 @Extended 1 Return 0 = Failed to create Text Cursor Object.
; --Processing Errors--
; @Error 3 @Extended 1 Return 0 = Failed to retrieve ViewCursor Object.
; @Error 3 @Extended 2 Return 0 = Failed to Retrieve Text Object.
; @Error 3 @Extended 3 Return 0 = Current ViewCursor is in unknown data type or failed detecting what data type.
; --Success--
; @Error 0 @Extended ? Return Object = Success, Cursor object was returned. @Extended can be on of the constants, $LOW_CURDATA_* as defined in LibreOfficeWriter_Constants.au3 indicating the current created cursor is in that type of data.
; Author ........: donnyh13
; Modified ......:
; Remarks .......: The cursor Created by this function in a text document, is used for inserting text, reading text, etc.
; If you set $bCreateAtEnd to False, the new cursor is created at the beginning of the document, True creates the cursor at the very end of the document.
; Setting $bCreateAtViewCursor to True will create a Textcursor at the current ViewCursor position.
; There are two types of cursors in Word documents. The one you see, called the "ViewCursor", and one you do not see, called a "TextCursor". A "ViewCursor" is the blinking cursor you see when you are editing a Word document, there is only one per document. A "TextCursor" on the other hand, is an invisible cursor used for inserting text etc., into a Writer document. You can have multiple "TextCursors" per document.
; Related .......: _LOWriter_CursorMove
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _LOWriter_DocCreateTextCursor(ByRef $oDoc, $bCreateAtEnd = True, $bCreateAtViewCursor = False)
Local $oCOM_ErrorHandler = ObjEvent("AutoIt.Error", __LOWriter_InternalComErrorHandler)
#forceref $oCOM_ErrorHandler
Local $oCursor, $oText, $oViewCursor
Local $iCursorType = 0
If Not IsObj($oDoc) Then Return SetError($__LO_STATUS_INPUT_ERROR, 1, 0)
If Not IsBool($bCreateAtEnd) Then Return SetError($__LO_STATUS_INPUT_ERROR, 2, 0)
If Not IsBool($bCreateAtViewCursor) Then Return SetError($__LO_STATUS_INPUT_ERROR, 3, 0)
If ($bCreateAtEnd = True) And ($bCreateAtViewCursor = True) Then Return SetError($__LO_STATUS_INPUT_ERROR, 4, 0)
If ($bCreateAtViewCursor = True) Then
$oViewCursor = $oDoc.CurrentController.getViewCursor()
If Not IsObj($oViewCursor) Then Return SetError($__LO_STATUS_PROCESSING_ERROR, 1, 0)
$oText = __LOWriter_CursorGetText($oDoc, $oViewCursor)
$iCursorType = @extended
If @error Or Not IsObj($oText) Then Return SetError($__LO_STATUS_PROCESSING_ERROR, 2, 0)
If __LOWriter_IntIsBetween($iCursorType, $LOW_CURDATA_BODY_TEXT, $LOW_CURDATA_HEADER_FOOTER) Then
$oCursor = $oText.createTextCursorByRange($oViewCursor)
Else
Return SetError($__LO_STATUS_PROCESSING_ERROR, 3, 0) ; ViewCursor in unknown data type.
EndIf
Else
$oText = $oDoc.getText
If Not IsObj($oText) Then Return SetError($__LO_STATUS_PROCESSING_ERROR, 2, 0)
$oCursor = $oText.createTextCursor()
$iCursorType = $LOW_CURDATA_BODY_TEXT
If ($bCreateAtEnd = True) Then
$oCursor.gotoEnd(False)
Else
$oCursor.gotoStart(False)
EndIf
EndIf
If Not IsObj($oCursor) Then Return SetError($__LO_STATUS_INIT_ERROR, 1, 0)
Return SetError($__LO_STATUS_SUCCESS, $iCursorType, $oCursor)
EndFunc ;==>_LOWriter_DocCreateTextCursor
; #FUNCTION# ====================================================================================================================
; Name ..........: _LOWriter_DocDescription
; Description ...: Set or Retrieve Document Description properties.
; Syntax ........: _LOWriter_DocDescription(ByRef $oDoc[, $sTitle = Null[, $sSubject = Null[, $asKeywords = Null[, $sComments = Null]]]])
; Parameters ....: $oDoc - [in/out] an object. A Document object returned by a previous _LOWriter_DocOpen, _LOWriter_DocConnect, or_LOWriter_DocCreate function.
; $sTitle - [optional] a string value. Default is Null. Set the Document's "Title" Property. See Remarks.
; $sSubject - [optional] a string value. Default is Null. Set the Document's "Subject" Property.
; $asKeywords - [optional] an array of strings. Default is Null. Set the Document's "Keywords" Property. Input must be a single dimension Array, which will overwrite any keywords previously set. Accepts numbers also. See Remarks.
; $sComments - [optional] a string value. Default is Null. Set the Document's "Comments" Property.
; Return values .: Success: 1 or Array.
; Failure: 0 and sets the @Error and @Extended flags to non-zero.
; --Input Errors--
; @Error 1 @Extended 1 Return 0 = $oDoc not an Object.
; @Error 1 @Extended 2 Return 0 = $sTitle not a String.
; @Error 1 @Extended 3 Return 0 = $sSubject not a String.
; @Error 1 @Extended 4 Return 0 = $asKeywords not an Array.
; @Error 1 @Extended 5 Return 0 = $sComments not a String.
; --Processing Errors--
; @Error 3 @Extended 1 Return 0 = Error retrieving Document Properties Object.
; --Property Setting Errors--
; @Error 4 @Extended ? Return 0 = Some settings were not successfully set. Use BitAND to test @Extended for the following values:
; | 1 = Error setting $sTitle
; | 2 = Error setting $sSubject
; | 4 = Error setting $asKeywords
; | 8 = Error setting $sComments
; --Success--
; @Error 0 @Extended 0 Return 1 = Success. Settings were successfully set.
; @Error 0 @Extended 1 Return Array = Success. All optional parameters were set to Null, returning current settings in a 4 Element Array with values in order of function parameters. "Keywords" value will be an Array, which could be empty if no keywords are presently set.
; Author ........: donnyh13
; Modified ......:
; Remarks .......: "Title" is the Title as found in File>Properties, not the Document's Title as set when saving it.
; "Keywords" error checking only checks to make sure the input array, and the set Array of Keywords is the same size, it does not check that each element is the same.
; Call this function with only the required parameters (or with all other parameters set to Null keyword), to get the current settings.
; Call any optional parameter with Null keyword to skip it.
; Related .......: