现在edge已经不支持activexobject了,如果想用javascript操作excel文件,基本上只能用nodejs了。下面的代码就是用nodejs操作excel文件的可用方法,读取每个cell,设置颜色。
// save this content as excel.js file // # npm i exceljs // # node excel.js const ExcelJS = require('exceljs'); async function ProcessSheet(sheet) { let rows=sheet.rowCount, cols=sheet.columnCount; console.log(` ${rows} rows, ${cols} cols`); for(let row=1; row<=rows; row++) { let r=sheet.getRow(row); if(row==1) { if(!r.font) r.font={}; r.font.color={ argb: 'FFFF0000'}; } for(let col=1; col<=cols; col++) { let cell=r.getCell(col); let v=cell.value; console.log(` [${row}, ${col}] ${v}`); } } } async function ProcessFile(ExcelFilePath) { const workbook = new ExcelJS.Workbook(); await workbook.xlsx.readFile(ExcelFilePath); let sheets=workbook.worksheets, sheetsCount=sheets.length; for(let sheet_index=0; sheet_index
还没有评论,来说两句吧...