How to use the node-xlsx.parse function in node-xlsx

To help you get started, we’ve selected a few node-xlsx examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github FE-Kits / Ueact / packages / ueact-i18n / lib / replace.js View on Github external
module.exports = function () {
  const xlsxBuffer = xlsx.parse(fs.readFileSync(`${process.cwd()}${path.sep}${config.prefix}_i18n.xlsx`));
  const callDef = config.customCall;
  let successCount = 0;
  const notMatchZhArr = [];
  const writeFileList = [];
  const newChnMap = {};
  xlsxBuffer[0].data.slice(1).reduce((cur, next) => {
    if (!newChnMap[next[2]]) {
      newChnMap[next[3]] = next[2];
    }
  }, []);
  const files = utils.getFiles();
  files.map((file, i) => {
    // 如果是en.js文件,则跳过,后面和zh-cn.js一起处理
    if (/i18n\/en\.js$/g.test(file)) {
      return;
    }
github suvllian / learning / Node / others / import-export-excel / node-xlsx / index.js View on Github external
const xlsx = require('node-xlsx')
const fs = require('fs')

// Parse a buffer
const workSheetsFromBuffer = xlsx.parse(fs.readFileSync(`${__dirname}/index.xlsx`));
// Parse a file
const workSheetsFromFile = xlsx.parse(`${__dirname}/index.xlsx`);

console.log(workSheetsFromBuffer)
console.log(workSheetsFromFile)

const data = [
  [1, 2, 3], 
  [true, false, null, 'sheetjs'], 
  ['foo', 'bar', new Date('2014-02-19T14:30Z'), '0.3'],
  ['baz', null, 'qux']
]

// Returns a buffer
const buffer = xlsx.build([{name: "mySheetName", data: data}]); 

console.log(buffer)
github lss5270 / vue-admin-spa-api / router / uploadRouter.js View on Github external
function excel2json(res,excelPath){
    // var xlsx = require('node-xlsx');
    // var fs = require('fs');
    //读取文件内容

    console.log('------11122-',excelPath)
    let _excelPath = path.resolve(__dirname, '../'+excelPath);
    // let obj = xlsx.parse(__dirname+'./../'+excelPath); //2次上传路径 经常解析错误。(目测是文件写入需要时间)
    let obj = xlsx.parse(_excelPath); //2次上传路径 经常解析错误。(目测是文件写入需要时间)

    let excelObj=obj[0].data;
    // console.log('解析的json--------',excelObj);
    /*[ [ '时间', '公司入款', '线上支付', '人工存入', '充值合计' ],
     [ '2017-9-17', '33366', '22', '111', '466' ],
     [ '2017-9-19', '100190', '1', '1', '3' ],
     [ '2017-9-18', '2', '2', '2', '6' ] ]*/

    for(var i = 1, len = excelObj.length;i < len; i++) {
        //定义提交入参
        let insertData = {};
        let item = excelObj[i];

        for(j in item){
            
            insertData[arr[j]] = item[j]
github RodgerLai / nodejs-nedb-excel / server / routes / gzh.js View on Github external
fs.rename(uploadedPath, dstPath, function(err) {
        if(err){
          console.log('rename error: ' + err);
        } else {
          console.log('rename ok');

          //读取文件内容
          var obj = xlsx.parse(dstPath);
         // console.log(obj[0].data);
          var sheet = obj[0];
         // console.log(sheet);
          var datas = sheet.data;
          console.log(datas[0]);
              datas.splice(0,1)//去除头部: 序号	公众号	ID	分类	粉丝数/w	头条/元	二条/元	三条/元	四条/元	备注
                              //	是否开通评论功能	阅读量	是否认证	媒体手机	媒体QQ	折扣	下次更新时间	商务对接
          //console.log(datas);
           var model_arr = datas.reduce(gzhModel.gzhReducer,[]);
           //console.log(model_arr);
           //console.log(model_arr.length);
           //gzhDao.add(model_arr,res,next);   
           res.json({"data":"导入成功"+model_arr.length+"条微信报价单数据","errorMsg":"","success":true,"totalCount":model_arr.length});   
            
        }   
      });
github dondi / GRNsight / test / additional-sheet-parser-tests.js View on Github external
it("handles missing data in _expression sheets", function () {
        var workbook = xlsx.parse(__dirname + "/../test-files/spreadsheet-controller-test-files/" +
        "log2_expression_with_missing_data.xlsx");
        var data = parseAdditionalSheets(workbook);
        assert(data,
            {"expression": {
                "wt_log2_expression": {
                    "time_points": [15, 15, 15, 15, 30, 30, 30, 30, 30, 60, 60, 60, 60],
                    "data": {
                        "ACE2":[0.6139, -1.0689, 0.1906, -0.398, 0.5827, null,
                            -0.3947, -0.6264, 0.3377, 0.817, 0.5566, -0.4357, -1.2497],
                        "ASH1":[0.97, 0.3043, -0.9904, -0.2636, -0.382, 0.4206, -0.4911,
                            -0.1284, -0.7236, -1.3477, -1.0468, -1.0978, -0.9248],
                        "ZAP1":[0.6594, 0.6135, 0.3238, -0.3712, 1.4712, 1.9049, 0.599,
                            -0.2354, -0.394, 2.9606, 3.5569, 1.3863, null]
                    }
                }
            },
github vmware / singleton / autotest / client / jscoresdk / utils / excelreader.ts View on Github external
readsheet_with_sheetname(sheetname: string) {
        var data = null;
        const workSheetsFromFile = xlsx.parse(this.file);
        for (const i in workSheetsFromFile) {
            let sheet = workSheetsFromFile[i];
            if (sheet.name == sheetname) {
                data = sheet.data;
                break;
            }
        }

        return this.convertdata(data);
    }
github eebhub / platform / routes / substantial.js View on Github external
exec(command, function(err2, stdout2, stderr2) {

		var str = '';
		var filename1 = '../utrc/Output_StageI.csv';
		fs.readFile(filename1, 'utf8', function(err, data) {   
			str = str + data.to_s;
		});
		console.log(str);
		var arr = str.split(/[,\n]+/);
		arr.splice(0,3);

		console.log(arr);
         
        var data1 = xlsx.parse('../utrc/Output_StageI.xlsx'); 
        var elec_heat01 = data1.worksheets[4].data[1][1].value;
        var elec_heat02 = data1.worksheets[4].data[1][2].value;
        var elec_heat03 = data1.worksheets[4].data[1][3].value;
        var elec_heat04 = data1.worksheets[4].data[1][4].value;
        var elec_heat05 = data1.worksheets[4].data[1][5].value;
        var elec_heat06 = data1.worksheets[4].data[1][6].value;
        var elec_heat07 = data1.worksheets[4].data[1][7].value;
        var elec_heat08 = data1.worksheets[4].data[1][8].value;
        var elec_heat09 = data1.worksheets[4].data[1][9].value;
        var elec_heat10 = data1.worksheets[4].data[1][10].value;
        var elec_heat11 = data1.worksheets[4].data[1][11].value;
        var elec_heat12 = data1.worksheets[4].data[1][12].value;

        var elec_heat = [elec_heat01,elec_heat02,elec_heat03,elec_heat04,elec_heat05,elec_heat06,elec_heat07,elec_heat08,elec_heat09,elec_heat10,elec_heat11,elec_heat12];
        
        var elec_pump01 = data1.worksheets[4].data[2][1].value;
github Jiasm / notebook / javascript / readExcel.js View on Github external
'use strict';

var fs = require('fs');
var xlsx = require("node-xlsx");

var buffer = xlsx.parse(fs.readFileSync(`${__dirname}/file2.xlsx`));
console.log(buffer);
github twem007 / p1 / code / tools / ConfigTools / out / main.js View on Github external
}
    var serverDir = outPath + "\\server";
    if (!fs.existsSync(serverDir)) {
        fs.mkdirSync(serverDir);
    }
    //创建客户端代码结构
    var defFileStr = "/**\n * \u8BE5\u6587\u4EF6\u4E3A\u5DE5\u5177\u81EA\u52A8\u751F\u6210\uFF0C\u8BF7\u52FF\u81EA\u884C\u4FEE\u6539\u3002\n *\n */\n";
    var templete = "export class {0} {\n{1}}\n";
    //读取文件
    if (files) {
        for (var i = 0, iLen = files.length; i < iLen; i++) {
            var file = files[i];
            if (file.indexOf('.xlsx') >= 0) {
                console.log("\u8BFB\u53D6\u6587\u4EF6\uFF1A" + file);
                var buffer = fs.readFileSync(xlsxPath + "\\" + file);
                var sheets = xlsx.parse(buffer);
                if (sheets.length == 0) {
                    return;
                }
                var sheet = sheets[0];
                var sheetData = sheet.data;
                //解析结构数据
                var fileName = sheetData[0][1];
                var remarks = sheetData[1];
                var channels = sheetData[3];
                var keys = sheetData[4];
                var types = sheetData[5];
                //创建客户端配置定义代码
                var keyTemplate = "";
                for (var i_1 = 0, iLen_1 = keys.length; i_1 < iLen_1; i_1++) {
                    var channel = channels[i_1];
                    switch (channel & 1) {
github yinfxs / ibird / lib / utils / excel.js View on Github external
app.import = (file, options) => {
    if (!path.isAbsolute(file)) file = path.resolve(process.cwd(), file);
    const sheets = xlsx.parse(file);
    if (!options || _.keys(options).length == 0) return sheets;
    const data = {};
    sheets.forEach((sheet) => {
        const name = sheet.name;
        const rows = sheet.data;
        const option = options[name];
        if (!option || option.json == undefined || option.json == false) return data[name] = rows;
        if (parseInt(option.keyRowIndex) >= rows.length) return;
        const keys = rows[option.keyRowIndex];
        const dataItems = [];
        for (let i = option.keyRowIndex + 1; i < rows.length; i++) {
            //循环数据行
            const object = {};
            const row = rows[i];
            keys.forEach((key, j) => {
                if (!key) return;

node-xlsx

NodeJS Excel files parser & builder

Apache-2.0
Latest version published 7 months ago

Package Health Score

71 / 100
Full package analysis