ヘッダーの下に複数の行のデータを追加しようとしています。これは新しいテーブルになります。これらはすべて同じイベントハンドラで実行されます。アドインを使用して一度に複数の行をExcelに追加するにはどうすればよいですか?
現在、テーブルはになります。ヘッダーとヘッダーの値も同じです。ただし、データの行はロードされません。
ここで私はテーブルを作成し、ヘッダと行を移入するために持っているコードです:
function createTable() {
Excel.run(function (context) {
const currentWorksheet = context.workbook.worksheets.getActiveWorksheet();
const expensesTable = currentWorksheet.tables.add("A1:D1", true /*hasHeaders*/);
expensesTable.name = "ExpensesTable";
expensesTable.getHeaderRowRange().values =
[["Date", "Merchant", "Category", "Amount"]];
expensesTable.rows.add(null /*add at the end*/, [
["1/1/2017", "The Phone Company", "Communications", "120"],
["1/2/2017", "Northwind Electric Cars", "Transportation", "142.33"],
["1/5/2017", "Best For You Organics Company", "Groceries", "27.9"],
["1/10/2017", "Coho Vineyard", "Restaurant", "33"],
["1/11/2017", "Bellows College", "Education", "350.1"],
["1/15/2017", "Trey Research", "Other", "135"],
["1/15/2017", "Best For You Organics Company", "Groceries", "97.88"]
]);
expensesTable.columns.getItemAt(3).getRange().numberFormat = [['€#,##0.00']];
expensesTable.getRange().format.autofitColumns();
expensesTable.getRange().format.autofitRows();
return context.sync();
})
.catch(function (error) {
console.log("Error: " + error);
if (error instanceof OfficeExtension.Error) {
console.log("Debug info: " + JSON.stringify(error.debugInfo));
}
});
}
これは、このエラーを生成します:
Error: InvalidArgument: The argument is invalid or missing or has an incorrect format.
Debug info: {
"code":"InvalidArgument",
"message":"The argument is invalid or missing or has an incorrect format.",
"errorLocation":"TableRowCollection.add"
}
私はtableRowCollectionについてthe JS API docsを読んでてきたが、オブジェクトとそのメソッドを追加しますが、ここで間違っていることはわかりません。どんな助けでも素晴らしいでしょう!
私は最初にnullの代わりに-1を試し、1行を追加します。 (デバッグの手順) –
これは良い提案です、Andyに感謝します。私はそれを試して、一度に1行(nullと-1の両方)を挿入するために動作します。おそらく私はよりよく質問するべきです、どうすればより多くの行/データを入力することができますか? –
これはまったく複製できません。あなたのコードは私のためにうまく動作しています。使用しているExcelのバージョンを教えてください。あなたは 'office.js'の参照方法を追加することもできますか? –