更新:请参阅下面的
我认为提出问题的最佳方式是描述目前的程序和我想执行的程序。当前程序:
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 Drive到特定的Google文件夹(例如"pendingCSV"(
-
点击此处创建新脚本
-
在此脚本中,获取特定文件夹中的所有文件。
-
将pendingCSV文件夹中的所有CSV转换为Google工作表。这可以用Utilities.parseCsv或Drive-api来完成。请参阅此处和此处的示例,并将转换后的电子表格放在另一个文件夹中,例如";pendingSpreadsheets";。
-
然后,脚本循环遍历pendingSpreadsheets中的每个文件,获取其id(
file.getId()
(,并使用(SpreadsheetApp.open(id)
(打开该文件。 -
一旦
file
被打开为Spreadsheet
,在循环中为所有其他file
的执行所有需要的格式化选项,如(设置粗体(和重复(步骤5(