[英]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.