function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
jishan royjishan roy 

How to upload and insert data through Excel in salesforce lwc

The requirement is show the excell file in object-account in lwc.
VinayVinay (Salesforce Developers) 
Hi Jishan,

Check below examples that can help you.

https://hicglobalsolutions.com/blog/how-to-import-records-using-lighting-web-component/
https://www.apexhours.com/export-to-csv-xls-using-lightning-web-component/
https://www.salesforcetroop.com/custom_file_upload_using_lwc

Please mark as Best Answer if above information was helpful.

Thanks,
mukesh guptamukesh gupta

Hi Jishan

Please follow below url:-

https://chowdera.com/2021/03/20210328020859302q.html

https://developer.salesforce.com/forums/?id=9062I000000INoNQAW

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh 

jishan royjishan roy
To insert excel file data into salesforce(Account - Object), Create a new apex class and create an LWC for uploading files. Make the changes in javascript for upload and insert the data in salesforce to achieve this task.
my query is I write the j.s. but how to write apex  for that i want to know,

here is my code:

import { LightningElement, track } from 'lwc';
import { loadScript } from 'lightning/platformResourceLoader';
import sheetmin from '@salesforce/resourceUrl/sheetmin';
let XLS = {};
export default class xlsxDemo extends LightningElement {
@track acceptedFormats = ['.xls', '.xlsx'];
    connectedCallback() {
        console.log('connected callback');
        Promise.all([
            loadScript(this, sheetmin  )
        ]).then(() => {
            XLS = XLSX
            
        })
    }
    handleUploadFinished(event){
        const uploadedFiles = event.detail.files;
        console.log('uploadedFiles',uploadedFiles);
        if(uploadedFiles.length > 0) {   
            this.ExcelToJSON(uploadedFiles[0])
        }
    }
    ExcelToJSON(file){
        var reader = new FileReader();
        reader.onload = event => {
            var data=event.target.result;
            var workbook=XLS.read(data, {
                type: 'binary'
            });
            var XL_row_object = XLS.utils.sheet_to_row_object_array(workbook.Sheets["Sheet1"]);
            var data = JSON.stringify(XL_row_object);
            console.log(JSON.stringify(data));
        };
        reader.onerror = function(ex) {
            this.error=ex;
            this.dispatchEvent(
                new ShowToastEvent({
                    title: 'Error while reding the file',
                    message: ex.message,
                    variant: 'error',
                }),
            );
        };
        reader.readAsBinaryString(file);
    }
}

please help me out how to write apex for this requirement.