egeriis / zipcelx

Turns JSON data into `.xlsx` files in the browser
MIT License
293 stars 90 forks source link

Can we use this library without npm or yarn. #71

Open jnarayan3039 opened 4 years ago

jnarayan3039 commented 4 years ago

Hi,

I am trying to use this library from Salesforce Lightning Web Component, I imported the downloaded zip file as a static resource and then imported the module.js into my javascript file. I am running into issues. Below is my code and explanation

@salesforce/resourceUrl/zipcelx - refers to the static resource that has entire downloaded zip reference. In salesforce we need to call loadScript for loading individual script files for using them

import { LightningElement, track, api} from 'lwc'; import zipcelx from '@salesforce/resourceUrl/zipcelx'; import getFieldsMetadata from '@salesforce/apex/ObjectFieldsGraphController.getFieldsMetadata' import { loadScript } from 'lightning/platformResourceLoader';

export default class SpreadSheetGenerator extends LightningElement {

renderedCallback() {
    Promise.all([
        loadScript(this, zipcelx+ '/zipcelx-master/lib/module.js')
    ]).then(() => {
        loadScript(this, zipcelx+ '/zipcelx-master/lib/standalone.js')
    }).then(() => {
        loadScript(this, zipcelx+ '/zipcelx-master/lib/legacy.js')
    }).then(() => {
        zipcelx({
            filename: 'general-ledger-Q1',
        sheet: {
          data: [
            [{
              value: 'Income - Webshop',
              type: 'string'
            }, {
              value: 1000,
              type: 'number'
            }]
          ]
        }})
    }).catch( e =>{
        console.log('Exception:'+e);
    });

}

}