Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance cell customization - add data-base64-xlsx-cell-config #64

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

yuanoook
Copy link

The use case is like this:

  1. To customize the cell to use the other numFmt, like currency "$"#,##0.00;[Red]\-"$"#,##0.00, or even more;

  2. Set _value: 10000, instead of _value: "10000".

The string _value: "10000" could not be recognized as a calculation dependency in excel software, which bugged our clients a lot.

To use data-base64-xlsx-cell-config

const htmlTo = require('html2xlsx')
const btoa = (window && window.btoa) || (str => Buffer.from(str, 'utf-8').toString('base64'))

htmlTo(`
  <table>
    <tr>
      <td data-base64-xlsx-cell-config="${btoa(JSON.stringify({
          numFmt: '"$"#,##0.00;[Red]\-"$"#,##0.00',
          cellType: 'TypeNumeric',
          _value: 10000
        }))}"
      >
        10000
      </td>
    </tr>
  </table>
`, (err, file) => {
  if (err) return console.error(err);

  file.saveAs()
    .pipe(fs.createWriteStream('test.xlsx'))
    .on('finish', () => console.log('Done.'));
});

@coveralls
Copy link

coveralls commented Dec 10, 2020

Coverage Status

Coverage remained the same at 100.0% when pulling e48f9b7 on yuanoook:cell-customization-enhancement into e104d08 on d-band:master.

@yuanoook yuanoook force-pushed the cell-customization-enhancement branch from 6688ffc to e48f9b7 Compare December 10, 2020 06:35
@yuanoook
Copy link
Author

yuanoook commented Dec 10, 2020

Another issue found: NODE_ENV is not a command when try to install 0.4.2 in windows

This could be solved with cross-env, or, run build in prepublish as 0.4.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants