title: Can an Excel file be used as a calculation engine for a Node.js app?
body: <p>I will be making a POST request to <code>/api/vehicles</code> with the body values: make, model, year, etc.  The goal is to have these values entered into an existing excel calculator file as inputs so that an output (as a result of excel formulas) is generated which can be stored in a database. The excel file will be used as a calculation engine.</p>
  <p>I'm currently using the <a href="https://www.npmjs.com/package/xlsx" rel="nofollow noreferrer">xlsx</a> npm package to read and modify the excel file. To recalculate, I attempted to use the <a href="https://www.npmjs.com/package/xlsx-calc" rel="nofollow noreferrer">xlsx-calc</a> npm package after changing a few cell values but it is not recalculating the workbook.</p>
  <p>The problem is that excel won't recalculate the workbook. Is it possible to use excel on the backend in this way? What options do I have?</p>
  <p>Here is vehicles route that doesn't work. the function call of <code>XLSX_CALC(workbook)</code> is where it hangs and doesn't send back a response:</p>
  <pre class="lang-js prettyprint-override"><code>const express = require('express');
  const XLSX = require('xlsx');
  const XLSX_CALC = require('xlsx-calc');
  const formulajs = require('@formulajs/formulajs');
  
  const router = express.Router();
  
  let directKeys = {};
  directKeys['GAMMA.INV'] = formulajs.GAMMA.INV;
  XLSX_CALC.import_functions(formulajs, { override: true });
  XLSX_CALC.import_functions(directKeys);
  
  const workbook = XLSX.readFile('backend/excel/testcalc.xlsx');
  const worksheet = workbook.Sheets[workbook.SheetNames[8]];
  
  router.post('/api/vehicles', async (req, res) =&gt; {
    try {
      const { user_id, mileage } = req.body;
      worksheet['B12'].v = mileage;
      XLSX_CALC(workbook);
      const summary = XLSX.utils.sheet_to_json(worksheet);
      res.send(summary);
    } catch (error) {
      console.error(error);
      res.status(error.status || 500).send({ error: error.message });
    }
  });
  
  module.exports = router;
  
  </code></pre>