0

I want to convert an excel file to a JSON, but at first, I want to find a way to access my excel file, which is in the assets folder, from app.component.ts- Can anyone help me, please?

MSD
  • 49
  • 1
  • 6

2 Answers2

0

import example from '../assets/example.json';

This should work, but may I ask why you are storing it in your assets folder? I used to do this to and figured that creating a rest-api almost always is better, even if it's a mock.

TKTurbo
  • 92
  • 1
  • 11
0

In short, it's not possible to do what you want. While you can read such files with the HTML5 Filereader API on a client-side basis, you can't simply pass the folder in your methods to make this work. Javascript has no immediate access to the system files. That's something Node.js solves - being a backend technology - but you can't do this on Angular.

You can read more about it in this question...

https://stackoverflow.com/a/6382820/9349240

ak.leimrey
  • 1,137
  • 2
  • 11
  • 25