「東雲 忠太郎」の平凡な日常のできごと

「東雲 忠太郎」の平凡な日常のできごと

2024.02.20
XML


async function updateData() {

  await Excel.run(async (context) => {

    // アクティブなワークシートを取得

    const sheet = context.workbook.worksheets.getActiveWorksheet();


    // テーブルを取得(テーブル名を適切なものに置き換えてください)

    const table = sheet.tables.getItem("Table1");


    // テーブルのデータを取得

    const tableRange = table.getDataBodyRange();

    tableRange.load("values");


    // ヘッダー行を取得

    const headers = table.getHeaderRowRange().load("values");


    // コンテキストの実行

    await context.sync();


    // テーブルのデータを取得

    const tableData = tableRange.values;

    // ヘッダー行のデータを取得

    const headerRow = headers.values[0];


    // 製品列のインデックスを見つける

    const productColumnIndex = headerRow.indexOf('製品');


    // 製品列のインデックスが見つかった場合

    if (productColumnIndex !== -1 && tableData.length > 0) {

      // 行番号1の製品データを更新

      const productData = '新しい製品データ';

      table.rows.getItemAt(0).getRange().getCell(0, productColumnIndex).values = [[productData]];

    }


    // コンテキストの実行(変更を反映)

    await context.sync();

  });

}


// 関数を実行

updateData().catch(console.error);







お気に入りの記事を「いいね!」で応援しよう

Last updated  2024.02.20 06:38:34
[OfficeScriptオフィススクリプト] カテゴリの最新記事


【毎日開催】
15記事にいいね!で1ポイント
10秒滞在
いいね! -- / --
おめでとうございます!
ミッションを達成しました。
※「ポイントを獲得する」ボタンを押すと広告が表示されます。
x

© Rakuten Group, Inc.
Design a Mobile Website
スマートフォン版を閲覧 | PC版を閲覧
Share by: