简体   繁体   中英

Adding a comma separated strings to an array

I'm trying to add comma separated spreadsheet values to an array using Google Apps Script. Let's call the cells I'm looking at A1, B1 and C1. All of them contain text, to be more precise these are the exact values:

A1="a"; B1="b,c,d"; C1="e"

Using the function below I get the following result in my console

[[a,b,c,d,e]]

If I want to paste them back into the spreadsheet I end up with

A1="a"; B1="b"; C1="c"; D1="d"; E1="e";

This problem is probably related to the comma separated values in B1 because the array should actually look similar to this:

[["a","b,c,d","e"]]

Replacing the commas is no option. Any ideas to tackle my problem are appreciated!

Code snippet:

function valuesToArray(){
            
var ss = SpreadsheetApp.getActiveSpreadsheet();
var worksheet = ss.getSheetByName("Worksheet");
var range = worksheet.getRange(1,1,1,3).getValues();

Logger.log(range);
    
}
function loadCsv(csv) {
  const ss=SpreadsheetApp.getActive();
  const sh=ss.getSheetByName('Worksheet');
  const vs=Utilities.parseCsv(csv);
  sh.getRange(1,1,vs.length,vs[0].length).setValues(vs);
}

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