Skip to content

Instantly share code, notes, and snippets.

@rkpatel33
Created May 10, 2017 06:04
Show Gist options
  • Save rkpatel33/9232aae9d22cbdc3dd98dc8d54fa898e to your computer and use it in GitHub Desktop.
Save rkpatel33/9232aae9d22cbdc3dd98dc8d54fa898e to your computer and use it in GitHub Desktop.
Shows how to set indentation, space between paragraphs and other paragraph properties. - Shared with Script Lab
name: Paragraph properties
description: 'Shows how to set indentation, space between paragraphs and other paragraph properties.'
host: WORD
api_set: {}
script:
content: |-
$("#indent").click(indent);
$("#spacing").click(spacing);
$("#space-after").click(spaceAfter);
$("#align").click(align);
$("#setup").click(setup);
function indent() {
Word.run(function (context) {
// Indents the first paragraph
context.document.body.paragraphs.
getFirst().leftIndent = 75; //units = points
return context.sync();
})
.catch(OfficeHelpers.Utilities.log);
}
function spacing() {
Word.run(function (context) {
// Adjusts line spacing
context.document.body.paragraphs
.getFirst().lineSpacing = 20;
return context.sync();
})
.catch(OfficeHelpers.Utilities.log);
}
function spaceAfter() {
Word.run(function (context) {
//Adjust space between paragraphs
context.document.body.paragraphs
.getFirst().spaceAfter = 20;
return context.sync();
})
.catch(OfficeHelpers.Utilities.log);
}
function align() {
Word.run(function (context) {
// Centers last paragraph alignment
context.document.body.paragraphs
.getLast().alignment = "centered";
return context.sync();
})
.catch(OfficeHelpers.Utilities.log);
}
function setup() {
Word.run(function (context) {
// lets insert a couple of paragraphs to illustrate the point..
context.document.body.clear();
context.document.body.insertParagraph("Video provides a powerful way to help you prove your point. When you click Online Video, you can paste in the embed code for the video you want to add. You can also type a keyword to search online for the video that best fits your document.", "start");
context.document.body.paragraphs.getLast().insertText("To make your document look professionally produced, Word provides header, footer, cover page, and text box designs that complement each other. For example, you can add a matching cover page, header, and sidebar. Click Insert and then choose the elements you want from the different galleries.", "replace");
return context.sync()
.then(function () {
context.document.body.paragraphs.getFirst().alignment = "left";
context.document.body.paragraphs.getLast().alignment = "left";
return context.sync();
})
})
.catch(OfficeHelpers.Utilities.log);
}
language: typescript
template:
content: |-
<h2 class="ms-font-m">This sample demonstrates paragraph property usage.</h2>
<div id="setup-container">
<p class="ms-font-m">Click "setup" to reset the sample.</p>
<button id="setup" class="ms-Button">
<span class="ms-Button-label">Setup</span>
</button>
</div>
<div id="samples-container">
<p class="ms-font-m">Sample snippets to try. <b>Click buttons top-down.</b></p>
<button id="indent" class="ms-Button">
<span class="ms-Button-label">Indent first paragraph</span>
</button>
<button id="spacing" class="ms-Button">
<span class="ms-Button-label">Adjust first paragraph's line spacing</span>
</button>
<button id="space-after" class="ms-Button">
<span class="ms-Button-label">Adjust space between paragraphs</span>
</button>
<button id="align" class="ms-Button">
<span class="ms-Button-label">Align last paragraph to center.</span>
</button>
</div>
language: html
style:
content: |4
body {
margin: 0;
padding: 10px;
}
/* Button customization, including overwriting some Fabric defaults */
.ms-Button, .ms-Button:focus {
background: #217346;
border: #217346;
}
.ms-Button > .ms-Button-label,
.ms-Button:focus > .ms-Button-label,
.ms-Button:hover > .ms-Button-label {
color: white;
}
.ms-Button:hover, .ms-Button:active {
background: #164b2e;
}
.ms-Button.is-disabled, .ms-Button:disabled {
background-color: #f4f4f4;
border-color: #f4f4f4;
}
.ms-Button.is-disabled .ms-Button-label,
.ms-Button:disabled .ms-Button-label {
color: #a6a6a6;
}
#setup.ms-Button, #setup.ms-Button:focus {
background: darkred;
border: darkred;
}
#setup.ms-Button:hover, #setup.ms-Button:active {
background: red;
}
#samples-container {
margin-top: 20px;
}
#samples-container .ms-Button {
display: block;
margin-bottom: 5px;
}
#samples-container .ms-Button, #setup-container .ms-Button {
margin-left: 20px;
min-width: 80px;
}
language: css
libraries: |-
// Office.js
https://appsforoffice.microsoft.com/lib/1/hosted/office.js
// NPM libraries
jquery@3.1.1
office-ui-fabric-js@1.4.0/dist/js/fabric.min.js
office-ui-fabric-js@1.4.0/dist/css/fabric.min.css
office-ui-fabric-js@1.4.0/dist/css/fabric.components.min.css
@microsoft/office-js-helpers@0.7.1/dist/office.helpers.min.js
core-js@2.4.1/client/core.min.js
// IntelliSense: Use dt~library_name for DefinitelyTyped or URLs to d.ts files
@types/office-js
@types/jquery
@types/core-js
@microsoft/office-js-helpers@0.7.1/dist/office.helpers.d.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment