使用输入类型文件上传后,IE会保留到xlsx文件

时间:2019-02-12 03:51:07

标签: javascript angularjs excel typescript internet-explorer

我正在尝试使用输入type =“ file”标签上传xlsx文件

    <div class="innerCnt fill" ng-app="ExcelImport" ng-controller="excelImportCtrl">
    <div class="row">
        <label for="fileToUpload">Select a File to Upload</label><br />
        <input type="file" id="fileToUpload" multiple class="fileUploadSelector" on-file-change="addFiles"  />
    </div>
    <h4 id="uploadStatusLabel" class="uploadStatusLabel"></h4>
    <div id="uploadExcelStatusGrid">
        <table class="table-striped" ng-hide="!files[0]">
            <thead>
                <tr>
                    <th>File name</th>
                    <th>Status</th>
                    <th>Actions</th>
                </tr>
            </thead>
            <tbody>
                <tr ng-repeat="file in files">
                    <td class="centerCell"><div>{{file.name}}</div></td>
                    <td class="centerCell"><div>{{file.status || 'Waiting for upload'}}</div></td>
                    <td class="centerCell"><div><a href="#" ng-if="!file.status" ng-click="removeFile($index)">Delete</a></div></td>
                </tr>
            </tbody>
        </table>
    </div>
    <input type="button" id="excelUploadButton" class="button blueBtn" ng-click="uploadFiles()" value="Upload" ng-disabled="excelUploading || !files[0]"/>
</div>

这是ts文件:

 appImport.directive('onFileChange', function () {

    return {
        restrict: 'A',
        link: function (scope, element, attrs) {
            var onChangeHandler = scope.$eval((attrs as any).onFileChange);
            element.bind('change', function () {
                scope.$apply(function () {
                    var files = (element[0] as any).files;
                    if (files) {
                        onChangeHandler(files);
                    }
                });
            });
        }
    };
});

这是添加文件fn:

class ImportController {
    private scope: any;

    constructor($scope: ng.IScope) {
        this.scope = $scope as any;
        this.scope.files = []
        this.scope.addFiles = files => this.addFiles(files)
        this.scope.removeFile = idx => this.removeFile(idx);
    }

    private addFiles(files: FileList) {
        for (var i = 0; i < files.length; i++) {
            this.scope.files.push(files.item(i))
        }
    }

    private removeFile(entryIdx: number) {
        this.scope.files.splice(entryIdx, 1)
    }
}
appImport.controller("excelImportCtrl", ImportController)

一旦我在IE中浏览文件,我就在excel中打开文件并进行了一些更改,保存文件后,将在同一目录中创建一个临时文件。

关闭应用程序后,临时文件将被删除。

我尝试使用Chrome进行相同的过程,但是没有临时文件。

有人可以帮助我如何使用IE删除此临时文件吗?

预先感谢

0 个答案:

没有答案