Advertisement
Guest User

Untitled

a guest
Sep 27th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. /**
  2. * writes a dataArray to an Excel workbook
  3. * this must happen in child process
  4. * otherwise a blank page results
  5. * get dataArray listening to process.send
  6. */
  7.  
  8. const Excel = require('exceljs')
  9.  
  10. // path is passed as only argument of the process
  11. // but first two arguments are used by node internally
  12. const path = process.argv[2]
  13.  
  14. // dataArray is passed as message
  15. // because process arguments can only be strings
  16. process.on('message', (dataArray) => {
  17. const workbook = new Excel.Workbook()
  18. const worksheet = workbook.addWorksheet('Geschäfte')
  19. worksheet.addRows(dataArray)
  20. worksheet.getRow(1).fill = {
  21. type: 'gradient',
  22. gradient: 'angle',
  23. degree: 0,
  24. stops: [
  25. { position: 0, color: { argb: 'FFD3D3D3' } },
  26. { position: 1, color: { argb: 'FFD3D3D3' } }
  27. ]
  28. }
  29. worksheet.getRow(1).font = {
  30. bold: true
  31. }
  32. worksheet.getRow(1).border = {
  33. bottom: {
  34. style: 'thin'
  35. }
  36. }
  37. workbook.xlsx.writeFile(path)
  38. .then(() =>
  39. process.send({ success: true })
  40. )
  41. .catch(err =>
  42. process.send({ error: err })
  43. )
  44. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement