admin管理员组文章数量:1418113
When I try to copy paragraphs form one doc to another I get unexpected error:
It is necessary to detach the element
What does it mean? What am I doing wrong?
function test_copy_paragrahps() {
var final = 'final';
var doc1 = get_doc('', final);
var doc2 = create_doc_in_path('', final+'test');
var body1 = doc1.getBody();
var body2 = doc2.getBody();
var par1 = body1.getParagraphs();
for (var i=0;i<par1.length;i++) {
body2.insertParagraph(i, par1[i]);
}
}
here is video
P.S. You can not mention on get_doc and create_doc_in_path implementations. Both return Document object.
When I try to copy paragraphs form one doc to another I get unexpected error:
It is necessary to detach the element
What does it mean? What am I doing wrong?
function test_copy_paragrahps() {
var final = 'final';
var doc1 = get_doc('', final);
var doc2 = create_doc_in_path('', final+'test');
var body1 = doc1.getBody();
var body2 = doc2.getBody();
var par1 = body1.getParagraphs();
for (var i=0;i<par1.length;i++) {
body2.insertParagraph(i, par1[i]);
}
}
here is video http://youtu.be/1WdCD5ATiYw
P.S. You can not mention on get_doc and create_doc_in_path implementations. Both return Document object.
Share Improve this question edited Aug 24, 2014 at 19:07 Karen Fisher asked Aug 24, 2014 at 18:15 Karen FisherKaren Fisher 7771 gold badge9 silver badges26 bronze badges 01 Answer
Reset to default 7You attempted to insert a paragraph that already has a parent Body. You need to create a detached copy of the paragraph before you can insert it.
See this part of the documentation that mentions detaching a paragraph.
I believe this will fix the error:
function test_copy_paragrahps() {
var final = 'final';
var doc1 = get_doc('', final);
var doc2 = create_doc_in_path('', final+'test');
var body1 = doc1.getBody();
var body2 = doc2.getBody();
var par1 = body1.getParagraphs();
for (var i=0;i<par1.length;i++) {
body2.insertParagraph(i, par1[i].copy()); //--- copy()
}
}
本文标签: javascriptquotIt is necessary to detach the elementquot error in google docs scriptStack Overflow
版权声明:本文标题:javascript - "It is necessary to detach the element" error in google docs script - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745281649a2651456.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论