复制并粘贴到特定列google工作表中的下一个可用行

时间:2018-04-04 05:41:04

标签: google-apps-script google-sheets copy-paste

我试图从Excel切换到Google表格,但我已经有了一个宏,但您无法在Google电子表格上运行宏。我想要的是将登录中的值!C5移动到另一张表格" w1"从A3栏开始。我的代码有效,但不是将其移入" w1!A3"它被放置在单元格A146上,因为它是下一个空行。有没有办法让值在A列的第一个空行中移动?不管其他列不是空的吗?

这是我的代码

function moveValuesOnly() {
 var ss = SpreadsheetApp.getActiveSpreadsheet();
 var source = ss.getRange('Log-in!C5');
 var destSheet = ss.getSheetByName('w1');
 var destRange = destSheet.getRange(destSheet.getLastRow()+1,1);
 source.copyTo (destRange, {contentsOnly: true});
 source.clear ();
}  

1 个答案:

答案 0 :(得分:0)

  • const express = require("express"); const app = express(); const bodyParser = require('body-parser'); const port = 4000; const jwt = require('jsonwebtoken'); //used to create, sign , and verify tokens const logger = require('morgan'); const mongoose = require("mongoose"); mongoose.Promise = global.Promise; mongoose.connect("mongodb://localhost:27017/saddleHorseacademy"); //Setting up basic middleware for all express requests app.use(logger('dev')); //Log requests to API using morgan //Enabling CORS from the client side app.use(function (request,response,next) { response.header("Access-Control-Allow-Origin","*"); response.header('Access-Control-Allow-Methods','PUT ,GET ,POST ,DELETE ,OPTIONS'); response.header("Access-Control-Allow-Headers","Origin, X-Requested-With, Content-Type, Accept, Authorization, Access-Control-Allow-Credentials"); response.header("Access-Control-Allow-Credentials","true"); next(); }); var registerSchema = new mongoose.Schema({ firstName: String, lastName: String, address: String, birthDay: Date, packageOption: String, batchOption: String, startDate: Date, endDate: Date, phoneNumber: Number, emailValue: String, specialRemarks: String }); // var changePassword = new mongoose.Schema({ // username : String, // newPassword : String, // }); var createUser = new mongoose.Schema({ userName : String, password : String }); var students = mongoose.model("students",registerSchema); var userList = mongoose.model("UserList",createUser); // var passwordChange = mongoose.model("UserList",changePassword); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({extended: true})); app.get("/", (request,response) => { response.send("hello"); }); // post call for creating user app.post("/addStudent",(request,response)=>{ var myData = new students(request.body); myData.save().then(item=>{ response.send('Student successfully registerd'); }) .catch(error =>{ response.status(400).send('Student not successfully registered'); }); }); //updating the password app.put("/loginPassword",(request,response)=>{ var newPassword = new userList(request.body); var query = {userName:request.body.userName}; userList.findOneAndUpdate(query,{$set:{password:newPassword}},{new:false},function(error,doc) { if(error) { console.log(error); response.send("Password not updated"); } else { response.send("password updated"); } }) }); // post call creating user app.post("/loginPassword",(request,response)=>{ var myUsers = new userList(request.body); myUsers.save().then(item2=>{ response.send("User Created"); }) .catch(error=>{ response.status(400).send("not able to create user"); }); }); app.listen(port,()=>{ console.log("server listening to port" +port); }) 只获取工作表的lastRow而不是范围。
  • 如果您只想要getLastRow(),请直接对其进行硬编码:尝试从

    更改
    w1!A3

    destSheet.getRange(destSheet.getLastRow()+1,1);
    

<小时/> 或者,要查找范围中的第一个空单元格,

destSheet.getRange(3,1);

代码1:

var colA = destSheet.getRange('A:A').getValues();

代码2:

//Filter 2D array to 1D
var fcolA = colA.filter(function (e) {return e[0];});
var firstEmptyRowIncolA = fcolA.indexOf('')+1;