开发者

Passing a Controller action parameter to Excel

How Do I 开发者_开发问答pass a parameter from a controller action to excel? I open an excel file using Response.Redirect in a controller action, but want to pass a parameter "id" to Cell "A1" of "Sheet1"

Here is my controller Action:

    public ActionResult LaunchStudentBook(string id)
    {
        var stdno = student.StudentTable.Where(a => a.StudentNumber == id);

        Response.Redirect("~/StudentBook/StudentBook.xlsm");

        return View(stdno );

    }


Your best bet to solve this problem is to modify the excel spreadsheet on the server and send back that modified document to the client. This will involve several independent steps:

  1. Get the EPPlus library, a highly regarded (and open source) API for reading and writing Excel files.

  2. Use that library to read from StudentBook.xlsm. This will parse the file into an object model that you can then manipulate using EPPlus. i.e. This is how you will "insert the 'id' parameter into cell A1".

  3. Use EPPlus to write the new document to a MemoryStream

  4. Create an action in your controller that will send this stream back to the client via a FileStreamResult.

You should take a stab at all this and then ask new SO questions as you start implementing them. However, if you respond here, I'll try to help if I can.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜