Search code examples
javascriptangularjsexcelcsvreadfile

Read Xlsx and csv file in angularjs


I need to read each line of xlsx and csv file in angularjs and get its data in json format.

Currently I am using angular-file-upload to get that file like this.

$scope.LatLongUploader = new FileUploader({
    //url: "/Map/UploadDamageRatioFile",
    queueLimit: 1,
    removeAfterUpload: true
});

$scope.locationUpload = function () {

        console.log( $scope.LatLongUploader)
        console.log( $scope.LatLongUploader.queue[0].file)
}

and in my html:

      <div ng-show="true" style="margin-top:4px">
      <input style=" width:212px; float:left" type="file" nv-file-select uploader="LatLongUploader" accept=".xlsx" class="AddLocationUpload" />
      <button ng-click="locationUpload()" ng-disabled=""  id="uploadlatlongfile" title="Upload Latitude Longitude File"><i class="fa fa-upload"></i></button></div>

Now I am unable to proceed with this file like object.i found several ways to read this file like this and this.But these are not working.I found some github projects like this_1 and this_1.

I want help in what is best practice to do so?

Should I do this file reading in my server side code and send data to client side?

Which third party app/widget is good for this purpose?


Solution

  • Finally I managed to get the file like this...

    $scope.getLatLonGFile = function () {
            var FileUpload = document.getElementsByClassName('AddLocationUpload');
            $scope.file = FileUpload[0].files[0];
    
            for (var i = 0; i < FileUpload.length; i++) {
                FileUpload[i] = function () {
                    $scope.file = this.files[0];
                }
            }
        } 
    

    Now you can easily read the file by $scope.file and get data according to the need.

    Thanks