一種の「スタック」を作成したいのですが、アイテムを削除するたびに、シートは空白のセルを削除します。明らかに、これにはフィルター関数を使用できません。
この目的のために作成された配列の読み取りに問題があります。
私の非常に疑似コード:空の配列を作成し、すべての値(空のものを含む)を取得し、空のものを除くすべての値を配列に入力し、最後にスタックをクリアして配列で値を設定します。
これが私のコードです:
function updateStack() {
var ss = SpreadsheetApp.getActive();
var sheet = ss.getSheetByName("main");
var zone = sheet.getRange(1, 1, 1, 10);
//seems that .getValues() returns a 2d array
var values = zone.getValues();
var j = 0;
var data = new Array();
for (var i = 0 ; i < 10 ; i++) {
//the problem seems to be here : I can't access the 2d array. After reading the debugging console about 1000 thousand times
// I discovered the 2 pairs of []
//I've found multiple ways to detect empty cells. Not sure if this is the right one. I've tried the .length = 0 trick, but something
// was wrong, maybe because of the "2dimensionality"
if (values[i] != "") {
data[j] = values[i];
j = j++;
} else {
// do nothing if the cell contains nothing
}
//not sure if I have to use return ! Don't know where to put it exactly too...
return data;
zone.clear();
//length of range must be the same as the array's length
zone = sheet.getRange(1, 1, 1, data.length);
zone.setValues(data);
}
}
私のコードには多くのコメントがありますが、ご理解いただければ幸いです。テストシートへのリンク: http://bit.ly/1JiWutn
助けてくれてありがとう!