简体   繁体   中英

Google Script help: copy pivot table without source linkage to a new sheet

any help here would be appreciated!

Currently I have a sheet "latest scorecard" that contain 3 pivot tables and the sheet gets updated weekly.

I want to write a script that will make a clone of "latest Scorecard" tab, paste only the values and format (ex. conditional formatting) and rename the tab as current date. The idea is when the "latest scorecard " tab get refreshed weekly, we can have a backup sheet on previous weeks data.

The script I get so far is able to make a clone and rename the copied sheet as current date, (BUT IT INCLUDES LINKAGE OF THE "SOURCE"). Can someone advise how to edit the script in order to only paste value and format instead of the whole pivot table source linkage.

here is my script

/*create scorecard clone*/
function cloneGoogleSheet() {

var ss = SpreadsheetApp.getActiveSpreadsheet();

var tz = ss.getSpreadsheetTimeZone();

var newDate= new Date();

var sheet = ss.getSheetByName('Latest Scorecard').copyTo(ss); 

var stringDate = Utilities.formatDate(newDate, tz, 'MM-dd-yy');

/* Make the new sheet active and rename to current date*/

ss.setActiveSheet(sheet).showSheet();

ss.renameActiveSheet(stringDate);

ss.moveActiveSheet(6);

}

Thank you so much!

I have it resolved thank you. I am posting the script that works here.

function cloneGoogleSheet() {

var ss = SpreadsheetApp.getActiveSpreadsheet();
var tz = ss.getSpreadsheetTimeZone();
var date = new Date();
var sheet = ss.getSheetByName('Latest Scorecard').getDataRange();
var newsheet = ss.insertSheet('New Sheet');
var stringDate = Utilities.formatDate(date , tz, 'MM-dd-yy');

/*copy the scorecard pivot table to a newsheet and make it static without copying the pivot table source*/  
sheet.copyTo(newsheet.getRange('A1'), {contentsOnly:true}); /*copy only content over to newsheet first*/
var newsheet_id = newsheet.getDataRange().getGridId();
sheet.copyFormatToRange(newsheet_id, 1, 26, 1, 30); /*then copy the format over to newsheet to break the source link*/

/* Make the new sheet active and rename to current date*/
ss.setActiveSheet(newsheet).showSheet(); 
ss.renameActiveSheet(stringDate);
ss.moveActiveSheet(6);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM