How to use the xlsx.readFile function in xlsx

To help you get started, we’ve selected a few 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 NGRP / node-red-contrib-viseo / node-red-contrib-file / node-file-xlsx.js View on Github external
}

  try  {

    // Get data
    if (config.save) {
      let saved = helper.getContextValue(RED, node, data, config.saveloc || '_sheet', config.savelocType);
      if (saved) {
        parameters.data = saved.data;
        parameters.cells = saved.cells;
        parameters.usedRange = saved.usedRange;
      }
    }
    if (!parameters.cells || typeof parameters.cells !== "object" || parameters.cells.length <= 0) {
      
      let sheets = XLSX.readFile(workbook);
      if (!sheets.Sheets || !sheets.Sheets[worksheet]) throw ({error: "Worksheet's name or ressource was not found"});
      else parameters.data = sheets;
      
      sheets = JSON.parse(JSON.stringify((sheets.Sheets[worksheet])));
      parameters.usedRange = sheets["!ref"];
      delete sheets["!ref"];

      
      let res = (parameters.usedRange) ?  getValues(parameters.usedRange, sheets) : [];
      if (config.save) {
        helper.setContextValue(RED, node, data, config.saveloc || '_sheet', {usedRange : parameters.usedRange, cells: res, data: parameters.data}, config.savelocType);
      }
      parameters.cells = [];
      for (let ob of res) parameters.cells.push(Array.from(ob));
      
    }
github rdmurphy / node-copytext / index.js View on Github external
function process (rawXLSX, options) {
  // if no options are passed, set an empty Object as default
  options = options || {}

  // if no processor is set, assume `keyvalue`
  const defaultProcessor = options.processor || 'keyvalue'

  // if no overrides were set, assume there are none
  const overrides = options.overrides || {}

  // if the XLSX file came over as a Buffer, read it differently
  const workbook = rawXLSX instanceof Buffer ? XLSX.read(rawXLSX, {type: 'buffer'}) : XLSX.readFile(rawXLSX)

  // get the names of all the sheets in an Array
  const sheets = workbook.SheetNames

  // the eventual payload returned to the callback
  let payload = {}

  // for each sheet in the workbook process its contents
  sheets.forEach(function (sheet) {
    // determine the appropriate processor, using the override if it exists
    const processor = overrides.hasOwnProperty(sheet) ? overrides[sheet] : defaultProcessor

    // pass pass the sheet on to the process script with the correct processor
    payload[sheet] = getProcessor(processor)(workbook.Sheets[sheet])
  })
github EdgeVerve / feel / test / decision-service / decision-table-tests.spec.js View on Github external
it('should detect a sheet marked as a boxed context without result', function() {
    var workbook = XLSX.readFile(testDataFile2);

    var worksheet = workbook.Sheets["Applicant Data"];

    var csvExcel = XLSX.utils.sheet_to_csv(worksheet, { FS: '&SP', RS: '&RSP'});

    var result = DL._.isBoxedContextWithoutResult(csvExcel);

    expect(result).to.be.true;

  });
github SheetJS / sheetjs / demos / electron / index.js View on Github external
function handleF(/*e*/) {
		var o = electron.dialog.showOpenDialog({
			title: 'Select a file',
			filters: [{
				name: "Spreadsheets",
				extensions: "xls|xlsx|xlsm|xlsb|xml|xlw|xlc|csv|txt|dif|sylk|slk|prn|ods|fods|uos|dbf|wks|123|wq1|qpw|htm|html".split("|")
			}],
			properties: ['openFile']
		});
		if(o.length > 0) process_wb(XLSX.readFile(o[0]));
	}
	readf.addEventListener('click', handleF, false);
github digplan / json2xlsx / json2xlsx.js View on Github external
function readXLSX(filename) {
  return require('xlsx').readFile(filename).Sheets;
}
github SheetJS / j / j.js View on Github external
var readFileSync = function(filename/*:string*/, options/*:any*/)/*:JWorkbook*/ { return [X, X.readFile(filename, options)]; };
var read = function(data/*:any*/, options/*:any*/)/*:JWorkbook*/ { return [X, X.read(data, options)]; };
github rdmurphy / node-copytext / src / index.ts View on Github external
export function process(
  file: string | Buffer,
  {
    include,
    exclude,
    processor = 'keyvalue',
    overrides = {},
  }: ProcessOptions = {}
): ProcessResults {
  const workbook = Buffer.isBuffer(file)
    ? XLSX.read(file, { type: 'buffer' })
    : XLSX.readFile(file);

  let sheetNames = workbook.SheetNames;

  if (include) {
    const includeFn = Array.isArray(include)
      ? (name: string) => include.includes(name)
      : (include as (value: string) => boolean);
    sheetNames = sheetNames.filter(includeFn);
  }

  if (exclude) {
    const excludeFn = Array.isArray(exclude)
      ? (name: string) => !exclude.includes(name)
      : (exclude as (value: string) => boolean);
    sheetNames = sheetNames.filter(excludeFn);
  }
github plantain-00 / js-excel-template / src / nodejs.ts View on Github external
public static fromFile(filepath: string) {
    const workbook = XLSX.readFile(filepath, {
      cellNF: true,
      cellStyles: true,
      cellDates: true
    })
    return new JsExcelTemplate(workbook)
  }
github pponugo / excel2jsonschema / src / validationUtil.js View on Github external
function hasSheet(fileName, sheetName) {
  try {
    return XLSX.readFile(fileName).Sheets[sheetName] !== undefined;
  } catch (err) {
    return false;
  }
}