0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

EXCELJS読み込み

Posted at
import ExcelJS from 'exceljs';

async function readExcelFile(filePath: string): Promise<string[]> {
    // Excelファイルを読み込むためのワークブックを作成
    const workbook = new ExcelJS.Workbook();
    await workbook.xlsx.readFile(filePath);

    // 1つ目のシートを取得
    const worksheet = workbook.getWorksheet(1);

    // A列の2行目以降の値を格納する配列
    const aColumnValues: string[] = [];

    // 2行目以降をループしてA列の値を取得
    worksheet.eachRow((row, rowNumber) => {
        if (rowNumber > 1) {
            const cellValue = row.getCell(1).text;  // A列の値
            aColumnValues.push(cellValue);
        }
    });

    return aColumnValues;
}

// 実行例
readExcelFile('path/to/your/excel/file.xlsx').then(aColumnValues => {
    console.log('A列の2行目以降の値:', aColumnValues);
});
import ExcelJS from 'exceljs';

async function readExcelFile(filePath: string): Promise<string[]> {
  const workbook = new ExcelJS.Workbook();
  await workbook.xlsx.readFile(filePath);

  const worksheet = workbook.getWorksheet(1); // 1番目のシートを取得
  const values: string[] = [];

  worksheet.eachRow((row, rowNumber) => {
    if (rowNumber > 1) { // 2行目以降を取得
      const cellValue = row.getCell('A').value;
      if (typeof cellValue === 'string' || typeof cellValue === 'number') {
        values.push(cellValue.toString());
      }
    }
  });

  return values;
}

// 使用例
(async () => {
  const filePath = 'path/to/your/excel-file.xlsx'; // Excelファイルのパス
  const values = await readExcelFile(filePath);
  console.log(values);
})();
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?