如何将脚本应用到谷歌电子表格中的整个列 [英] how to apply script to entire columns in google spredsheet

查看:267
本文介绍了如何将脚本应用到谷歌电子表格中的整个列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此脚本将E1更改为36,然后清除D1。即它添加两个单元,然后清除另一个单元。
D1 E1
10 26

  var ss = SpreadsheetApp.getActiveSheet(); 
var num1 = ss.getRange(D1)。getValue();
var num2 = ss.getRange(E1)。getValue();
ss.getRange(E1)。setValue(num1 + num2);
ss.getRange(D1)。clear();

正如我从 Google电子表格脚本将两个单元格加在一起
i希望以上例子适用于列中的所有单元格,即整个D列和E列。

解决方案

这是一个回答:

pre $ function addColumns(){
var ss = SpreadsheetApp.getActiveSheet();
var len = ss.getLastRow();
for(var i = 1; i< len +1; i ++){
var num1 = ss.getRange(D+ i).getValue();
var num2 = ss.getRange(E+ i).getValue();
ss.getRange(E+ i).setValue(num1 + num2);
ss.getRange(D+ i).clear();


$ / code $ / pre

这并不是很有效率......所以你会发现奇怪的慢。但它的工作原理。
我同意@eddyparkinson认为学习谷歌应用程序脚本(这与javascript几乎相同)是很好的,因为您可能会从中获益良多。我必须从一年前开始从头开始学习它,主要是通过查看这个特定的谷歌应用程序脚本论坛,然后,当我陷入困境时,引用大量的JavaScript一般帮助,你可以在互联网上找到只是做一个搜索手中的术语。


编辑
为了说明问题,我已在电子表格中共享此脚本(点击此处)。
在该电子表格中,有一个名为脚本中心菜单>自定义菜单>将列D添加到E



然后将列D Sheet1中的所有值对于E栏1中的那些栏,在栏E中显示它们并删除栏D中的原始值。(如果你想进行实验,你可以手动准备栏的值,只需在D栏和E栏中输入你需要的值 - 首先清除D列和E列中的当前值可能更容易。另一种设置演示值的方法是使用第二个菜单项脚本中心菜单>复制列,它将简单地复制Sheet2中的现有值到Sheet1)。


this script changes E1 to 36 and then clears D1. i.e it add two cells and then clears the other cell. D1 E1 10 26

 var ss = SpreadsheetApp.getActiveSheet(); 
 var num1 = ss.getRange("D1").getValue(); 
 var num2 = ss.getRange("E1").getValue();
 ss.getRange("E1").setValue(num1+num2); 
 ss.getRange("D1").clear();

As i have copied code from Google spreadsheet script to add two cells together. i want to aplly above example to all cells in columns i.e entire column D and column E.

解决方案

This is an answer:

function addColumns(){
  var ss = SpreadsheetApp.getActiveSheet();
  var len = ss.getLastRow();
  for(var i = 1 ; i < len +1  ; i++){
    var num1 = ss.getRange("D"+i).getValue(); 
    var num2 = ss.getRange("E"+i).getValue();
    ss.getRange("E"+i).setValue(num1+num2); 
    ss.getRange("D"+i).clear(); 
  }
}

It is not at all efficient ... so you will find it strangely slow. But it works.
I agree with @eddyparkinson that it is good to learn google apps script (which is pretty much the same as javascript) because you are likely to get a lot out of it. I had to start learning it from scratch about 1 year ago, mainly by looking at this particular forum for google apps script and then, when I got stuck, referencing the huge quantity of javascript general help you can find on the internet just by doing a search for the term in hand.

EDIT To make it apparent, I have shared this script within a spreadsheet (click here). In that spreadsheet, there is a custom menu called "Script Center Menu>Add column D to E

This will then add all the values in column D Sheet1 to those in column E Sheet 1, displaying them in column E and deleting the original value in column D. (If you wish to experiment, you can prepare the columns' values manually, simply by typing your required values into columns D and E - it may be easier to first clear current values in columns D and E. An alternative way to set yourself up the values for a demonstration is to use the second menu item Script Center Menu>Copy Columns which will simply copy the existing values in Sheet2 over to Sheet1).

这篇关于如何将脚本应用到谷歌电子表格中的整个列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆