如何将excel文件上传到服务器? [英] How to upload an excel file to the server?

查看:582
本文介绍了如何将excel文件上传到服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好人,

我正在开发一个Web应用程序,用户上传excel文件,单击上传按钮并将文件及其内容发送到服务器进行处理。我正在使用angular.js和Web API技术。任何人都可以建议如何从客户端应用程序POST文件并在服务器端接受?



1.这是前端的html代码:

Good People,
I am working on a web application where a user uploads an excel file, clicks the upload button and sends the file with its contents to the server for processing. I am am using angular.js and web API technologies. Can anyone advise on how do I "POST" the file from the client application and accept on the server side?

1. This is the html code for the front end:

<div class="modal fade" id="uploadUsersModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-removed" style="width: 510px">
            <div class="modal-header">
                <h4 class="modal-title">Bulk Upload - Users</h4>
            </div>
            <div class="modal-body">
                <div class="form-group has-success has-feedback" style="width: 400px">
                    <label for="adminChecklist">File</label>
                    <input type="file" ng-model="model.file" class="form-control" accept=".csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel" />
                </div>
            </div>
            <div class="modal-footer">

                <div class="form-group has-success has-feedback" style="width: 440px">
                    <span class="pull-left">{{confirmation.confirmation}}</span><button type="button" class="btn btn-primary" ng-click="upload(model)">{{confirmation.buttonMessage}}Upload</button>
                    <button type="button" class="btn btn-danger" ng-click="closeUploadUsersModal()">Close</button>
                </div>
            </div>

        </div>
    </div>
</div>





2.这是我的控制器中的javascript代码,必须将文件发送到服务器:

PenStatus是viewerAPI上的控制器。



2. This is javascript code in my controller that has to send the file to the server:
PenStatus is the controller on the viewerAPI.

var Files = $resource('viewerAPI/PenStatus/:id', { id: "@id" });

           angular.extend($scope, {

               model: { file: null },

               upload: function (model) {
                   Files.prototype.$save.call(model.file, function (self, headers) {
                       // Handle server response
                   });
               }
           });





3.我需要接受excel文件的服务器上的这个c#代码:



3. This c# code on the server where I need to accept the excel file:

// POST: api/PenStatus/5
       [HttpPost]
       public IHttpActionResult Post()
       {



           return null;
       }

推荐答案

资源(' viewerAPI / PenStatus /:id',{id: @id});

angular.extend(
resource('viewerAPI/PenStatus/:id', { id: "@id" }); angular.extend(


scope,{

model:{file: null },

上传:功能(型号){
Files.prototype。
scope, { model: { file: null }, upload: function (model) { Files.prototype.


save.call(model.file, function (self,headers){
// 处理服务器响应
});
}
});
save.call(model.file, function (self, headers) { // Handle server response }); } });





3.我需要接受excel文件的服务器上的这个c#代码:



3. This c# code on the server where I need to accept the excel file:

// POST: api/PenStatus/5
       [HttpPost]
       public IHttpActionResult Post()
       {



           return null;
       }


这篇关于如何将excel文件上传到服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆