2017-05-24 8 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(); 
을 사용하고 있습니다
관련 문제