Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function copyAllForms() {
- copyForms(true,true);
- }
- function copyStandardForms() {
- copyForms(true,false);
- }
- function copyLeaderForms() {
- copyForms(false,true);
- }
- function copyForms(sheet1,sheet2) {
- var mSheet = SpreadsheetApp.getActiveSpreadsheet();
- var sheetS = mSheet.getSheetByName('Standard');
- var sheetL = mSheet.getSheetByName('Leadership');
- var sheetD = mSheet.getSheetByName('Data');
- var copies = sheetD.getRange(2,2,sheetD.getMaxRows(),3).getValues()
- .filter(function(x) { return x[0] != ''; });
- makeDupes(copies, sheetS, sheetL, sheet1, sheet2);
- }
- function makeDupes(copies, sheetS, sheetL, sheet1, sheet2) {
- copies.forEach((nSheet)=> {
- if (nSheet[1] && sheet1)
- dupSheet(nSheet[0], sheetS, "Standard");
- if (nSheet[2] && sheet2)
- dupSheet(nSheet[0], sheetL, "Leadership");
- })
- }
- function dupSheet(nName, oSheet, sName) {
- var sParent = SpreadsheetApp.openById(nName);
- var nSheet = sParent.getSheetByName(sName);
- if (nSheet == null)
- nSheet = sParent.insertSheet().setName(sName);
- var mRanges = nSheet.getRange("A1:ZZZ9999").getMergedRanges();
- mRanges.forEach((rng) => rng.breakApart());
- if (nSheet.getMaxRows() > oSheet.getMaxRows())
- nSheet.deleteRows(oSheet.getMaxRows()+1,nSheet.getMaxRows() - oSheet.getMaxRows())
- if (nSheet.getMaxColumns() > oSheet.getMaxColumns())
- nSheet.deleteColumns(oSheet.getMaxColumns()+1,nSheet.getMaxColumns() - oSheet.getMaxColumns())
- mRanges = oSheet.getRange("A1:ZZZ9999").getMergedRanges();
- var a1Note;
- mRanges.forEach((rng) => {
- a1Note = rng.getA1Notation();
- nSheet.getRange(a1Note).merge();
- });
- dupRules(nSheet, oSheet);
- for (var c = 0; c < oSheet.getMaxColumns(); c++) {
- nSheet.setColumnWidth(c+1, oSheet.getColumnWidth(c+1));
- for (var r = 0; r < oSheet.getMaxRows(); r++) {
- dupCell(r+1,c+1,nSheet,oSheet);
- }
- }
- nSheet.setFrozenRows(oSheet.getFrozenRows());
- addImage(nSheet, sName);
- }
- function dupCell(row,col,nSheet,oSheet) {
- var oRng = oSheet.getRange(row,col);
- var nRng = nSheet.getRange(row,col);
- nRng.setValue(oRng.getValue());
- if (oRng.getFormula() != "") {
- nRng.setFormula(oRng.getFormula());
- nRng.setNumberFormat(oRng.getNumberFormat());
- }
- nRng.setFontColor(oRng.getFontColor());
- nRng.setFontSize(oRng.getFontSize());
- nRng.setFontWeight(oRng.getFontWeight());
- nRng.setFontStyle(oRng.getFontStyle());
- nRng.setFontLine(oRng.getFontLine());
- nRng.setFontFamily(oRng.getFontFamily());
- nRng.setBackground(oRng.getBackground());
- nRng.setHorizontalAlignment(oRng.getHorizontalAlignment());
- nRng.setVerticalAlignment(oRng.getVerticalAlignment());
- nRng.setWrapStrategy(oRng.getWrapStrategy());
- if (oRng.getBackground() == '#fefefe') {
- nRng.setBorder(true,true,true,true,true,true,'#fefefe',SpreadsheetApp.BorderStyle.SOLID);
- } else {
- nRng.setBorder(true,true,true,true,true,true,'black',SpreadsheetApp.BorderStyle.SOLID);
- }
- if (row == 1)
- nRng.setBorder(true,null,null,null,null,null,'black',SpreadsheetApp.BorderStyle.SOLID_MEDIUM);
- if (col == 1)
- nRng.setBorder(null,true,null,null,null,null,'black',SpreadsheetApp.BorderStyle.SOLID_MEDIUM);
- if (row == nSheet.getMaxRows())
- nRng.setBorder(null,null,true,null,null,null,'black',SpreadsheetApp.BorderStyle.SOLID_MEDIUM);
- if (col == nSheet.getMaxColumns())
- nRng.setBorder(null,null,null,true,null,null,'black',SpreadsheetApp.BorderStyle.SOLID_MEDIUM);
- nRng.setDataValidation(oRng.getDataValidation());
- }
- function dupRules(nSheet, oSheet) {
- var rules = oSheet.getConditionalFormatRules();
- var nRules = []
- rules.forEach((rule) => {
- rule.getRanges().forEach((rng) => {
- nRules.push(SpreadsheetApp.newConditionalFormatRule()
- .withCriteria(rule.getBooleanCondition().getCriteriaType(),rule.getBooleanCondition().getCriteriaValues())
- .setBackground(rule.getBooleanCondition().getBackground())
- .setRanges([nSheet.getRange(rng.getA1Notation())])
- .build());
- });
- });
- nSheet.setConditionalFormatRules(nRules);
- }
- function addImage(nSheet, sName) {
- var images = nSheet.getImages();
- images.forEach((image) => {
- image.remove();
- });
- var blob = "https://drive.google.com/uc?export=view&id=1s4tCwyfEdTSwVUEVqHDlJpN9KtPVR6lj";
- nSheet.insertImage(blob, 10, 1).assignScript("clear"+sName);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement