Files
Gainsight/Scripts/GoogleScripts/Courtney_Confluence/Adv.js
2023-05-12 16:45:50 -04:00

40 lines
1.5 KiB
JavaScript

/**
* Test harness to demonstrate getting named styles from the Advanced Docs Service
*/
function getStylesTestHarness() {
// Get the current document
var doc = DocumentApp.getActiveDocument()
// https://developers.google.com/apps-script/reference/document/paragraph-heading
var namedStyleType = DocumentApp.ParagraphHeading.HEADING2;
getStyles_(doc.getId(), namedStyleType);
}
/**
* Get named styles from the Advanced Docs Service
* Assumes that heading text is unique, which it should be with date stamp
* @param {string} documentId
* @param {string} styleType https://developers.google.com/apps-script/reference/document/paragraph-heading
* @private
*/
function getStyles_(documentId, styleType) {
var namedStyleArr;
var namedStyleObj;
var appsScriptNamedStyle;
// Get the corresponding document from the Advanced Docs Service
var document = Docs.Documents.get(documentId);
var namedStyleArr = document.namedStyles.styles;
for (var i=namedStyleArr.length;i--;) {
namedStyleObj = namedStyleArr[i];
// convert from Advanced Docs Service style names which have separating underscores
appsScriptNamedStyle = namedStyleObj.namedStyleType.split('_').join('');
if (appsScriptNamedStyle == styleType) {
console.log('namedStyleType '+namedStyleObj.namedStyleType);
console.log('textStyle '+JSON.stringify(namedStyleObj.textStyle));
console.log('paragraphStyle '+JSON.stringify(namedStyleObj.paragraphStyle));
}
}
}