1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

exceljsの範囲指定方法

Posted at

このページを読んでわかること

  • exceljsを使って、Excelファイルに書き出すときのセルの指定方法

exceljs

使い方

  • 以下のような準備を行う

      var Excel = require('exceljs');   // 宣言する
      var workbook = new Excel.Workbook();   // Excelファイルの作成
      var sheet = workbook.addWorksheet("サンプル");   // シートの作成
    

指定方法

  • 一つのセルだけ指定 *B3のセルを指定する

      sheet.getCell('B3')
    

    もしくは

      sheet.getCell(3, 2)
    
  • 列での指定 *B列を指定する

      sheet.getColumn('B')
    

    もしくは

      sheet.getColumn(2)
    
  • 行での指定 *3行目を指定する

      sheet.getRow(4)
    

複数列複数行指定

  • 範囲選択方法がないので、for文を使う(もしあったら教えてください)以下ヘッダーに色をつける例

      var rowCount = data1.length;
      var colCount = data2.length;
    
      for (row = 1; row <= rowCount; row++) {
        for (col = 1; col <= colCount; col++) {
          sheet.getCell(row, col).fill = {
            type: 'pattern',
            pattern: 'solid',
            fgColor: { argb: 'ffdaeef3' }
          };
        }
      }
    
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?