I have a code to read data from excel using Angular Typescript. Its working file till converted to JSON. But didn't fetch into HTML Page. Problem is in column name of Excelsheet.
Excel file column names are like (i) Autodesk Material Description (ii) Autodesk SAP Material Description
If I use in HTML {{pricedata.Autodesk Material Description}}, {{pricedata.Autodesk SAP Material Description}}. It gives me error.
So I converted that name into (i) Autodesk_Material_Description (ii) Autodesk_SAP_Material_Description IN EXCELSHEET and code too ({{pricedata.Autodesk_Material_Description}}, {{pricedata.Autodesk_SAP_Material_Description}}).
Now it's working fine. So, how to handle this problem ?
import { Component, HostListener } from '@angular/core';
import * as XLSX from 'xlsx';
@Component({
selector: 'app-importpricelist',
templateUrl: './importpricelist.component.html',
styleUrls: ['./importpricelist.component.css']
})
export class ImportpricelistComponent
{
ExcelData:any;
constructor(){
}
ReadExcel(event:any){
let file = event.target.files[0];
let fileReader = new FileReader();
fileReader.readAsBinaryString(file);
fileReader.onload = (e) => {
var workBook = XLSX.read(fileReader.result, {type:'binary'});
var SheetNames = workBook.SheetNames;
this.ExcelData = XLSX.utils.sheet_to_json(workBook.Sheets[SheetNames[0]]);
console.log(this.ExcelData);
}
}
}