问题标签 [google-sheets-macros]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
370 浏览

google-sheets - Google 表格宏:在特定表格和多个范围内自动排序

我正在尝试对特定 googlesheet 上的 2 个范围进行自动排序,但是,我只能让它适用于一个范围(代码中标识的最后一个范围始终有效)。

有谁知道如何修改代码以使其适用于两个范围(不仅仅是最后一个)?

太感谢了!

我试图为每个复制整个代码并组合范围(“b16:b55”,“b59:b100”),但没有任何效果。

此代码将始终按范围 b16-b55 的第二列中的值排序。但是,我希望它适用于该范围和 b59:b100

0 投票
1 回答
799 浏览

google-apps-script - Google App 脚本:无法保留前导零,因为它已被自动删除

我是谷歌脚本的新手。我有一个像下面这样的场景。

我有带有 A 列和 B 列的 Sheet1。通常我会尝试将十进制值存储到其中。我的意思是A列中的整数部分和B列中的小数部分

例如:

场景 1:如果值为 23.75,则 A 列应为 23,B 列应为 75

场景 2:如果值为 22.00,则 A 列应为 22,B 列应为 00

我试过这样

这适用于场景 1,但对于场景 2,它仅显示一个零(自动删除前导零)。我试图将完整的列格式更改为纯文本,但没有运气。在过去的两天里,我正在努力实现这一目标。任何帮助是极大的赞赏。

0 投票
1 回答
32 浏览

google-sheets - 根据匹配数据将单元格数据复制到第二张工作表

我想使用来自收集进出时间和位置的 Google 表单(表 1)中的数据。我希望他们进出提交合并到最终产品的第二张表(表 2)上。如果电子邮件和日期匹配,请将它们的进出时间戳放在第二张纸上,以用于额外的计算和查看。有几个例子和我尝试过的东西,但我找不到任何东西。如果需要额外的数据来过滤可以添加,这在当前格式中可能是不可能的。我在这里先向您的帮助表示感谢。

表 1

表 2

0 投票
0 回答
20 浏览

google-sheets - Google 表格中基于时间的触发器未触发

我创建了一个基于时间的触发器,就像我在谷歌表格中所做的那样。然而,令人费解的是,这个没有火。

我启用了触发器,执行显示脚本每分钟都在运行。但是,该脚本未按预期执行。我在堆栈驱动程序日志中显示的脚本中有一条调试消息,这很有趣。

如果我手动运行脚本,它运行良好。为什么会这样?

这是我的脚本:

0 投票
1 回答
188 浏览

javascript - 如何从 Google 表格中的单元格中获取值,用作 Google 脚本中的数字变量

我正在尝试使用 Cell A3 的值作为变量来指定特定数组的确切大小。下面的代码不起作用,为什么?

A3 是 =COUNTA(B2:VF2)-1,当前计算结果为 446

出现的错误是:“无法将 Range1 转换为(类)。”

0 投票
1 回答
976 浏览

google-apps-script - Google 应用程序脚本:autoResizeColumn 工作不正确,无法按预期工作

我正在尝试使用以下代码通过谷歌应用程序脚本将 column1 调整为第 10 列。

列的大小已调整,但未按预期进行。

我期待这样, 在此处输入图像描述 但实际上我得到了这个 在此处输入图像描述

0 投票
0 回答
194 浏览

google-sheets - 如何在列表的最后一项下方添加一行

我有一个任务列表,我想创建一个宏以在该列表的最后一项下方添加一行。但是我尝试过的所有宏都不起作用。有人可以帮我弄这个吗?

这里是:

0 投票
1 回答
416 浏览

excel - How to replace ID numbers with names after exporting from Google sheets

I am currently working on a project for an organization to allow staff members to fill out timesheets online. I am currently using google sheets to do this and it works fine. The problem is that the organization can not store personal information outside of Canada, and after doing research I determined that Google drive does not store the information in Canada. The timesheets need to have employees name and signature on them. This cannot be stored on Google drive but must be put onto the file before printing.

This means that there are a couple different options that came to my mind:

  1. Have the ability to use the Google sheets/Google drive API but have the data stored in Canada somehow

  2. Use a number instead of the employee's name, and when the files need to be printed, they will be exported as an excel workbook from Google sheets, and the column with the number will be replaced with the employee's actual name automatically (this would be simple if there were only a few employees & it could be done manually, but there are almost 200 employees)

I have tried finding a solution to store the data within Canada. Google cloud seems to be the only way to do this through Google, however, Google cloud has no Google sheets/drive API. I have looked at many different employee timesheet softwares, none of them meet the needs. I have tried to find a solution and came across Powerquery, however, I don't think that it will work for what I am trying to do.

The code that must be updated is very simple. It is just changing one column from each different workbook which contains a number that corresponds with each employee to their actual name. The numbers are obviously different in every workbook, however, the column and row are the exact same.

For example,

  • "1234" needs to be changed to "John Cena" in workbook 1234.xlsx
  • "1235" needs to be changed to "Margeret Carmex" in workbook 1235.xlsx
  • "1236" needs to be changed to "Jossi Wells" in workbook 1236.xlsx

All of the numbers are in column A1 but in their own separate workbooks. All of the workbooks will be in the same folder after being exported from Google drive.

The expected result is to have column A1 on every single workbook be changed from a number to the name which corresponds to that number.

If anyone has any advice on how to accomplish this using Google sheets, Excel, a macro, or any desktop application please let me know. An option for storing the information within Canada using Google sheets would be ideal.

I am open to any solutions that are not any of the ones that came to my mind as well.

Thank you.

0 投票
1 回答
1264 浏览

google-apps-script - Google 应用脚本:为空单元格分配零

我是 Google Apps 脚本的新手,试图根据列的当前值和标志为其设置值。

  1. 如果 Flag = Y 则对 C1 中的值进行下限:

    C1列值=23.9895
    期望值=23

  2. 如果 Flag = N 则舍入 C1 中的现有值:

    C1列值=23.9895
    期望值=24

  3. 如果标志是 Y 或 N,则写入 0:

    C1 列值=空单元格
    预期值=0

我已经实现了下面的代码。它正在部分工作。前两个场景工作正常,但第三个场景失败。
当我尝试设置零时,我得到的是#NUM!错误而不是零。不知道该怎么做。

0 投票
1 回答
53 浏览

google-apps-script - 重新调整命名范围大小的脚本不能动态工作?

我正在尝试重新调整命名范围的大小,这需要非常具体的大小(而不是仅仅正常更新)

单元格 C2 包含新范围需要的大小(行)当前 = 736

为什么会这样:

但这不起作用:

我希望他们都做同样的事情,但是代码的第二个(动态)版本返回Cannot find method getRange(number,number,number,number).

如果有帮助,我可以在单元格 C2 中编写一个快速公式,以便它包含B4:K739为一个字符串,但是我不知道如何将它放入脚本中?