如何将数据集一个一个地拆分?

How to split a data set one below the other?

有一个googlesheet坐标集。它在单个单元格内有很多坐标值。如下图所示。 这里的坐标为 N、E、Z。在第一个坐标 1 之后,我们转到同一单元格内的下一行。我试图将我想要的那些分开为一个单元格,但它没有用。

    function sepCoordi() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName("Coordi");

  //get data to array
  var coor = sheet.getRange("A2:B47").getValues();
  var one = coor[0][1];
  Logger.log(one);

  var onesplit = one.split(" ");
  Logger.log(onesplit);  
}

结果

这就是我想要的[[80.091821,6.842871,98.23][80.091861,6.842881,106.1][80.091905,6.842894,109.25][....][....]]

在您的脚本和显示的电子表格中,进行以下修改如何?

修改后的脚本:

function sepCoordi() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName("Coordi");
  var coor = sheet.getRange("A2:B47").getValues();
  
  // I modified below script.
  var values = coor.flatMap(([,b]) => b.split("\n").map(e => e.split(",").map(f => f.trim())));
  console.log(values)
}

参考:

重构数据

function restructure() {
  var ss = SpreadsheetApp.getActive();
  var sh = ss.getSheetByName("Sheet0");
  var vs = sh.getRange("A1:B5").getValues().map(r => r[1].split('\n')).flat().map(e => e.split(','));
  console.log(vs);
  sh.getRange(1,3,vs.length,vs[0].length).setValues(vs);
}

Sheet 0:

Execution log
4:24:45 PM  Notice  Execution started
4:24:45 PM  Info    [ [ '1', '2', '3' ],
  [ '4', '5', '6' ],
  [ '7', '8', '9' ],
  [ '10', '11', '12' ],
  [ '1', '2', '3' ],
  [ '4', '5', '6' ],
  [ '7', '8', '9' ],
  [ '10', '11', '12' ],
  [ '1', '2', '3' ],
  [ '4', '5', '6' ],
  [ '7', '8', '9' ],
  [ '10', '11', '12' ],
  [ '1', '2', '3' ],
  [ '4', '5', '6' ],
  [ '7', '8', '9' ],
  [ '10', '11', '12' ],
  [ '1', '2', '3' ],
  [ '4', '5', '6' ],
  [ '7', '8', '9' ],
  [ '10', '11', '12' ] ]
4:24:46 PM  Notice  Execution completed

发布到 Sheet0:

C D E
1 2 3
4 5 6
7 8 9
10 11 12
1 2 3
4 5 6
7 8 9
10 11 12
1 2 3
4 5 6
7 8 9
10 11 12
1 2 3
4 5 6
7 8 9
10 11 12
1 2 3
4 5 6
7 8 9
10 11 12

Array Methods