2016-07-22 6 views
0

私はイタリアのアンドリューです!異なるデータ間に行を挿入

私は、スプレッドシート内のいくつかのデータの間に空白行を挿入するスクリプトを記述しようとしています。

例は、私は、このデータセットがあります。

starting data set

を、私はこのような何か入手したい:

スクリプトは以下を行う必要がありますつまり

final data set

をすべての行をチェックし、日付の変更と名前の変更があった場合は、空の行を追加する必要があります。

このことについて任意のアイデア? 私はシートで空白の行を削除するスクリプトを修正しようとしましたが、結果は得られません。

ありがとうございます!

+1

私はすべてのデータを得るでしょう、プロセスそれは、構築空白行で設定された新しいデータは、その後、元のデータを上書きします。あなたのsuggestioneため –

+0

@SandyGoodのおかげ。私は、空白行を追加し、異なる場合は、以前のものとのセルの内容を比較し、何かを書くしようとしている。I」コーディングでMは良いではない。あなたは?と –

答えて

2

(:私はここにあなたが始めることができますコードの一部だ、ちょうど私の頭の上の...サンディ良いと同意:

function doSomething() { 
var spreadsheet = SpreadsheetApp.openById('yourID'), // Get the spreadsheet 
    tab = spreadsheet.getSheets()[0], // Get the first tab 
    values = tab.getRange(2, 1, tab.getLastRow(), 3).getDisplayValues(), //Get the values beginning in the second row because of the headers 
    newValues = [], // Empty array where we're gonna push the new values 
    lastDate, 
    lastName; 

// Loop through all the values 
for(var i = 0; i <values.length; i++){ 
    // If the last name is different from the current name or the last date is different from the current date add an empty "row" to the new array 
    if((lastDate != undefined && lastName != undefined) && (values[i][0] != lastDate || values[i][1] != lastName)){ 
    newValues.push(['','','']); 
    } 

    //Add the current row to the new array 
    newValues.push(values[i]); 

    //Sets the lastDate and lastName to the current values for the next evaluation 
    lastDate = values[i][0]; 
    lastName = values[i][1]; 
} 

//Sets the new values 
tab.getRange(2,1,newValues.length,3).setValues(newValues) 

} 
+0

感謝を開始するためにいくつかの例を持っています!これは私がdinamically列の数に基づいて、「プッシュ引数」を変更したい場合は?私はサイクルのために試してみました何が良い解決策は!(あります"、" '"何回もcolの数を書く欄)が動作しません。私は変数を配列にプッシュできないと思う。なにか提案を? –

関連する問題