How to use the node-xlsx.build 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 suvllian / learning / Node / others / import-export-excel / node-xlsx / index.js View on Github external
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)

fs.writeFile("test.xlsx", buffer,  "binary",function(err) {
    if(err) {
        console.log(err);
    } else {
        console.log("The file was saved!");
    }
});
github cxq / sfcc-images-cleaner / scripts / exportResults.js View on Github external
function createRow(index) {
        let row = [];
        row.push(data.xmlImages[index] || '');
        row.push(data.folderImages[index] || '');
        row.push(data.copiedImages[index] || '');
        row.push(data.skippedImages[index] || '');
        return row;
    }

    const rows = [];
    rows.push(headers);
    for (let i = 0, l = totalLines; i < l; i++) {
        rows.push(createRow(i));
    }
    const xlsBuffer = xlsx.build([{name: 'exportSFCCResults', data: rows}]);

    // If extension is missing, we fallback to CSV
    if (path.extname(outputFile) === '') {
        outputFile = outputFile + '.csv';
    }

    // Create the worksheet
    return fs.outputFile(outputFile, xlsBuffer).then(() => {
        const results = performance.stop();
        console.log(`Finished '${chalk.cyan('Export Excel report')}' after ${chalk.magenta(results.time + 'ms')}`);
        return {};
    });
}
github rickbergfalk / sqlpad / server / models / resultCache.js View on Github external
function writeXlsx(cacheKey, queryResult) {
  // loop through rows and build out an array of arrays
  const resultArray = [];
  resultArray.push(queryResult.fields);
  for (let i = 0; i < queryResult.rows.length; i++) {
    const row = [];
    for (let c = 0; c < queryResult.fields.length; c++) {
      const fieldName = queryResult.fields[c];
      row.push(queryResult.rows[i][fieldName]);
    }
    resultArray.push(row);
  }
  const xlsxBuffer = xlsx.build([{ name: 'query-results', data: resultArray }]);
  return new Promise(resolve => {
    fs.writeFile(xlsxFilePath(cacheKey), xlsxBuffer, function(err) {
      // if there's an error log it but otherwise continue on
      // we can still send results even if download file failed to create
      if (err) {
        console.log(err);
      }
      return resolve();
    });
  });
}
github eJayYoung / auto-translate-converter / lib / build.js View on Github external
function generateMCMSxlsx(chnArr) {
  const tempPath = config.templatePath
    ? `${path.resolve(config.templatePath)}`
    : `${path.join(path.resolve(__dirname, '..'), '/template/mcms_intl-i18nadmin_en_US.xlsx')}`;
  const template = xlsx.parse(fs.readFileSync(tempPath));
  template[0].data = template[0].data.concat(chnArr);
  const newBuffer = xlsx.build(template);
  const xlsxPath = `${process.cwd()}${path.sep}${config.prefix}_i18n.xlsx`;
  try {
    fs.writeFileSync(xlsxPath, newBuffer);
    console.timeEnd('generate MCMSxlsx');
    console.log(`build success ${xlsxPath}`.green);
    console.log(`words count: ${chnArr.length}`);
  }catch(e) {
    throw new Error(`build failed: ${e}`);
  }
}
github DavidCai1993 / awesomeOaSystem / app / controllers / citygovproj.js View on Github external
CitygovprojService.getAll(function (err, citygovprojs) {
      if (err) {
        console.log(err);
        citygovprojs = [];
      }

      var data = CitygovprojService.getDataForExcel(citygovprojs);

      var buffer = xlsx.build([{name: _tmpFileName, data: data}]);

      fs.writeFile(path.join(__dirname, "../../public/excel/", _tmpFileName), buffer, function (err) {
        if (err) console.log(err);
        res.download(path.join(__dirname, "../../public/excel/", _tmpFileName), '市政项目.xlsx', function (err) {
          if (err) console.log(err);
          fse.remove(path.join(__dirname, "../../public/excel/", _tmpFileName), function (err) {
            if (err) console.log(err)
          });
        });
      });

    });
  });
github SAP / com.sap.openSAP.hana5.example / core_js / router / routes / excel.js View on Github external
(err, rs) => {
						if (err) {
							res.type("text/plain").status(500).send(`ERROR: ${err.toString()}`);
						} else {
							var out = [];
							for(let item of rs){ 
								out.push([item["PurchaseOrderId"], item["PartnerId"], item["CompanyName"], item["CreatedByLoginName"],  item["CreatedAt"], item["GrossAmount"]]);
							}
							var result = excel.build([{
								name: "Purchase Orders",
								data: out
							}]);
							res.header("Content-Disposition", "attachment; filename=poWorklist.xlsx");
							res.type("application/vnd.ms-excel").status(200).send(result);
						}
					});
			});
github iNuanfeng / node-spider / build / buildExcel.js View on Github external
async function writeXls(datas, xlsName) {
  var buffer = xlsx.build([{
    name: 'sheet1',
    data: datas
  }]);
  await writeFile(path.join(__dirname, `../dist/${xlsName}.xlsx`), buffer, {
    'flag': 'w'
  }); //生成excel
}
github wificoin-project / wwas / controller / device / device.js View on Github external
async export(req, res, next) {
        var user = req.body.user_account;
        var query = await DeviceModel.find({ 'channelPath': user }).exec();
        var macs = [];
        for (var i = 0; i < query.length; i++) {
            macs.push([query[i].gwId]);
        }
        var datas = xlsx.build([
            { name: user, data: macs }
        ]);
        var time = moment().format('YYYYMMDDHHMMSS');
        var file_path = '/device/' + time + '.xlsx';
        var write_path = './public' + file_path;
        fs.writeFileSync(write_path, datas, { 'flag': 'w' });
        res.send({ ret_code: 0, ret_msg: 'SUCCESS', extra: file_path });
    }
github itagn / excel-merge / lib / core.js View on Github external
function mergeMutiple(resource, tag){
        let destObj = excel.parse(destFile), resourceObj = excel.parse(resource);
        let buildArr = [];
        for(let i=0;i
github SAP / com.sap.openSAP.hana5.example / core_node / router / routes / myNode.js View on Github external
app.get("/products", async(req, res) => {
		try {
			let dbClass = require(global.__base + "utils/dbPromises");
			let dbConn = new dbClass(req.db);
			var hdbext = require("@sap/hdbext");
			const sp = await dbConn.loadProcedurePromisified(hdbext, null, "build_products");
			const output = await dbConn.callProcedurePromisified(sp, {});
			var out = [];
			for (let result of output.results) {
				out.push([result.PRODUCTID, result.CATEGORY, result.PRICE]);
			}
			var excel = require("node-xlsx");
			var excelOut = excel.build([{
				name: "Products",
				data: out
			}]);
			res.header("Content-Disposition", "attachment; filename=Excel.xlsx");
			return res.type("application/vnd.ms-excel").status(200).send(excelOut);
		} catch (err) {
			return res.type("text/plain").status(500).send(`ERROR: ${err.toString()}`);
		}
	});

node-xlsx

NodeJS Excel files parser & builder

Apache-2.0
Latest version published 7 months ago

Package Health Score

71 / 100
Full package analysis