簡體   English   中英

Google腳本幫助:將沒有源鏈接的數據透視表復制到新工作表

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

這里的任何幫助將不勝感激!

目前,我有一個工作表“最新記分卡”,其中包含3個數據透視表,並且工作表每周更新一次。

我想編寫一個腳本來克隆“最新記分卡”選項卡,僅粘貼值和格式(例如條件格式),然后將選項卡重命名為當前日期。 這個想法是,當“最新記分卡”標簽每周刷新一次時,我們可以為前幾周的數據准備一個備份表。

到目前為止,我得到的腳本能夠進行克隆,並將復制的工作表重命名為當前日期(但包括“源”的鏈接)。 有人可以建議如何編輯腳本以便僅粘貼值和格式,而不粘貼整個數據透視表源鏈接。

這是我的劇本

/*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);

}

非常感謝!

我解決了,謝謝。 我正在發布在這里有效的腳本。

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);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM