简体   繁体   English

如何在谷歌应用脚本中的 CSV 文件中添加一列(具有 static 值)?

[英]How can I add a column (with a static value) to a CSV file in google apps script?

I'm trying to load a CSV google drive file to bigtable, similar to the load CSV example here: https://developers.google.com/apps-script/advanced/bigquery我正在尝试将 CSV 谷歌驱动器文件加载到 bigtable,类似于此处的加载 CSV 示例: https://developers.google.com/appced-script/

However, the CSV file is missing a column.但是,CSV 文件缺少一列。 I want to add a column and the value in that column (for every row) will be the name of the file.我想添加一列,该列中的值(对于每一行)将是文件的名称。 The problem I have is that I don't know how to add that column to the data before uploading to BigTable.我遇到的问题是,在上传到 BigTable 之前,我不知道如何将该列添加到数据中。

Moreover, I need to do it in a way that isn't too expensive: I have thousands of CSV files (each with thousands of rows).此外,我需要以一种不太昂贵的方式进行操作:我有数千个 CSV 文件(每个文件都有数千行)。 The method in that link allows me to access the file and pass the entire file/blob to bigtable in one line, not one row at a time.该链接中的方法允许我访问文件并将整个文件/blob 传递给 bigtable 一行,而不是一次一行。 I'd like to maintain that efficiency if possible.如果可能的话,我想保持这种效率。

(I'm basically taking all rows from every CSV file and combining them into one bigtable with an additional column to indicate which file they came from) (我基本上是从每个 CSV 文件中取出所有行,并将它们组合成一个带有附加列的大表,以指示它们来自哪个文件)

You can use Utilities.parseCSV() and then Array.unshift() to add a column on the beginning of each row or Array.splice() to put them anywhere you want.您可以使用 Utilities.parseCSV() 然后使用 Array.unshift() 在每行的开头添加一列,或者使用 Array.splice() 将它们放在您想要的任何位置。 When you're done with that you might be able to use Array.join() to get them back into strings.完成后,您可以使用 Array.join() 将它们重新转换为字符串。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 gs 文件中的变量作为 Google Apps 脚本中 HTML 文件的输入值? - How can I use the variable in the gs file as the input value in the HTML file in Google Apps script? 如何在 Google Apps 脚本中解决这个问题? - How can I solve this in Google Apps Script? 如何在 Google Sheets Apps 脚本 CSV 导入中保留现有格式 - How Can I Preserve Existing Formatting on a Google Sheets Apps Script CSV Import 如何将值插入到 a.csv 文件中的列 - How can i insert a value to a column in a .csv file 我可以向 Google Apps 脚本类添加自定义方法吗? - Can I add custom methods to Google Apps Script classes? 如何将变量从HTML脚本文件传递到Google Apps脚本中的javascript函数? - How can I pass a variable from an HTML script file to a javascript function in google apps script? 使用 getRange() 时如何跳过一列 - Google Apps 脚本 - How can I skip a column when using getRange() - Google Apps Script 如何在 Google Apps 脚本中为前端 HTML 中的表单添加验证? - How can I add validation to a form in front end HTML in Google Apps Script? 我基于电子表格列中的变量在 Google Apps 脚本中创建 PDF。 我无法让变量分配正确的值 - I am basing a variable on a spreadsheet column to create PDFs in Google Apps Script. I can't get the variable to assign the correct value 如何将HTML复选框的值传递给Google Apps脚本? - How do I pass the value of a HTML checkbox to Google Apps Script?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM