我正在尝试将Google云端硬盘中的两页电子表格复制到另一个文件夹。
这是我设法束缚自己的地方;
function clearRange() {
var sheet = Spreadsheetapp.getactive().getSheetByName('Internal copy');
sheet.getRange('B3:B7').clearContent();
sheet.getRange('D3:D5').clearContent();
sheet.getRange('B12:C15').clearContent();
sheet.getRange('B20:C23').clearContent();
sheet.getRange('B28:C31').clearContent();
}
function copySpreadSheet() {
var source = Spreadsheetapp.getactiveSheet();
var sourceName = source.getSheetName();
var sValues = source.getDataRange().getvalues();
var destination = Spreadsheetapp.openById('1Mcnlyknqmtf2u_TEhbWxwzYqlxGw39sno2bOXgkErb4');
source.copyTo('destination')
var destinationSheet = destination.getSheetByName('Copy of '+sourceName)
destinationSheet.getRange(1,1,sValues.length,sValues[0].length).setvalues(sValues);
function main() {
copySpreadSheet("Internal Estimate invoice Blundell");
}
请注意,第一位是保存后清除单元格的另一功能。这是我希望我的商店使用的报价模板,而不会弄乱报价。我希望他们输入数据,将其保存为副本,然后将字段重置为零,以备下一次引用。
任何帮助将不胜感激!
****更新********
所以,我已经使它有些工作了。这是我的新代码;
function copySheetvaluesV4(){
var sourceSpreadsheet = Spreadsheetapp.getactiveSpreadsheet();
var sourceSheets = sourceSpreadsheet.getSheets();
var destination = Spreadsheetapp.create(sourceSpreadsheet.getName()+' Final');
for (var i = 0; i < sourceSheets.length; i++){
var sourceSheet = sourceSheets[i];
if (!sourceSheet.isSheetHidden()) {
var sourceSheetName = sourceSheet.getSheetName();
var sValues = sourceSheet.getDataRange().getvalues();
sourceSheet.copyTo(destination)
var destinationSheet = destination.getSheetByName('Copy of '+sourceSheetName).setName(sourceSheetName);
destinationSheet.getRange(1,sValues[0].length).setvalues(sValues);// overwrite all formulas that the copyTo preserved */
}
destination.getSheetByName("sheet1").hideSheet() // Remove the default "sheet1" */
}
}
它会在我的/ root文件夹中进行复制,这现在可以了,但是它不会复制任何公式,也不会复制受保护的范围。
有什么想法吗?