Reputation: 81
I'm creating a function that will transfer text that a user is currently selecting from one document to another.
It works fine most of the time, but when I try to transfer list items, as seen on this image, the list item numbers disappear.
After being transferred to the target document, the list items from the last image now look like this.
Is there a way to make sure the numbers get transferred, or at least recreate them in an efficient way? Thanks!
function sendToDoc() {
var currentDoc = DocumentApp.getActiveDocument().getSelection();
var targetDoc = DocumentApp.openByUrl(a different documents url);
var body = targetDoc.getBody();
//if you are selecting some text, this function will transfer your selection into the target document
if(currentDoc) {
var totalElements = currentDoc.getRangeElements();
//for each element in your selection
for( var index = 0; index < totalElements.length; ++index ) {
var element = totalElements[index].getElement().copy();
var type = element.getType();
//gets the element type and transfers it over to the target doc
if( type == DocumentApp.ElementType.PARAGRAPH ){
body.appendParagraph(element);
}
else if( type == DocumentApp.ElementType.TABLE){
body.appendTable(element);
}
else if( type == DocumentApp.ElementType.LIST_ITEM){ //this is where the list items get transferred
body.appendListItem(element);
}
else if( type == DocumentApp.ElementType.INLINE_IMAGE ){
body.appendImage(element);
}
else if( type == DocumentApp.ElementType.HORIZONTAL_RULE ){
body.appendHorizontalRule();
}
else {
}
}
}
Upvotes: 0
Views: 83