I would like to know how to open a CSV file using Angular 4. I found an example on the network, but it is not exactly what I need because in that case the file is downloaded from the server. I need to open the file locally, is it possible?
I found this example:
http://blog.sodhanalibrary.com/2016/10/read-csv-data-using-angular-2.html#.WYNdCnWGNp8
Thanks
you can load files from the client machine using Javascript FileReader object and (Angular 2+ indeed).
import { Component } from '@angular/core';
@Component({
selector: 'app',
encapsulation: ViewEncapsulation.None,
template: `<input id="preview" type="file" (change)="previewFile($event)" />`
})
export class AppComponent implements OnInit {
...
public previewImage(event) {
const reader = new FileReader();
reader.onload = (e: any) => {
console.log('csv content', e.target.result);
};
reader.readAsDataURL(event.target.files[0]);
}
}
you can use FileReader() api.have a look at this thread : Getting Data from FileReader in Angular 2
Yes, it is possible like described in the link you provided too
You implement a webservice that will provide you the local file .
your angular applications makes a request to the webservice and retrieve the local file.