function writeData () {
var sss= SpreadsheetApp.getActiveSpreadsheet();
//var inSheet2 = sss.getSheetByName('Copy of 01-Raw Data 2');
var inSheet2 = sss.getSheets()[4];
var input2 = inSheet2.getRange(2, 1, inSheet2.getLastRow(),42);
var outSheet1 = sss.getSheets()[0];
var outStartRow2 = outSheet1.getLastRow() + 2;
var outStartRow3 = outSheet1.getLastRow() + 2;
input2.copyFormatToRange(outSheet1, 2, 42, outStartRow3, outStartRow2);
var ss = SpreadsheetApp.getActiveSpreadsheet();
var inSheet = sss.getSheets()[0];
var input = inSheet.getRange(2, 18, inSheet.getLastRow(), 42).getValues();
var outSheet2 = sss.getSheets()[4];
var outStartRow = outSheet2.getLastRow() + 1;
for (var col = 0; col < input.length; col++) {
for (var row = 0; row < input[col].length; row++) {
outSheet2.getRange(outStartRow + row, col + 5)
.setValue(input[col][row]);
}
}
}
function onOpen() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var menuEntries = [];
menuEntries.push({name: "Write data", functionName: "writeData"});
ss.addMenu("Custom functions", menuEntries);
}
我在Google电子表格中使用google-apps-script。
我有什么:
我想要实现的目标:
如果你有办法正确地做到这一点,请告诉我。
答案 0 :(得分:0)
守则:
function myFunction() {
var ss=SpreadsheetApp.getActive();
var sh0=ss.getSheetByName('INPUT');
var sh1=ss.getSheetByName('OUTPUT');
var rg0=sh0.getDataRange();
var vA=rg0.getValues();
var oA=[];
for(var i=0;i<vA.length;i++)
{
for(var j=0;j<vA[0].length;j++)
{
if(vA[j][i])
{
oA.push([vA[j][i]]);
}
else
{
for(var k=0;k<j;k++)
{
oA.pop();
}
break;
}
}
}
sh1.getRange(1,1,oA.length,oA[0].length).setValues(oA);
}
数据表:
输出表: