2

非常に基本的な質問のように感じて申し訳ありません。Excel テーブルを反復処理し、新しいアドイン モデルを使用して空の行を削除しようとしています。私は JavaScript にかなり慣れていないので、すべての非同期性とコールバックが私を複雑に結び付けています!

これは簡単だと思うので、誰かが簡単なコードサンプルを投稿するのに十分親切であるか、それを行うための最もクリーンな方法を提案する必要があるかどうか疑問に思いましたか? ドキュメントに記載されていない場合は申し訳ありません。

よろしくお願いします。

ティム

4

3 に答える 3

1

次のコードは、探していることを実行するはずです。

Excel.run(function(ctx) {
    var rows = ctx.workbook.tables.getItem('YourTableName').rows;
    rows.load("values"); // We'll need the rows values to check if they're empty.
    return ctx.sync().then(function() {
        // Important to go through the items in reverse fashion as deleting a row shifts the rest up.
        rows.items.reverse().forEach(function(row) {
            // row.values is a double array. Although, we know it can only contain one row.
            var isEmpty = row.values[0].every(function(col) {
                return col === "";
            });

            if (isEmpty) {
                row.delete();
            }
        });
    }).then(ctx.sync);
}).catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});

それが役立つことを願って、

Gabriel Royer - Office Extensibility Team の開発者、MSFT

于 2015-12-01T00:26:16.010 に答える
-4

基本的な作業を行うには、マクロ レコーダー機能を使用することをお勧めします。次に、空の行テストを含む基本的な For Each Cell ループ内でそれを使用して、ジョブを実行します。

于 2015-11-30T14:49:21.893 に答える