WorkbookDesigner mvc里面返回file

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace test.Controllers
{
    using System.Data;
    using System.IO;
    using Aspose.Cells;


    public class ExcelController : Controller
    {
        public FileResult excels()
        {
            DataTable dt = new DataTable();
            dt.TableName = "table1";
            dt.Columns.Add(new DataColumn("ROW1", typeof(string)));
            dt.Columns.Add(new DataColumn("ROW12", typeof(string)));
            DataRow dr;
            for (int i = 0; i <= 10; i++)
            {
                dr = dt.NewRow();
                dr["ROW1"] = Guid.NewGuid().ToString();
                dr["ROW12"] = Guid.NewGuid().ToString();
                dt.Rows.Add(dr);
            }

            WorkbookDesigner designer = new WorkbookDesigner();
            string path = Server.MapPath("/Templete/DDD.xls");
            designer.Workbook.Open(path);
            designer.SetDataSource(dt);
            designer.Process();

            //将文件存在服务器端,名称是123.xls
            designer.Save(Server.MapPath("/Templete/123.xls"), FileFormatType.Default);

            //将服务器端的文件/Templete/123.xls下载到客户端
            return File(Server.MapPath("/Templete/123.xls"), "application/ms-excel", "dsds.xls");

            //将流文件写到客户端流的形式写到客户端,名称是_report.xls
           //designer.Save("_report.xls", SaveType.OpenInExcel, FileFormatType.Excel2003, System.Web.HttpContext.Current.Response);
           // Response.Flush();
           //Response.Close();
          //designer = null;
           // Response.End();
           // return View("getexcel");

        }

 

http://ming2882code.googlecode.com/svn-history/r279/trunk/ext3mvc/Web/Controllers/ReportController.cs

转载于:https://www.cnblogs.com/muer/p/WorkbookDesigner_mg.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值