How to use the node-xlsx.default.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 wztscau / vue-i18n-xlsx / lib / input.js View on Github external
// 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*,.*?)?\)/
  // Get all i18ns from project
  traversingDirectory(rootPath, function (fileContent, filePath, fileDir) {
    if (/\.(vue|js)$/.test(filePath)) {
      let matchList = fileContent.match(RegExp(i18nReg, 'gm'))
      if (matchList) {
        i18ns = i18ns.concat(matchList.map(item => item.replace(i18nReg, '$1')))
      }
github wztscau / vue-i18n-xlsx / lib / input.js View on Github external
row.push(inputRow ? inputRow[i] : zh)
      // others
      } else {
        let inputRow = inputData.find(row => row.includes(zh))
        row.push(inputRow ? inputRow[i] : null)
      }
    }
    outputData.push(row)
  })
  Log(chalk('> ',
    'Length of i18n after reading from project and excel itself:',
    chalk.cyan(outputData.length),
    outputData.length === inputData.length ? chalk.magenta('(no changed)') : ''
  ))
  // Build
  let buffer = Excel.build([{name: path.basename(filePath, '.xlsx'), data: outputData}])
  fs.writeFileSync(filePath, buffer)
  ///////// END /////////
  Log(chalk.green(
    chalk.bgGreen.black(' DONE '),
    `Generate excel successfully in ${Date.now()-startTime} ms`
  ))
  // Tmp
  let tmpProject = path.join(os.tmpdir(), 'vue-i18n-xlsx', path.basename(projectPath))
  !fs.existsSync(tmpProject) && mkdirsSync(tmpProject)
  fs.writeFileSync(path.join(tmpProject, path.basename(filePath)), buffer)
}
github moshang-xc / lottery / server / help.js View on Github external
function writeXML(data, name) {
  let buffer = xlsx.build([
    {
      name: "抽奖结果",
      data: data
    }
  ]);

  return new Promise((resolve, reject) => {
    fs.writeFile(path.join(cwd, name), buffer, err => {
      if (err) {
        reject(err);
        return;
      }
      resolve();
    });
  });
}

node-xlsx

NodeJS Excel files parser & builder

Apache-2.0
Latest version published 21 days ago

Package Health Score

85 / 100
Full package analysis