-
Notifications
You must be signed in to change notification settings - Fork 65
/
word.body.yml
1207 lines (962 loc) · 44.2 KB
/
word.body.yml
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
### YamlMime:TSType
name: Word.Body
uid: 'word!Word.Body:class'
package: word!
fullName: Word.Body
summary: Represents the body of a document or a section.
remarks: |-
\[ [API set: WordApi 1.1](/javascript/api/requirement-sets/word/word-api-requirement-sets) \]
#### Examples
```TypeScript
// Get the body object and read its font size.
await Word.run(async (context) => {
// Create a proxy object for the document body.
const body = context.document.body;
body.load("font/size");
await context.sync();
console.log("Font size: " + body.font.size);
});
```
isPreview: false
isDeprecated: false
type: class
properties:
- name: contentControls
uid: 'word!Word.Body#contentControls:member'
package: word!
fullName: contentControls
summary: Gets the collection of rich text content control objects in the body.
remarks: '\[ [API set: WordApi 1.1](/javascript/api/requirement-sets/word/word-api-requirement-sets) \]'
isPreview: false
isDeprecated: false
syntax:
content: 'readonly contentControls: Word.ContentControlCollection;'
return:
type: '<xref uid="word!Word.ContentControlCollection:class" />'
- name: context
uid: 'word!Word.Body#context:member'
package: word!
fullName: context
summary: >-
The request context associated with the object. This connects the add-in's process to the Office host
application's process.
remarks: ''
isPreview: false
isDeprecated: false
syntax:
content: 'context: RequestContext;'
return:
type: '<xref uid="word!Word.RequestContext:class" />'
- name: font
uid: 'word!Word.Body#font:member'
package: word!
fullName: font
summary: 'Gets the text format of the body. Use this to get and set font name, size, color and other properties.'
remarks: >-
\[ [API set: WordApi 1.1](/javascript/api/requirement-sets/word/word-api-requirement-sets) \]
#### Examples
```TypeScript
// Link to full sample:
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/50-document/manage-body.yaml
// Gets the style and the font size, font name, and font color properties on the body object.
// Run a batch operation against the Word object model.
await Word.run(async (context) => {
// Create a proxy object for the document body.
const body: Word.Body = context.document.body;
// Queue a command to load font and style information for the document body.
body.load("font/size, font/name, font/color, style");
// Synchronize the document state by executing the queued commands, and return a promise to indicate task completion.
await context.sync();
// Show font-related property values on the body object.
const results =
"Font size: " +
body.font.size +
"; Font name: " +
body.font.name +
"; Font color: " +
body.font.color +
"; Body style: " +
body.style;
console.log(results);
});
```
isPreview: false
isDeprecated: false
syntax:
content: 'readonly font: Word.Font;'
return:
type: '<xref uid="word!Word.Font:class" />'
- name: inlinePictures
uid: 'word!Word.Body#inlinePictures:member'
package: word!
fullName: inlinePictures
summary: Gets the collection of InlinePicture objects in the body. The collection doesn't include floating images.
remarks: >-
\[ [API set: WordApi 1.1](/javascript/api/requirement-sets/word/word-api-requirement-sets) \]
#### Examples
```TypeScript
// Link to full sample:
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/15-images/insert-and-get-pictures.yaml
// Gets the first image in the document.
await Word.run(async (context) => {
const firstPicture: Word.InlinePicture = context.document.body.inlinePictures.getFirst();
firstPicture.load("width, height, imageFormat");
await context.sync();
console.log(`Image dimensions: ${firstPicture.width} x ${firstPicture.height}`, `Image format: ${firstPicture.imageFormat}`);
// Get the image encoded as Base64.
const base64 = firstPicture.getBase64ImageSrc();
await context.sync();
console.log(base64.value);
});
```
isPreview: false
isDeprecated: false
syntax:
content: 'readonly inlinePictures: Word.InlinePictureCollection;'
return:
type: '<xref uid="word!Word.InlinePictureCollection:class" />'
- name: paragraphs
uid: 'word!Word.Body#paragraphs:member'
package: word!
fullName: paragraphs
summary: Gets the collection of paragraph objects in the body.
remarks: >-
\[ [API set: WordApi 1.1](/javascript/api/requirement-sets/word/word-api-requirement-sets) \]
Important: Paragraphs in tables aren't returned for requirement sets 1.1 and 1.2. From requirement set 1.3,
paragraphs in tables are also returned.
#### Examples
```TypeScript
// Link to full sample:
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/25-paragraph/get-word-count.yaml
// Counts how many times each term appears in the document.
await Word.run(async (context) => {
const paragraphs: Word.ParagraphCollection = context.document.body.paragraphs;
paragraphs.load("text");
await context.sync();
// Split up the document text using existing spaces as the delimiter.
let text = [];
paragraphs.items.forEach((item) => {
let paragraph = item.text.trim();
if (paragraph) {
paragraph.split(" ").forEach((term) => {
let currentTerm = term.trim();
if (currentTerm) {
text.push(currentTerm);
}
});
}
});
// Determine the list of unique terms.
let makeTextDistinct = new Set(text);
let distinctText = Array.from(makeTextDistinct);
let allSearchResults = [];
for (let i = 0; i < distinctText.length; i++) {
let results = context.document.body.search(distinctText[i], { matchCase: true, matchWholeWord: true });
results.load("text");
// Map each search term with its results.
let correlatedResults = {
searchTerm: distinctText[i],
hits: results
};
allSearchResults.push(correlatedResults);
}
await context.sync();
// Display the count for each search term.
allSearchResults.forEach((result) => {
let length = result.hits.items.length;
console.log("Search term: " + result.searchTerm + " => Count: " + length);
});
});
```
isPreview: false
isDeprecated: false
syntax:
content: 'readonly paragraphs: Word.ParagraphCollection;'
return:
type: '<xref uid="word!Word.ParagraphCollection:class" />'
- name: parentContentControl
uid: 'word!Word.Body#parentContentControl:member'
package: word!
fullName: parentContentControl
summary: >-
Gets the content control that contains the body. Throws an `ItemNotFound` error if there isn't a parent content
control.
remarks: '\[ [API set: WordApi 1.1](/javascript/api/requirement-sets/word/word-api-requirement-sets) \]'
isPreview: false
isDeprecated: false
syntax:
content: 'readonly parentContentControl: Word.ContentControl;'
return:
type: '<xref uid="word!Word.ContentControl:class" />'
- name: style
uid: 'word!Word.Body#style:member'
package: word!
fullName: style
summary: >-
Specifies the style name for the body. Use this property for custom styles and localized style names. To use the
built-in styles that are portable between locales, see the "styleBuiltIn" property.
remarks: '\[ [API set: WordApi 1.1](/javascript/api/requirement-sets/word/word-api-requirement-sets) \]'
isPreview: false
isDeprecated: false
syntax:
content: 'style: string;'
return:
type: string
- name: text
uid: 'word!Word.Body#text:member'
package: word!
fullName: text
summary: Gets the text of the body. Use the insertText method to insert text.
remarks: >-
\[ [API set: WordApi 1.1](/javascript/api/requirement-sets/word/word-api-requirement-sets) \]
#### Examples
```TypeScript
// Link to full sample:
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/50-document/manage-body.yaml
// Gets the text content of the body.
// Run a batch operation against the Word object model.
await Word.run(async (context) => {
// Create a proxy object for the document body.
const body: Word.Body = context.document.body;
// Queue a command to load the text in document body.
body.load("text");
// Synchronize the document state by executing the queued commands, and return a promise to indicate task completion.
await context.sync();
console.log("Body contents (text): " + body.text);
});
```
isPreview: false
isDeprecated: false
syntax:
content: 'readonly text: string;'
return:
type: string
methods:
- name: clear()
uid: 'word!Word.Body#clear:member(1)'
package: word!
fullName: clear()
summary: Clears the contents of the body object. The user can perform the undo operation on the cleared content.
remarks: >-
\[ [API set: WordApi 1.1](/javascript/api/requirement-sets/word/word-api-requirement-sets) \]
#### Examples
```TypeScript
// Link to full sample:
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/50-document/manage-body.yaml
// Clears out the content from the document body.
// Run a batch operation against the Word object model.
await Word.run(async (context) => {
// Create a proxy object for the document body.
const body: Word.Body = context.document.body;
// Queue a command to clear the contents of the body.
body.clear();
console.log("Cleared the body contents.");
});
// The Silly stories add-in sample shows how the clear method can be used to clear the contents of a document.
// https://aka.ms/sillystorywordaddin
```
isPreview: false
isDeprecated: false
syntax:
content: 'clear(): void;'
return:
type: void
description: ''
- name: getHtml()
uid: 'word!Word.Body#getHtml:member(1)'
package: word!
fullName: getHtml()
summary: >-
Gets an HTML representation of the body object. When rendered in a web page or HTML viewer, the formatting will be
a close, but not exact, match for of the formatting of the document. This method doesn't return the exact same
HTML for the same document on different platforms (Windows, Mac, Word on the web, etc.). If you need exact
fidelity, or consistency across platforms, use `Body.getOoxml()` and convert the returned XML to HTML.
remarks: >-
\[ [API set: WordApi 1.1](/javascript/api/requirement-sets/word/word-api-requirement-sets) \]
#### Examples
```TypeScript
// Link to full sample:
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/50-document/manage-body.yaml
// Gets the HTML that represents the content of the body.
// Run a batch operation against the Word object model.
await Word.run(async (context) => {
// Create a proxy object for the document body.
const body: Word.Body = context.document.body;
// Queue a command to get the HTML contents of the body.
const bodyHTML = body.getHtml();
// Synchronize the document state by executing the queued commands, and return a promise to indicate task completion.
await context.sync();
console.log("Body contents (HTML): " + bodyHTML.value);
});
```
isPreview: false
isDeprecated: false
syntax:
content: 'getHtml(): OfficeExtension.ClientResult<string>;'
return:
type: '<xref uid="office!OfficeExtension.ClientResult:class" /><string>'
description: ''
- name: getOoxml()
uid: 'word!Word.Body#getOoxml:member(1)'
package: word!
fullName: getOoxml()
summary: Gets the OOXML (Office Open XML) representation of the body object.
remarks: >-
\[ [API set: WordApi 1.1](/javascript/api/requirement-sets/word/word-api-requirement-sets) \]
#### Examples
```TypeScript
// Link to full sample:
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/50-document/manage-body.yaml
// Gets the OOXML that represents the content of the body.
// Run a batch operation against the Word object model.
await Word.run(async (context) => {
// Create a proxy object for the document body.
const body: Word.Body = context.document.body;
// Queue a command to get the OOXML contents of the body.
const bodyOOXML = body.getOoxml();
// Synchronize the document state by executing the queued commands, and return a promise to indicate task completion.
await context.sync();
console.log("Body contents (OOXML): " + bodyOOXML.value);
});
```
isPreview: false
isDeprecated: false
syntax:
content: 'getOoxml(): OfficeExtension.ClientResult<string>;'
return:
type: '<xref uid="office!OfficeExtension.ClientResult:class" /><string>'
description: ''
- name: 'insertBreak(breakType, insertLocation)'
uid: 'word!Word.Body#insertBreak:member(1)'
package: word!
fullName: 'insertBreak(breakType, insertLocation)'
summary: Inserts a break at the specified location in the main document.
remarks: >-
\[ [API set: WordApi 1.1](/javascript/api/requirement-sets/word/word-api-requirement-sets) \]
#### Examples
```TypeScript
// Link to full sample:
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/50-document/manage-body.yaml
// Inserts a page break at the beginning of the document.
// Run a batch operation against the Word object model.
await Word.run(async (context) => {
// Create a proxy object for the document body.
const body: Word.Body = context.document.body;
// Queue a command to insert a page break at the start of the document body.
body.insertBreak(Word.BreakType.page, Word.InsertLocation.start);
// Synchronize the document state by executing the queued commands, and return a promise to indicate task completion.
await context.sync();
console.log("Added a page break at the start of the document body.");
});
```
isPreview: false
isDeprecated: false
syntax:
content: >-
insertBreak(breakType: Word.BreakType | "Page" | "Next" | "SectionNext" | "SectionContinuous" | "SectionEven" |
"SectionOdd" | "Line", insertLocation: Word.InsertLocation.start | Word.InsertLocation.end | "Start" | "End"):
void;
parameters:
- id: breakType
description: Required. The break type to add to the body.
type: >-
<xref uid="word!Word.BreakType:enum" /> | "Page" | "Next" | "SectionNext" | "SectionContinuous" |
"SectionEven" | "SectionOdd" | "Line"
- id: insertLocation
description: Required. The value must be 'Start' or 'End'.
type: >-
<xref uid="word!Word.InsertLocation.start:member" /> | <xref uid="word!Word.InsertLocation.end:member" /> |
"Start" | "End"
return:
type: void
description: ''
- name: insertContentControl(contentControlType)
uid: 'word!Word.Body#insertContentControl:member(1)'
package: word!
fullName: insertContentControl(contentControlType)
summary: Wraps the Body object with a content control.
remarks: >-
\[ [API set: WordApi 1.1](/javascript/api/requirement-sets/word/word-api-requirement-sets) \]
Note: The `contentControlType` parameter was introduced in WordApi 1.5. `PlainText` support was added in WordApi
1.5. `CheckBox` support was added in WordApi 1.7.
#### Examples
```TypeScript
// Link to full sample:
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/50-document/manage-body.yaml
// Creates a content control using the document body.
// Run a batch operation against the Word object model.
await Word.run(async (context) => {
// Create a proxy object for the document body.
const body: Word.Body = context.document.body;
// Queue a command to wrap the body in a content control.
body.insertContentControl();
// Synchronize the document state by executing the queued commands, and return a promise to indicate task completion.
await context.sync();
console.log("Wrapped the body in a content control.");
});
```
isPreview: false
isDeprecated: false
syntax:
content: >-
insertContentControl(contentControlType?: Word.ContentControlType.richText | Word.ContentControlType.plainText |
Word.ContentControlType.checkBox | "RichText" | "PlainText" | "CheckBox"): Word.ContentControl;
parameters:
- id: contentControlType
description: >-
Optional. Content control type to insert. Must be 'RichText', 'PlainText', or 'CheckBox'. The default is
'RichText'.
type: >-
<xref uid="word!Word.ContentControlType.richText:member" /> | <xref
uid="word!Word.ContentControlType.plainText:member" /> | <xref
uid="word!Word.ContentControlType.checkBox:member" /> | "RichText" | "PlainText" | "CheckBox"
return:
type: '<xref uid="word!Word.ContentControl:class" />'
description: ''
- name: 'insertFileFromBase64(base64File, insertLocation)'
uid: 'word!Word.Body#insertFileFromBase64:member(1)'
package: word!
fullName: 'insertFileFromBase64(base64File, insertLocation)'
summary: Inserts a document into the body at the specified location.
remarks: >-
\[ [API set: WordApi 1.1](/javascript/api/requirement-sets/word/word-api-requirement-sets) \]
Note: Insertion isn't supported if the document being inserted contains an ActiveX control (likely in a form
field). Consider replacing such a form field with a content control or other option appropriate for your scenario.
#### Examples
```TypeScript
// Link to full sample:
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/50-document/manage-body.yaml
// Inserts the body from the external document at the beginning of this document.
// Run a batch operation against the Word object model.
await Word.run(async (context) => {
// Create a proxy object for the document body.
const body: Word.Body = context.document.body;
// Queue a command to insert the Base64-encoded string representation of the body of the selected .docx file at the beginning of the current document.
body.insertFileFromBase64(externalDocument, Word.InsertLocation.start);
// Synchronize the document state by executing the queued commands, and return a promise to indicate task completion.
await context.sync();
console.log("Added Base64-encoded text to the beginning of the document body.");
});
```
isPreview: false
isDeprecated: false
syntax:
content: >-
insertFileFromBase64(base64File: string, insertLocation: Word.InsertLocation.replace | Word.InsertLocation.start
| Word.InsertLocation.end | "Replace" | "Start" | "End"): Word.Range;
parameters:
- id: base64File
description: Required. The Base64-encoded content of a .docx file.
type: string
- id: insertLocation
description: 'Required. The value must be ''Replace'', ''Start'', or ''End''.'
type: >-
<xref uid="word!Word.InsertLocation.replace:member" /> | <xref uid="word!Word.InsertLocation.start:member"
/> | <xref uid="word!Word.InsertLocation.end:member" /> | "Replace" | "Start" | "End"
return:
type: '<xref uid="word!Word.Range:class" />'
description: ''
- name: 'insertHtml(html, insertLocation)'
uid: 'word!Word.Body#insertHtml:member(1)'
package: word!
fullName: 'insertHtml(html, insertLocation)'
summary: Inserts HTML at the specified location.
remarks: >-
\[ [API set: WordApi 1.1](/javascript/api/requirement-sets/word/word-api-requirement-sets) \]
#### Examples
```TypeScript
// Link to full sample:
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/50-document/manage-body.yaml
// Inserts the HTML at the beginning of this document.
// Run a batch operation against the Word object model.
await Word.run(async (context) => {
// Create a proxy object for the document body.
const body: Word.Body = context.document.body;
// Queue a command to insert HTML at the beginning of the document.
body.insertHtml("<strong>This is text inserted with body.insertHtml()</strong>", Word.InsertLocation.start);
// Synchronize the document state by executing the queued commands, and return a promise to indicate task completion.
await context.sync();
console.log("HTML added to the beginning of the document body.");
});
```
isPreview: false
isDeprecated: false
syntax:
content: >-
insertHtml(html: string, insertLocation: Word.InsertLocation.replace | Word.InsertLocation.start |
Word.InsertLocation.end | "Replace" | "Start" | "End"): Word.Range;
parameters:
- id: html
description: Required. The HTML to be inserted in the document.
type: string
- id: insertLocation
description: 'Required. The value must be ''Replace'', ''Start'', or ''End''.'
type: >-
<xref uid="word!Word.InsertLocation.replace:member" /> | <xref uid="word!Word.InsertLocation.start:member"
/> | <xref uid="word!Word.InsertLocation.end:member" /> | "Replace" | "Start" | "End"
return:
type: '<xref uid="word!Word.Range:class" />'
description: ''
- name: 'insertInlinePictureFromBase64(base64EncodedImage, insertLocation)'
uid: 'word!Word.Body#insertInlinePictureFromBase64:member(1)'
package: word!
fullName: 'insertInlinePictureFromBase64(base64EncodedImage, insertLocation)'
summary: Inserts a picture into the body at the specified location.
remarks: >-
\[ [API set: WordApi 1.2](/javascript/api/requirement-sets/word/word-api-requirement-sets) \]
#### Examples
```TypeScript
// Link to full sample:
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/50-document/manage-body.yaml
// Inserts an image inline at the beginning of this document.
// Run a batch operation against the Word object model.
await Word.run(async (context) => {
// Create a proxy object for the document body.
const body: Word.Body = context.document.body;
// Base64-encoded image to insert inline.
const base64EncodedImg =
"iVBORw0KGgoAAAANSUhEUgAAAB4AAAANCAIAAAAxEEnAAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAACFSURBVDhPtY1BEoQwDMP6/0+XgIMTBAeYoTqso9Rkx1zG+tNj1H94jgGzeNSjteO5vtQQuG2seO0av8LzGbe3anzRoJ4ybm/VeKEerAEbAUpW4aWQCmrGFWykRzGBCnYy2ha3oAIq2MloW9yCCqhgJ6NtcQsqoIKdjLbFLaiACnYyf2fODbrjZcXfr2F4AAAAAElFTkSuQmCC";
// Queue a command to insert a Base64-encoded image at the beginning of the current document.
body.insertInlinePictureFromBase64(base64EncodedImg, Word.InsertLocation.start);
// Synchronize the document state by executing the queued commands, and return a promise to indicate task completion.
await context.sync();
console.log("Added a Base64-encoded image to the beginning of the document body.");
});
```
isPreview: false
isDeprecated: false
syntax:
content: >-
insertInlinePictureFromBase64(base64EncodedImage: string, insertLocation: Word.InsertLocation.start |
Word.InsertLocation.end | "Start" | "End"): Word.InlinePicture;
parameters:
- id: base64EncodedImage
description: Required. The Base64-encoded image to be inserted in the body.
type: string
- id: insertLocation
description: Required. The value must be 'Start' or 'End'.
type: >-
<xref uid="word!Word.InsertLocation.start:member" /> | <xref uid="word!Word.InsertLocation.end:member" /> |
"Start" | "End"
return:
type: '<xref uid="word!Word.InlinePicture:class" />'
description: ''
- name: 'insertOoxml(ooxml, insertLocation)'
uid: 'word!Word.Body#insertOoxml:member(1)'
package: word!
fullName: 'insertOoxml(ooxml, insertLocation)'
summary: Inserts OOXML at the specified location.
remarks: >-
\[ [API set: WordApi 1.1](/javascript/api/requirement-sets/word/word-api-requirement-sets) \]
#### Examples
```TypeScript
// Link to full sample:
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/50-document/manage-body.yaml
// Inserts OOXML at the beginning of this document.
// Run a batch operation against the Word object model.
await Word.run(async (context) => {
// Create a proxy object for the document body.
const body: Word.Body = context.document.body;
// Queue a command to insert OOXML at the beginning of the body.
body.insertOoxml(
"<pkg:package xmlns:pkg='http://schemas.microsoft.com/office/2006/xmlPackage'><pkg:part pkg:name='/_rels/.rels' pkg:contentType='application/vnd.openxmlformats-package.relationships+xml' pkg:padding='512'><pkg:xmlData><Relationships xmlns='http://schemas.openxmlformats.org/package/2006/relationships'><Relationship Id='rId1' Type='http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument' Target='word/document.xml'/></Relationships></pkg:xmlData></pkg:part><pkg:part pkg:name='/word/document.xml' pkg:contentType='application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml'><pkg:xmlData><w:document xmlns:w='http://schemas.openxmlformats.org/wordprocessingml/2006/main' ><w:body><w:p><w:pPr><w:spacing w:before='360' w:after='0' w:line='480' w:lineRule='auto'/><w:rPr><w:color w:val='70AD47' w:themeColor='accent6'/><w:sz w:val='28'/></w:rPr></w:pPr><w:r><w:rPr><w:color w:val='70AD47' w:themeColor='accent6'/><w:sz w:val='28'/></w:rPr><w:t>This text has formatting directly applied to achieve its font size, color, line spacing, and paragraph spacing.</w:t></w:r></w:p></w:body></w:document></pkg:xmlData></pkg:part></pkg:package>",
Word.InsertLocation.start
);
// Synchronize the document state by executing the queued commands, and return a promise to indicate task completion.
await context.sync();
console.log("Added OOXML to the beginning of the document body.");
});
// Read "Understand when and how to use Office Open XML in your Word add-in" for guidance on working with OOXML.
// https://learn.microsoft.com/office/dev/add-ins/word/create-better-add-ins-for-word-with-office-open-xml
// The Word-Add-in-DocumentAssembly sample shows how you can use this API to assemble a document.
// https://github.com/OfficeDev/Word-Add-in-DocumentAssembly
```
isPreview: false
isDeprecated: false
syntax:
content: >-
insertOoxml(ooxml: string, insertLocation: Word.InsertLocation.replace | Word.InsertLocation.start |
Word.InsertLocation.end | "Replace" | "Start" | "End"): Word.Range;
parameters:
- id: ooxml
description: Required. The OOXML to be inserted.
type: string
- id: insertLocation
description: 'Required. The value must be ''Replace'', ''Start'', or ''End''.'
type: >-
<xref uid="word!Word.InsertLocation.replace:member" /> | <xref uid="word!Word.InsertLocation.start:member"
/> | <xref uid="word!Word.InsertLocation.end:member" /> | "Replace" | "Start" | "End"
return:
type: '<xref uid="word!Word.Range:class" />'
description: ''
- name: 'insertParagraph(paragraphText, insertLocation)'
uid: 'word!Word.Body#insertParagraph:member(1)'
package: word!
fullName: 'insertParagraph(paragraphText, insertLocation)'
summary: Inserts a paragraph at the specified location.
remarks: >-
\[ [API set: WordApi 1.1](/javascript/api/requirement-sets/word/word-api-requirement-sets) \]
#### Examples
```TypeScript
// Link to full sample:
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/25-paragraph/insert-formatted-text.yaml
await Word.run(async (context) => {
// Second sentence, let's insert it as a paragraph after the previously inserted one.
const secondSentence: Word.Paragraph = context.document.body.insertParagraph(
"This is the first text with a custom style.",
"End"
);
secondSentence.font.set({
bold: false,
italic: true,
name: "Berlin Sans FB",
color: "blue",
size: 30
});
await context.sync();
});
```
isPreview: false
isDeprecated: false
syntax:
content: >-
insertParagraph(paragraphText: string, insertLocation: Word.InsertLocation.start | Word.InsertLocation.end |
"Start" | "End"): Word.Paragraph;
parameters:
- id: paragraphText
description: Required. The paragraph text to be inserted.
type: string
- id: insertLocation
description: Required. The value must be 'Start' or 'End'.
type: >-
<xref uid="word!Word.InsertLocation.start:member" /> | <xref uid="word!Word.InsertLocation.end:member" /> |
"Start" | "End"
return:
type: '<xref uid="word!Word.Paragraph:class" />'
description: ''
- name: 'insertText(text, insertLocation)'
uid: 'word!Word.Body#insertText:member(1)'
package: word!
fullName: 'insertText(text, insertLocation)'
summary: Inserts text into the body at the specified location.
remarks: >-
\[ [API set: WordApi 1.1](/javascript/api/requirement-sets/word/word-api-requirement-sets) \]
#### Examples
```TypeScript
// Link to full sample:
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/50-document/manage-body.yaml
// Inserts text at the beginning of this document.
// Run a batch operation against the Word object model.
await Word.run(async (context) => {
// Create a proxy object for the document body.
const body: Word.Body = context.document.body;
// Queue a command to insert text at the beginning of the current document.
body.insertText('This is text inserted with body.insertText()', Word.InsertLocation.start);
// Synchronize the document state by executing the queued commands, and return a promise to indicate task completion.
await context.sync();
console.log("Text added to the beginning of the document body.");
});
```
isPreview: false
isDeprecated: false
syntax:
content: >-
insertText(text: string, insertLocation: Word.InsertLocation.replace | Word.InsertLocation.start |
Word.InsertLocation.end | "Replace" | "Start" | "End"): Word.Range;
parameters:
- id: text
description: Required. Text to be inserted.
type: string
- id: insertLocation
description: 'Required. The value must be ''Replace'', ''Start'', or ''End''.'
type: >-
<xref uid="word!Word.InsertLocation.replace:member" /> | <xref uid="word!Word.InsertLocation.start:member"
/> | <xref uid="word!Word.InsertLocation.end:member" /> | "Replace" | "Start" | "End"
return:
type: '<xref uid="word!Word.Range:class" />'
description: ''
- name: load(options)
uid: 'word!Word.Body#load:member(1)'
package: word!
fullName: load(options)
summary: >-
Queues up a command to load the specified properties of the object. You must call `context.sync()` before reading
the properties.
remarks: ''
isPreview: false
isDeprecated: false
syntax:
content: 'load(options?: Word.Interfaces.BodyLoadOptions): Word.Body;'
parameters:
- id: options
description: Provides options for which properties of the object to load.
type: '<xref uid="word!Word.Interfaces.BodyLoadOptions:interface" />'
return:
type: '<xref uid="word!Word.Body:class" />'
description: ''
- name: load(propertyNames)
uid: 'word!Word.Body#load:member(2)'
package: word!
fullName: load(propertyNames)
summary: >-
Queues up a command to load the specified properties of the object. You must call `context.sync()` before reading
the properties.
remarks: ''
isPreview: false
isDeprecated: false
syntax:
content: 'load(propertyNames?: string | string[]): Word.Body;'
parameters:
- id: propertyNames
description: A comma-delimited string or an array of strings that specify the properties to load.
type: 'string | string[]'
return:
type: '<xref uid="word!Word.Body:class" />'
description: ''
- name: load(propertyNamesAndPaths)
uid: 'word!Word.Body#load:member(3)'
package: word!
fullName: load(propertyNamesAndPaths)
summary: >-
Queues up a command to load the specified properties of the object. You must call `context.sync()` before reading
the properties.
remarks: ''
isPreview: false
isDeprecated: false
syntax:
content: |-
load(propertyNamesAndPaths?: {
select?: string;
expand?: string;
}): Word.Body;
parameters:
- id: propertyNamesAndPaths
description: >-
`propertyNamesAndPaths.select` is a comma-delimited string that specifies the properties to load, and
`propertyNamesAndPaths.expand` is a comma-delimited string that specifies the navigation properties to load.
type: |-
{
select?: string;
expand?: string;
}
return:
type: '<xref uid="word!Word.Body:class" />'
description: ''
- name: 'search(searchText, searchOptions)'
uid: 'word!Word.Body#search:member(1)'
package: word!
fullName: 'search(searchText, searchOptions)'
summary: >-
Performs a search with the specified SearchOptions on the scope of the body object. The search results are a
collection of range objects.
remarks: >-
\[ [API set: WordApi 1.1](/javascript/api/requirement-sets/word/word-api-requirement-sets) \]
#### Examples
```TypeScript
// Link to full sample:
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/25-paragraph/search.yaml
// Does a basic text search and highlights matches in the document.
await Word.run(async (context) => {
const results : Word.RangeCollection = context.document.body.search("extend");
results.load("length");
await context.sync();
// Let's traverse the search results and highlight matches.
for (let i = 0; i < results.items.length; i++) {
results.items[i].font.highlightColor = "yellow";
}
await context.sync();
});
...
// Does a wildcard search and highlights matches in the document.
await Word.run(async (context) => {