简体   繁体   中英

How can read an excel file which is in the assets folder- Angular?

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?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM