0

I want to read an excel file which is stored in SharePoint library in PNP JS. How can I achieve this ?

0

Mian code:

 import * as XLSX from 'xlsx';  



sp.web.getFileByServerRelativeUrl("/sites/SPCapabilityTeam/Documents/ss.xlsx").getBuffer().then((buffer: ArrayBuffer) => {  
                    var workbook = XLSX.read(buffer, {  
                        type: "buffer"  
                    });  
                    var first_sheet_name = workbook.SheetNames[0];  
                    var worksheet = workbook.Sheets[first_sheet_name];  
                    var headers = {};  
                    var data = [];  
                    let z: any;  
                    for (z in worksheet) {  
                        if (z[0] === '!') continue;  
                        var tt = 0;  
                        for (var i = 0; i < z.length; i++) {  
                            if (!isNaN(z[i])) {  
                                tt = i;  
                                break;  
                            }  
                        }  
                        var col = z.substring(0, tt);  
                        var row = parseInt(z.substring(tt));  
                        var value = worksheet[z].v;  
                        //store header names  
                        if (row == 1 && value) {  
                            headers[col] = value;  
                            continue;  
                        }  
                        if (!data[row]) data[row] = {};  
                        data[row][headers[col]] = value;  
                    }  
                    console.log(data)  
                });  

Reference: https://www.c-sharpcorner.com/blogs/reading-sharepoint-document-library-excel-file-using-spfx-and-pnpjs

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.