0

I pass Excel file to json and I need to put the information from the object in one json file placed in assets folder. I try using FILE component but I can not find the solution any Help please. The ExcelData need to write to files """

import { Component, OnInit } from '@angular/core';
import * as XLSX from 'xlsx'
import { HttpClient, HttpHeaders } from '@angular/common/http';

export class ExcelPage implements OnInit {

 ExcelData: any;
files= this.httpClient.get('../../assets/json/data.json')


  constructor( private httpClient: HttpClient) { }

  ngOnInit() {
  }

  ReadExcel(event:any){
    let file= event.target.files[0];
    let fileReader = new FileReader();

    fileReader.readAsBinaryString(file);
    fileReader.onload =(e)=>{
      var wb = XLSX.read(fileReader.result,{type:'binary'});
      var sheetNames = wb.SheetNames;
      this.ExcelData = XLSX.utils.sheet_to_json(wb.Sheets[sheetNames[0]])
     // console.log(this.ExcelData)
      JSON.stringify(this.ExcelData)

  XLSX.writeFile(this.ExcelData, "../../assets/json/data.json")

"""

1 Answer 1

0

The assets folder is read only at run time.

You can only store files in it during development time.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.