5

I'm currently creating generic spreadsheets in JS using https://www.npmjs.com/package/xlsx . This works fine to generate just a generic spreadsheet to display my data. However, I wanna add a few features.

https://i.stack.imgur.com/3qBc7.jpg is an example of what I want to achieve. It was created using Apache POI, which is only available for Java.

The features I want in that screenshot are

  1. The ability to add a picture (seen as a logo in the top-left)
  2. Ability to change font-color (as seen in the Title in the center)
  3. Ability to center-align text (as seen with the SubTitles in the center)
  4. Ability to make fields sortable (As seen with the arrow buttons per each column)

Seems like SheetJS can provide some of this functionality through their premium version. https://dzone.com/articles/5-popular-standalone-javascript-spreadhsheet-libra is a list of other libraries I looked into. However, that list seems more of emulating a spreadsheet with native JS objects as opposed to creating an .xlsx file. Also, most of them require paid licenses.

Anybody have experience with creating my 4 requirements with a free JS solution? I'm building on Meteor JS btw.

If not, are there any other workarounds to achieving this? I.e. Having the app just output a .csv, but then creating a generic excel "template" file which will do all the formatting with the csv? Or, delegating to some other program/script to generate the XLSX and downloading the output file.

Thanks

user2402616
  • 1,434
  • 4
  • 22
  • 38

2 Answers2

12

exceljs got all the features you want, it's just got a slightly different API and not as popular as xlsx that's why it always flies under the radar.

Harry Adel
  • 1,238
  • 11
  • 16
  • Just saw this yesterday. I surprisingly had to go about the 3rd Google search page to find this. Not sure why, as its documentation seems to have everything the paid libraries do. Just a quick question if you've used this before. I'm trying to run their demo in https://github.com/natergj/excel4node under 'Basic Usage'. Do you know how to write the output .xlsx to a filehandle on client-side so that I can download the file on my browser and test it? – user2402616 Nov 21 '19 at 14:16
  • 2
    Yeah, it's a hidden gem basically. If you'd like to download the xlsx file you may try this method here: https://github.com/exceljs/exceljs/issues/342#issuecomment-481225998 – Harry Adel Nov 22 '19 at 04:28
  • 2
    Yeah, I got it pretty much doing it that way wb.xlsx.writeBuffer() .then(buffer => { // buffer --> blob const blob = new Blob([buffer], { type: "application/vnd.ms-excel" }) let link = document.createElement('a') link.download = 'download.xlsx' link.target = 'blank' // blob --> url link.href = URL.createObjectURL(blob) link.click() }) .catch(err => { throw err }); Lots of trial and error to get it to dl browser-side. I had to use their browser library which had lots of dependencies – user2402616 Nov 22 '19 at 15:57
0

Use XLSX library, it support all features that you need.

  • 3
    Please add further details to expand on your answer, such as working code or documentation citations. – Community Aug 27 '21 at 11:18