|
发表于 2020-12-15 14:14
来自手机
|
显示全部楼层
jinxuanmr 发表于 2020-12-15 12:31
麻烦您了,用户名:zhengling006@谷歌邮箱后缀
米吗:Zhengling006+ 用我的吧
第一个问题,他是根据整个工作表判断的,你要根据那一列?
last_row = target_sheet.getLastRow();
第二个问题
// ------------ GENERAL GOOGLE SHEET DOC TO TRACKING GOOGLE SHEET DOC ------------
function GeneralToTracking(tName) {
/*
This code defines the Source Google Sheet Doc and the Target Google Sheet Doc. These are two
different google sheet docs. They are NOT 2 sheets in the same google sheet doc.
*/
var ss = SpreadsheetApp.getActiveSpreadsheet();
/*
var target = SpreadsheetApp.openById('1yxfpC7Yag9GAkoe5BUjjg12cUhGmGr5ryeGl87JmZqU');
*/
/*这里 同一个 工作簿 */
var target=SpreadsheetApp.getActiveSpreadsheet();
/*
This code is to pick specific sheets within the Source & Target Sheet.
Source Google Sheet ="New Stuff"
Target Google Sheet ="Archive"
*/
var source_sheet = ss.getActiveSheet(); // ++++ TO DO: Need to make this work on whatever sheet the user is on currently, instead of being hardcoded. ++++
var target_sheet = target.getSheetByName(tName); // ++++ TO DO: Need to present the user with a list of tabs in the Target doc. Prompt w/ Radio Buttons. ++++
/*
This code determines the from-range and the to-range to copy & says where to put it in the Target.
*/
var source_range = source_sheet.getActiveRange();
var sValues = source_range.getValues();
var last_row = target_sheet.getLastRow();
// source_range.copyTo(target_range);
if (last_row > 0) target_sheet.insertRowAfter(last_row);
var target_range = target_sheet.getRange(last_row + 1, 1, sValues.length, sValues[0].length);
target_range.setValues(sValues);
// double check and enable these when above test is pass
// var copiedsheet = source_sheet.copyTo(target);
// copiedsheet.getRange(source_range.getA1Notation()).copyTo(target_range);
// target.deleteSheet(copiedsheet);
}
function onOpen() {
SpreadsheetApp.getUi() // Or DocumentApp or SlidesApp or FormApp.
.createMenu('Custom Menu')
/*
.addItem('Enter Target Name', 'enterTargetName')
*/
.addItem('复制粘贴到dest表', 'zpy2')
.addToUi();
}
function zpy2(){
var text="dest";//目标表的名称
GeneralToTracking(text);
}
function enterTargetName() {
var ui = SpreadsheetApp.getUi(); // Same variations.
var result = ui.prompt(
'Enter Target Sheet Name',
'Please enter target sheet name:',
ui.ButtonSet.OK_CANCEL
);
// Process the user's response.
var button = result.getSelectedButton();
var text = result.getResponseText();
if (button == ui.Button.OK) {
// User clicked"OK".
GeneralToTracking(text);
}
}
我的手机为啥不能注册? |
|