Code Monkey home page Code Monkey logo

lightning-excel-import's Introduction

Lightning-excel-import

Component, which allows you to import excel (.xlsx) documents and get their content in lightning component. Based on the XLSX.js library.

Use-cases

Use it, when you need your user to import .xlsx files and use its content in you lightning component and/or apex class.

Usage

To use this component, simply include it in your markup and handle the import event.

<aura:component>
    ...
    <c:ExcelImport onImport="{!c.myImportHandlingFunction}"/>
    ...
</aura:component>

ExcelImport renders into a file lightning:input component with additional handling for Excel table files.

Supported attributes

Attribute Type Inherited? Description Default Value
label String Yes Label for input Import Excel File
class String Yes Additional classes applied to the input
variant String Yes Input appearance standard
required Boolean Yes Shows if input is mandatory false
disabled Boolean Yes Disables the input false
accept String Yes Accepted file types .xls, .xlsx
stretchedDropzone Boolean No Makes dropzone take all available space false
fileSizeThreshhold Integer No Max file size in bytes 10000000
messageFileSizeExceeded String No File size exceeded message File size exceeded
messageNoFileSpecified String No No file specified message No file specified

Event handling

onImport event is a component-level event, which has this attributes:

Attribute Type Description
type String Type of the event: SUCCESS, ERROR
message String Message in case of error
fileName String Name of the imported file
table String Parsed Excel table, see XLSX.js docs for details

To handle onImport event and get the parsed table object simply use event parameters:

{
    ...
    myImportHandlingFunction: function(component, event, helper) {
        let eventType = event.getParam("type");
        if (eventType === "SUCCESS") {
            console.log(event.getParam("fileName"));
            console.log(event.getParam("table"));
        }
        if (eventType === "ERROR") {
            console.log(event.getParam("message"));
        }
    }
    ...
})

Todos

  • Make input support any type of file, processing tables only
  • Improve error handling
  • (?) change some of the attributes

License

MIT

lightning-excel-import's People

Contributors

4an70m avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.