• 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");

            }

  • 相关阅读:
    0.计算机相关
    面试笔试大概会出现的问题其二
    uboot传递启动参数给内核
    移植uboot之裁剪和修改参数
    uboot移植之支持板子nand启动
    uboot移植之建立新板、初始化时钟/SDRAM/UART
    uboot移植之重定位
    uboot移植之重定位之前的启动过程
    uboot移植之初步编译
    输入子系统分析
  • 原文地址:https://www.cnblogs.com/nxxshxf/p/6408740.html
Copyright © 2020-2023  润新知