我正在尝试从模板文件中生成Google文档中的报告。当它复制文档时,它会将所有格式重置为用户的默认格式,而不是原始文档中的格式。我尝试了以下方法,尝试在文档、tableRow和tableCell级别设置格式,但在创建报告时,行距为1.5,段落后有一个空格
var style = {};
style[DocumentApp.Attribute.SPACING_AFTER] =0;
style[DocumentApp.Attribute.SPACING_BEFORE] =0;
style[DocumentApp.Attribute.LINE_SPACING]=1;
var newrow= tables[2].insertTableRow(n).setBold(false).setAttributes(style);
if(j==0){
newrow.insertTableCell(0,reportDate).setPaddingBottom(0).setPaddingTop(0).setAttributes(style);
}
else{
newrow.insertTableCell(0,'').setPaddingBottom(0).setPaddingTop(0).setAttributes(style);
}
newrow.insertTableCell(0,values1[rowId1][1]+' '+values1[rowId1][2]).setPaddingBottom(0).setPaddingTop(0).setAttributes(style);
newrow.insertTableCell(0,'').setPaddingBottom(0).setPaddingTop(0).setAttributes(style);
doc.editAsText().setAttributes(style);对于如何让报告遵循这些属性,有什么建议吗?
发布于 2012-11-30 02:30:26
由于set属性没有设置属性,并且您不能将任何元素强制转换为段落,因此我通过获取所有段落并在末尾添加以下内容来手动设置它们,从而解决了这个问题
var p=doc.getParagraphs();
for(i=0;i<p.length; i++){
p[i].setLineSpacing(1).setSpacingAfter(0);发布于 2014-03-20 11:22:52
我认为SPACING_AFTER、SPACING_BEFORE和LINE_SPACING不是与TABLE_CELL对象相关联的属性。您必须引用子段才能设置这些内容。
var style = {};
style[DocumentApp.Attribute.SPACING_AFTER] =0;
style[DocumentApp.Attribute.SPACING_BEFORE] =0;
style[DocumentApp.Attribute.LINE_SPACING]=1;
var newrow = tables[2]
.insertTableRow(n)
.setBold(false);
if (j == 0) {
newrow.insertTableCell(0,reportDate)
.setPaddingBottom(0)
.setPaddingTop(0);
}
else {
newrow.insertTableCell(0,'').setPaddingBottom(0).setPaddingTop(0);
}
newrow.insertTableCell(0,values1[rowId1][1]+' '+values1[rowId1][2])
.setPaddingBottom(0)
.setPaddingTop(0);
newrow.insertTableCell(0,'')
.setPaddingBottom(0)
.setPaddingTop(0);
var newrowTableCell = newrow.getChild(0);
var newrowParagraph = newrowTableCell.getChild(0).setAttributes(style);发布于 2012-11-20 03:13:45
用户需要能够编辑报告,还是只需要查看报告?为什么不生成一个pdf呢?每次我这样做的时候,它都会保存格式。
var file = DocsList.getFileById('1DIfn_wVpXSI4hU5zG43Fvp2ZdpUP_KqgtgFRT9NWJ7E');
var newFile = DocsList.copy(file, ename+'-'+reportDate+'Monthly Report');
var report=DocsList.createFile(newFile.getAs("application/pdf")).rename(newFile.getName() + ".pdf");
var a = report.getID();
var doc = DocumentApp.openById(a);https://stackoverflow.com/questions/13310412
复制相似问题