简体   繁体   中英

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

However, the CSV file is missing a column. 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.

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). 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. 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)

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. When you're done with that you might be able to use Array.join() to get them back into strings.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM