Google apps script 有没有可能在任何打开的电子表格中运行Google Sheets宏?如果是,怎么做?

Google apps script 有没有可能在任何打开的电子表格中运行Google Sheets宏?如果是,怎么做?,google-apps-script,google-sheets,Google Apps Script,Google Sheets,更新:见下文 我认为提出我的问题的最好方式是描述目前的程序和我想实施的程序。 现行程序: 1) My program creates NNN (some number) of CSV files (e.g. file1.csv, file2.csv, file3.csv, etc). 2) I move those CSVs to my Google Drive. 3) I select the first one and [right click] "Open With Go

更新:见下文

我认为提出我的问题的最好方式是描述目前的程序和我想实施的程序。 现行程序:

1) My program creates NNN (some number) of CSV files (e.g. file1.csv, file2.csv, file3.csv, etc).  
2) I move those CSVs to my Google Drive.  
3) I select the first one and [right click] "Open With Google Sheets"
4) Once the data from the CSV file is imported into the new Google Spreadsheet file, I:
    A) Delete the first column (A)
    B) Highlight all the column headings (first row)
    C) Apply Bold, and Bottom Border
    D) Highlight all the columns (A-F)
    E) Double-click on a column-head separator to resize all columns to an optimal width
    F) View, Freeze, 1 Row
    G) Close the spreadsheet
5) Repeat, until all CSVs are imported and reformatted (separate single-sheet/tab spreadsheets, one for each CSV file)
我想要的程序是:

1) My program creates NNN (some number) of CSV files.  
2) I move those CSV files to my Google Drive.  
3) I select the first one and [right click] "Open With Google Sheets"
4) Once the data from the CSV file is imported into the new Google Spreadsheet file, I:
    A) Press [Alt]-r* (which performs the formatting steps A-G, detailed above)
5) Repeat, until all CSV files are imported and reformatted (separate single-sheet/tab spreadsheet files, one for each CSV file)
诀窍(也是我问题的基础)是,当宏的代码存储在其他电子表格文件(例如MyReformattingMacro)中时,如何在我刚刚创建的每个电子表格中运行指定为[Alt]-r的宏

*触发宏的按键并不重要。我以“[Alt]-r”为例

更新:根据@ale13的建议,我认为我的“我想要的程序”的替代方案可以是:

1) My program creates NNN (some number) of CSV files.  
2) I move those CSV files to my Google Drive.  
3) I select the first one and [right click] "Open With Google Sheets"
4) Once the data from the CSV file is imported into the new Google Spreadsheet file, I:
5) Repeat, until all CSV files are imported and reformatted (separate single-sheet/tab spreadsheet files, one for each CSV file)
6) I open a spreadsheet that contains the names of all the spreadsheet I just created (I could create the names list at the same time I create the original CSV files), and copy and paste the list into "MyReformattingMacro" (mentioned above).  And then press [Alt]-r* (which performs the reformatting operations A-G, detailed above)
流程将是:

  • 您可以将本地CSV文件移动到我的Google驱动器中的特定Google文件夹(如“PendingCSV”)

  • 通过单击创建新脚本

  • 在此脚本中,位于特定文件夹中

  • 将PendingCSV文件夹中的所有CSV转换为Google工作表。这可以通过或查看并将转换后的电子表格放到另一个文件夹中,比如“PendingPreadsheets”

  • 然后脚本循环遍历PendingPreadsheets中的每个文件,获取其id(),并使用()打开文件

  • 一旦
    文件
    作为
    电子表格
    打开,执行所有必要的格式化选项,如()并在循环中对所有其他
    文件
    重复(步骤5)

  • 流程将是:

  • 您可以将本地CSV文件移动到我的Google驱动器中的特定Google文件夹(如“PendingCSV”)

  • 通过单击创建新脚本

  • 在此脚本中,位于特定文件夹中

  • 将PendingCSV文件夹中的所有CSV转换为Google工作表。这可以通过或查看并将转换后的电子表格放到另一个文件夹中,比如“PendingPreadsheets”

  • 然后脚本循环遍历PendingPreadsheets中的每个文件,获取其id(),并使用()打开文件

  • 一旦
    文件
    作为
    电子表格
    打开,执行所有必要的格式化选项,如()并在循环中对所有其他
    文件
    重复(步骤5)


  • 不幸的是,我无法理解可用于我打开的任何工作表的
    宏。我为此道歉。我可以问你目标的细节吗?我想写一个宏,我想在打开的任何工作表中使用它。换句话说,一个选项是编写我想要的宏一次,然后复制并粘贴到特定工作表的宏区域,然后在该工作表上运行它。但是,复制和粘贴操作所需的时间与手动格式化所需的时间相同(就像我现在所做的那样)。是否可以打开一张工作表,然后运行存储在不同工作表中的宏,对当前工作表进行操作?谢谢您的回复。从您的回复中,我无法理解我想在打开的任何工作表中使用的
    任何工作表
    。我为此道歉。在这种情况下,在一个谷歌电子表格中有几个表格?或者有几个谷歌电子表格,包括一个工作表?你可以创建一个脚本在。一旦csv到达“驱动程序”>“可以编程方式导入为电子表格”>“根据需要从同一宏修改每个电子表格”。您对ale13的回答是正确的(尽管ale13的回答本身是不正确的,这意味着“tab”而不是文件)。请注意,“工作表”是指“电子表格”(工作簿或文件)中的制表符@TheMaster无需如此,您在回答中对此进行了澄清。谢谢。很遗憾,我无法理解我打开的任何工作表都可以使用的
    宏。我为此道歉。我可以问你目标的细节吗?我想写一个宏,我想在打开的任何工作表中使用它。换句话说,一个选项是编写我想要的宏一次,然后复制并粘贴到特定工作表的宏区域,然后在该工作表上运行它。但是,复制和粘贴操作所需的时间与手动格式化所需的时间相同(就像我现在所做的那样)。是否可以打开一张工作表,然后运行存储在不同工作表中的宏,对当前工作表进行操作?谢谢您的回复。从您的回复中,我无法理解我想在打开的任何工作表中使用的
    任何工作表
    。我为此道歉。在这种情况下,在一个谷歌电子表格中有几个表格?或者有几个谷歌电子表格,包括一个工作表?你可以创建一个脚本在。一旦csv到达“驱动程序”>“可以编程方式导入为电子表格”>“根据需要从同一宏修改每个电子表格”。您对ale13的回答是正确的(尽管ale13的回答本身是不正确的,这意味着“tab”而不是文件)。请注意,“工作表”是指“电子表格”(工作簿或文件)中的制表符@TheMaster无需如此,您在回答中对此进行了澄清。谢谢。这似乎是一个很好的解决方案!我找不到任何参考资料,其中包括一个在目录中的电子表格文件上运行的脚本。我将开始编写代码,并且假设我没有遇到一些不可预见的障碍,我将再次将您的代码标记为“解决方案”。谢谢!这似乎是一个很好的解决方案!我找不到任何参考资料,其中包括一个在目录中的电子表格文件上运行的脚本。我将开始编写代码,并且假设我没有遇到一些不可预见的障碍,我将再次将您的代码标记为“解决方案”。谢谢!