How to use the node-xlsx.default.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 wztscau / vue-i18n-xlsx / lib / input.js View on Github external
* Read stage
   */
  // Read from excel. Get head and data
  let inputData = []
  try {
    let tmpFilePath = path.join(os.tmpdir(), 'vue-i18n-xlsx', path.basename(projectPath), path.basename(filePath))
    if (!global._cacheCleared) {
      try {
        fs.unlinkSync(tmpFilePath)
      } catch (e) {
        // noop
      } finally {
        global._cacheCleared = true
      }
    }
    inputData = Excel.parse(tmpFilePath)[0].data
  } catch (e) {
    try {
      inputData = Excel.parse(filePath)[0].data
    } catch (e) {
      Warn(chalk.yellow(
        chalk.bgYellow.black(' WARN '),
        'Excel file not exist'
      ))
      mkdirsSync(path.dirname(filePath))
      fs.writeFileSync(filePath, Excel.build([{name: path.basename(filePath, '.xlsx'), data: null}]))
    }
  }
  Log(chalk('> ',
    'Length of i18n before reading from project:',
    chalk.cyan(inputData.length)
  ))
github wztscau / vue-i18n-xlsx / lib / output.js View on Github external
module.exports = function (excelPath, jsPath, projectPath) {
  ///////// START /////////
  let startTime = Date.now()
  // File path must end with .xlsx
  excelPath = excelPath.endsWith('.xlsx') ? excelPath : excelPath + '.xlsx'
  // Read from excel
  let inputData = []
  try {
    inputData = Excel.parse(excelPath)[0].data
  } catch (e) {
    Warn(chalk.yellow(
      chalk.bgYellow.black(' WARN '),
      'Excel file not exist'
    ))
    return
  }
  // Generate json
  let head = inputData[0]
  let data = {}
  for (let i = 1; i < inputData.length; i++) {
    let row = inputData[i]
    for (let j = 1; j < head.length; j++) {
      let col = row[j]
      let lang = data[head[j]] = data[head[j]] || {}
      lang[row[0]] = col || ''
github wztscau / vue-i18n-xlsx / lib / input.js View on Github external
let inputData = []
  try {
    let tmpFilePath = path.join(os.tmpdir(), 'vue-i18n-xlsx', path.basename(projectPath), path.basename(filePath))
    if (!global._cacheCleared) {
      try {
        fs.unlinkSync(tmpFilePath)
      } catch (e) {
        // noop
      } finally {
        global._cacheCleared = true
      }
    }
    inputData = Excel.parse(tmpFilePath)[0].data
  } catch (e) {
    try {
      inputData = Excel.parse(filePath)[0].data
    } catch (e) {
      Warn(chalk.yellow(
        chalk.bgYellow.black(' WARN '),
        'Excel file not exist'
      ))
      mkdirsSync(path.dirname(filePath))
      fs.writeFileSync(filePath, Excel.build([{name: path.basename(filePath, '.xlsx'), data: null}]))
    }
  }
  Log(chalk('> ',
    'Length of i18n before reading from project:',
    chalk.cyan(inputData.length)
  ))
  // zh keys
  let i18ns = inputData.map(row => row[0]).filter(col => col !== 'index')
  const i18nReg = /\$t\(['"`](.*?)['"`](?:\s*,.*?)?\)/
github zapkub / cu-vivid-museum-wiki / seed / index.js View on Github external
const XLSX = require('node-xlsx').default;
const path = require('path');
const _ = require('lodash');
const fs = require('fs');
const ObjectID = require('mongodb').ObjectID;
const gardenSheet = XLSX.parse(path.join(__dirname, './garden.xlsx'));
const herbariumnSheet = XLSX.parse(path.join(__dirname, './herbarium.xlsx'));

let amount = process.env.JSON_PARSE_AMOUNT || 999999999;

exports.setAmount = function setAmount(_amount) {
    amount = _amount;
}
function encodeRFC5987ValueChars(str) {
    return encodeURI(str).
        replace(/['()]/g, escape)
}
function escapeRegExp(str) {
    return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
}
function getScinameKey(sciname) {
    const scinameSplit = sciname.split(' ');
    return `${scinameSplit[0]} ${scinameSplit[1]}`;
github zapkub / cu-vivid-museum-wiki / seed / index.js View on Github external
const XLSX = require('node-xlsx').default;
const path = require('path');
const _ = require('lodash');
const fs = require('fs');
const ObjectID = require('mongodb').ObjectID;
const gardenSheet = XLSX.parse(path.join(__dirname, './garden.xlsx'));
const herbariumnSheet = XLSX.parse(path.join(__dirname, './herbarium.xlsx'));

let amount = process.env.JSON_PARSE_AMOUNT || 999999999;

exports.setAmount = function setAmount(_amount) {
    amount = _amount;
}
function encodeRFC5987ValueChars(str) {
    return encodeURI(str).
        replace(/['()]/g, escape)
}
function escapeRegExp(str) {
    return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
}
function getScinameKey(sciname) {
    const scinameSplit = sciname.split(' ');
github zapkub / cu-vivid-museum-wiki / server / updates / 0.0.5-herbarium.js View on Github external
const XLSX = require('node-xlsx').default;
const path = require('path');
const keystone = require('keystone');
const _ = require('lodash');

const Plant = keystone.list('Plant');
const PlantCategory = keystone.list('Category');
const Location = keystone.list('Location');
const herbariumSheet = XLSX.parse(path.join(__dirname, '../../seed/Herbarium.xlsx'));


function letterToColumns(input) {
  return input.charCodeAt(0) - 65;
}

const herbs = herbariumSheet[0]
.data
.filter((item, i) => i > 0 && item[letterToColumns('E')])
.filter(item => item[letterToColumns('F')])
.map(columns => ({
  cuid: columns[letterToColumns('A')],
  localName: columns[letterToColumns('F')],
  otherName: columns[letterToColumns('G')] ? columns[letterToColumns('G')].split(';') : [],
  duplicateAmount: columns[letterToColumns('H')],
  scientificName: columns[letterToColumns('E')],
github moshang-xc / lottery / server / help.js View on Github external
function loadXML(xmlPath) {
  let userData = xlsx.parse(xmlPath);
  let outData = [];
  userData.forEach(item => {
    outData = item.data;
    outData.shift();
    return false;
  });
  outData = outData.filter(item => item.length > 0);
  return outData;
}
github etalab / decoupage-administratif / build / util.js View on Github external
async function readSheets(filePath) {
  const rawFileContent = await readFile(filePath)
  const fileContent = filePath.endsWith('.gz') ? await gunzip(rawFileContent) : rawFileContent
  return xlsx.parse(fileContent, {cellDates: true})
}
github zapkub / cu-vivid-museum-wiki / server / updates / 0.0.6-garden.js View on Github external
const XLSX = require('node-xlsx').default;
const path = require('path');
const keystone = require('keystone');
const _ = require('lodash');

const Plant = keystone.list('Plant');
const PlantCategory = keystone.list('Category');
const Location = keystone.list('Location');

const gardenSheet = XLSX.parse(path.join(__dirname, '../../seed/Garden.xls'));


function letterToColumns(input) {
  return input.charCodeAt(0) - 65;
}

const gardens = gardenSheet[0]
	.data
	.filter((item, i) => i > 0 && item[letterToColumns('E')])
	.map((columns) => {
  const anatomy = [];
  if (columns[letterToColumns('Q')]) {
    anatomy.push(columns[letterToColumns('Q')]);
  }
  if (columns[letterToColumns('P')]) {
    anatomy.push(columns[letterToColumns('P')]);

node-xlsx

NodeJS Excel files parser & builder

Apache-2.0
Latest version published 7 months ago

Package Health Score

71 / 100
Full package analysis