I am using this very helpful script (below) from a previous question (Export Google Docs comments into Google Sheets, along with highlighted text?) to retrieve comments (and the associated highlighted text) from a Google Doc and put it into a Google Sheet.
I want to add a third column that retrieves the relevant section header (Heading1) for the highlighted text. For example, if the comment and highlighted text are in Section 3 of the document, I want to retrieve the section heading "Section 3" and have it appear in a third column.
function listComments() {
// Change docId into your document's ID
// See below on how to
var docId = '14oWkmw0GJ_RqNZVpPyFH5e0Mn7u1-5J-1v-lG1va9kk';
var comments = Drive.Comments.list(docId);
var hList = [], cList = [];
// Get list of comments
if (comments.items && comments.items.length > 0) {
for (var i = 0; i < comments.items.length; i++) {
var comment = comments.items[i];
// add comment and highlight to array's first element
hList.unshift([comment.context.value]);
cList.unshift([comment.content]);
}
// Set values to A and B
var sheet = SpreadsheetApp.getActiveSheet();
sheet.getRange("A1:A" + hList.length).setValues(hList);
sheet.getRange("B1:B" + cList.length).setValues(cList);
}
}
I would appreciate any help!
Thanks, Chloe