How do I get a Google Apps Script Document Outline from the API?
up vote
0
down vote
favorite
I am able to get the contents of a documents outline by searching all the paragraphs and seeing the heading each paragraph is using. This works but isn't ideal. If I manually remove an item from the outline, it doesn't change the heading of that item to normal. Therefore when I run my code again it'll detect the removed item as still being part of the outline since it's heading matches one used for the outline.
var searchHeading = DocumentApp.ParagraphHeading.HEADING4;
var paragraphs = getParagraphs();
return paragraphs.filter(function(paragraph) {
return (paragraph.header == searchHeading);
});
function getParagraphs() {
var paragraphs = DocumentApp.getActiveDocument().getBody().getParagraphs();
return paragraphs.map(function(p, index) {
return {
paragraph: p.getText(),
header: p.getHeading(),
id: index
};
});
}
Is there anyway to get the contents of the outline without parsing each paragraph and filtering those whose header matches a specific heading, ideally from an API call?
EDIT: Added getParagraphs()
google-apps-script
add a comment |
up vote
0
down vote
favorite
I am able to get the contents of a documents outline by searching all the paragraphs and seeing the heading each paragraph is using. This works but isn't ideal. If I manually remove an item from the outline, it doesn't change the heading of that item to normal. Therefore when I run my code again it'll detect the removed item as still being part of the outline since it's heading matches one used for the outline.
var searchHeading = DocumentApp.ParagraphHeading.HEADING4;
var paragraphs = getParagraphs();
return paragraphs.filter(function(paragraph) {
return (paragraph.header == searchHeading);
});
function getParagraphs() {
var paragraphs = DocumentApp.getActiveDocument().getBody().getParagraphs();
return paragraphs.map(function(p, index) {
return {
paragraph: p.getText(),
header: p.getHeading(),
id: index
};
});
}
Is there anyway to get the contents of the outline without parsing each paragraph and filtering those whose header matches a specific heading, ideally from an API call?
EDIT: Added getParagraphs()
google-apps-script
I'm sorry for my poor English skill. In order to understand correctly the result you want and the current result, can I ask you about your question? Can you provide about the detail ofgetParagraphs()
and the current result? From your current result, can you also provide the result you want?
– Tanaike
Nov 9 at 0:20
No problem, I updated the question with the implementation for getParagraphs(). It returns a list of custom paragraph objects. There are the same as google paragrahps but also have an id for their order. This function works fine, but ultimately what I want is an API call to get the contents of a documents outline.
– Alexsh
Nov 12 at 16:38
Thank you for replying it.
– Tanaike
Nov 12 at 23:15
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am able to get the contents of a documents outline by searching all the paragraphs and seeing the heading each paragraph is using. This works but isn't ideal. If I manually remove an item from the outline, it doesn't change the heading of that item to normal. Therefore when I run my code again it'll detect the removed item as still being part of the outline since it's heading matches one used for the outline.
var searchHeading = DocumentApp.ParagraphHeading.HEADING4;
var paragraphs = getParagraphs();
return paragraphs.filter(function(paragraph) {
return (paragraph.header == searchHeading);
});
function getParagraphs() {
var paragraphs = DocumentApp.getActiveDocument().getBody().getParagraphs();
return paragraphs.map(function(p, index) {
return {
paragraph: p.getText(),
header: p.getHeading(),
id: index
};
});
}
Is there anyway to get the contents of the outline without parsing each paragraph and filtering those whose header matches a specific heading, ideally from an API call?
EDIT: Added getParagraphs()
google-apps-script
I am able to get the contents of a documents outline by searching all the paragraphs and seeing the heading each paragraph is using. This works but isn't ideal. If I manually remove an item from the outline, it doesn't change the heading of that item to normal. Therefore when I run my code again it'll detect the removed item as still being part of the outline since it's heading matches one used for the outline.
var searchHeading = DocumentApp.ParagraphHeading.HEADING4;
var paragraphs = getParagraphs();
return paragraphs.filter(function(paragraph) {
return (paragraph.header == searchHeading);
});
function getParagraphs() {
var paragraphs = DocumentApp.getActiveDocument().getBody().getParagraphs();
return paragraphs.map(function(p, index) {
return {
paragraph: p.getText(),
header: p.getHeading(),
id: index
};
});
}
Is there anyway to get the contents of the outline without parsing each paragraph and filtering those whose header matches a specific heading, ideally from an API call?
EDIT: Added getParagraphs()
google-apps-script
google-apps-script
edited Nov 12 at 16:36
asked Nov 8 at 16:59
Alexsh
135
135
I'm sorry for my poor English skill. In order to understand correctly the result you want and the current result, can I ask you about your question? Can you provide about the detail ofgetParagraphs()
and the current result? From your current result, can you also provide the result you want?
– Tanaike
Nov 9 at 0:20
No problem, I updated the question with the implementation for getParagraphs(). It returns a list of custom paragraph objects. There are the same as google paragrahps but also have an id for their order. This function works fine, but ultimately what I want is an API call to get the contents of a documents outline.
– Alexsh
Nov 12 at 16:38
Thank you for replying it.
– Tanaike
Nov 12 at 23:15
add a comment |
I'm sorry for my poor English skill. In order to understand correctly the result you want and the current result, can I ask you about your question? Can you provide about the detail ofgetParagraphs()
and the current result? From your current result, can you also provide the result you want?
– Tanaike
Nov 9 at 0:20
No problem, I updated the question with the implementation for getParagraphs(). It returns a list of custom paragraph objects. There are the same as google paragrahps but also have an id for their order. This function works fine, but ultimately what I want is an API call to get the contents of a documents outline.
– Alexsh
Nov 12 at 16:38
Thank you for replying it.
– Tanaike
Nov 12 at 23:15
I'm sorry for my poor English skill. In order to understand correctly the result you want and the current result, can I ask you about your question? Can you provide about the detail of
getParagraphs()
and the current result? From your current result, can you also provide the result you want?– Tanaike
Nov 9 at 0:20
I'm sorry for my poor English skill. In order to understand correctly the result you want and the current result, can I ask you about your question? Can you provide about the detail of
getParagraphs()
and the current result? From your current result, can you also provide the result you want?– Tanaike
Nov 9 at 0:20
No problem, I updated the question with the implementation for getParagraphs(). It returns a list of custom paragraph objects. There are the same as google paragrahps but also have an id for their order. This function works fine, but ultimately what I want is an API call to get the contents of a documents outline.
– Alexsh
Nov 12 at 16:38
No problem, I updated the question with the implementation for getParagraphs(). It returns a list of custom paragraph objects. There are the same as google paragrahps but also have an id for their order. This function works fine, but ultimately what I want is an API call to get the contents of a documents outline.
– Alexsh
Nov 12 at 16:38
Thank you for replying it.
– Tanaike
Nov 12 at 23:15
Thank you for replying it.
– Tanaike
Nov 12 at 23:15
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53212639%2fhow-do-i-get-a-google-apps-script-document-outline-from-the-api%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I'm sorry for my poor English skill. In order to understand correctly the result you want and the current result, can I ask you about your question? Can you provide about the detail of
getParagraphs()
and the current result? From your current result, can you also provide the result you want?– Tanaike
Nov 9 at 0:20
No problem, I updated the question with the implementation for getParagraphs(). It returns a list of custom paragraph objects. There are the same as google paragrahps but also have an id for their order. This function works fine, but ultimately what I want is an API call to get the contents of a documents outline.
– Alexsh
Nov 12 at 16:38
Thank you for replying it.
– Tanaike
Nov 12 at 23:15