在一定数量的段落后插入分页符 [英] insert page break after a certain number of paragraphs
问题描述
function worksheetGen () {
var templateDocID = ScriptProperties.getProperty("listTemplateDocID");
var docID = DocsList.getFileById(templateDocID).makeCopy().getId();
var doc = DocumentApp.openById(docID);
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var activeSheetName = sheet.getName();
var user = Session.getUser().getEmail();
if (sheet != null) {
var lastRow = sheet.getLastRow();
var lastColumn = sheet.getLastColumn();
var lastACell = sheet.getRange("A"+lastRow);
Logger.log("Last Column: " + lastColumn + " Last A Cell: " + lastACell)
for (var q = 0; q < lastRow; ++q){
var firstName = sheet.getRange(q+2,3).getValue();
var lastName = sheet.getRange(q+2,4).getValue();
var include = sheet.getRange(q+2,1).getValue();
var dispo1 = "Request Left With Dr.";
var dispo2 = "Needs Appointment";
var dispo3 = "Prescription Received";
var dispo4 = "Prescription Denied";
var notes = "Notes:";
if (firstName != null && include == "Y") {
var nameSet = firstName + " " + lastName + ": ";
var dispoSet = "| " + dispo1 + " | " + dispo2 + " | " + dispo3 + " | " + dispo4 + " |";
var cells = [[nameSet, dispoSet]];
var table = doc.appendTable(cells);
table.setBorderWidth(0).setColumnWidth(1, 334);
var cell2 = table.getCell(0, 1).getChild(0).asParagraph();
cell2.setAlignment(DocumentApp.HorizontalAlignment.RIGHT).setFontSize(8);
var content2 = doc.appendParagraph(notes);
var divider = doc.appendHorizontalRule();
}
}
}
doc.addFooter().appendParagraph(activeSheetName + " -- " + new Date());
doc.setName(activeSheetName + " - " + Utilities.formatDate(new Date(), "MDT", "MM/dd/yy"));
doc.addEditor(user);
doc.addEditor("ecaldwell@kmrmedical.com");
}
我尝试了一个if语句,以检查 q 之后是否等于5或倍数,但是我一定做错了.我敢肯定这是一个简单的修复程序,但是我对此还很陌生,因此可以提供任何帮助.
在var Divider = doc ...以下尝试一下.
if(q==5||(q>6&&q/6==parseInt(q/6))){doc.appendPageBreak()}
i have written a script that generates a paragraph based on data from a spreadsheet, it adds a new paragraph for each line of data. my problem is that some of the paragraphs are split between pages and i can't figure out how to insert a page break automatically after 6 (actually 5 on the first page and 6 for every page after that) instances of the paragraph.
function worksheetGen () {
var templateDocID = ScriptProperties.getProperty("listTemplateDocID");
var docID = DocsList.getFileById(templateDocID).makeCopy().getId();
var doc = DocumentApp.openById(docID);
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var activeSheetName = sheet.getName();
var user = Session.getUser().getEmail();
if (sheet != null) {
var lastRow = sheet.getLastRow();
var lastColumn = sheet.getLastColumn();
var lastACell = sheet.getRange("A"+lastRow);
Logger.log("Last Column: " + lastColumn + " Last A Cell: " + lastACell)
for (var q = 0; q < lastRow; ++q){
var firstName = sheet.getRange(q+2,3).getValue();
var lastName = sheet.getRange(q+2,4).getValue();
var include = sheet.getRange(q+2,1).getValue();
var dispo1 = "Request Left With Dr.";
var dispo2 = "Needs Appointment";
var dispo3 = "Prescription Received";
var dispo4 = "Prescription Denied";
var notes = "Notes:";
if (firstName != null && include == "Y") {
var nameSet = firstName + " " + lastName + ": ";
var dispoSet = "| " + dispo1 + " | " + dispo2 + " | " + dispo3 + " | " + dispo4 + " |";
var cells = [[nameSet, dispoSet]];
var table = doc.appendTable(cells);
table.setBorderWidth(0).setColumnWidth(1, 334);
var cell2 = table.getCell(0, 1).getChild(0).asParagraph();
cell2.setAlignment(DocumentApp.HorizontalAlignment.RIGHT).setFontSize(8);
var content2 = doc.appendParagraph(notes);
var divider = doc.appendHorizontalRule();
}
}
}
doc.addFooter().appendParagraph(activeSheetName + " -- " + new Date());
doc.setName(activeSheetName + " - " + Utilities.formatDate(new Date(), "MDT", "MM/dd/yy"));
doc.addEditor(user);
doc.addEditor("ecaldwell@kmrmedical.com");
}
i tried an if statement to check if q equaled 5 or a multiple after that but i must have been doing it wrong. i'm sure it's a simple fix but i'm fairly new to this so any help is appreciated.
Try this just below var divider = doc...
if(q==5||(q>6&&q/6==parseInt(q/6))){doc.appendPageBreak()}
这篇关于在一定数量的段落后插入分页符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!