读取 angularjs 中的 Xlsx 和 csv 文件
Read Xlsx and csv file in angularjs
我需要读取 angularjs 中 xlsx 和 csv 文件的每一行,并以 json 格式获取其数据。
目前我正在使用 angular-file-upload 来获取这样的文件。
$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)
}
在我的 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>
现在我无法继续处理此文件 object.i 找到了几种读取此文件的方法 this and this.But these are not working.I found some github projects like this_1 and this_1。
我需要帮助了解这样做的最佳做法是什么?
我应该在我的服务器端代码中读取这个文件并将数据发送到客户端吗?
哪个第三方 app/widget 适合此目的?
我终于得到了这样的文件...
$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];
}
}
}
现在您可以通过$scope.file
轻松读取文件,并根据需要获取数据。
谢谢
我需要读取 angularjs 中 xlsx 和 csv 文件的每一行,并以 json 格式获取其数据。
目前我正在使用 angular-file-upload 来获取这样的文件。
$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)
}
在我的 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>
现在我无法继续处理此文件 object.i 找到了几种读取此文件的方法 this and this.But these are not working.I found some github projects like this_1 and this_1。
我需要帮助了解这样做的最佳做法是什么?
我应该在我的服务器端代码中读取这个文件并将数据发送到客户端吗?
哪个第三方 app/widget 适合此目的?
我终于得到了这样的文件...
$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];
}
}
}
现在您可以通过$scope.file
轻松读取文件,并根据需要获取数据。
谢谢