2017-05-24 62 views
0

で試行しました。cellValue = worksheet.getRow(1).getCell(1).value;TypeError:未定義のプロパティ 'getRow'を読み取ることができません。

と cellValue =はconsole.log(worksheet.getCell( 'A1'))

私のコードの下に見つけてください:

cellread2=function(){ 
     var Excel; 
     var filePath = path.resolve(__dirname,'E:/excel.xlsx'); 
     if (typeof require !== 'undefined') { 
        Excel = require('C:/Users/user/AppData/Roaming/npm/node_modules/exceljs/dist/exceljs'); 
     } 
     var wb = new Excel.Workbook(); 
     console.log(wb); 
     wb.xlsx.readFile(filePath); 
     var worksheet = wb.getWorksheet('Sheet1'); 
     //cellValue= worksheet.getRow(1).getCell(1).value;//Error :TypeError: Cannot read property 'getRow' of undefined 
     cellValue=console.log(worksheet.getCell('A1'))// TypeError: Cannot read property 'getCell' of undefined 
     console.log(cellValue); 


    } 

答えて

0

既存のライブラリのコードに問題があります。それを機能させたい場合は、ファイルAppData\Roaming\npm\node_modules\exceljs\dist\es5\xlsx\xform\sheet\worksheet-xform.jsの既存のコードを少し変更する必要があります。 284行目のコードを次のように置き換えます。

if (drawing.anchors && drawing.anchors.length > 0) { 
     drawing.anchors.forEach(function (anchor) {    
      if (anchor.medium && anchor.range) { 
      var image = { 
       type: 'image', 
       imageId: anchor.medium.index, 
       range: anchor.range 
      }; 
      model.media.push(image); 
      } 
     }); 
     } 

また、ファイルを読むためのコードは次のコードを使用してください。

注:私は、グローバルexceljsライブラリをインストールし、私はバージョン4.6.1

var path = require('path'); 
var Excel = require('exceljs'); 
var cellread2 = function() { 
    var filePath = path.resolve('E:', 'excel.xlsx'); 
    var wb = new Excel.Workbook(); 
    wb.xlsx.readFile(filePath).then(function (data) { 
    var worksheet = wb.getWorksheet('Sheet1'); 
    var cellValue = worksheet.getRow(1).getCell(1).value; 
    console.log('cellValue', cellValue); 
    }).catch(function (e) { 
    console.log(e); 
    }); 
} 
cellread2(); 
を使用しています
関連する問題