示例#1
0
        public ActionResult Export()
        {
            //var exportSpource = this.GetExportData();
            //var dt = JsonConvert.DeserializeObject<DataTable>(exportSpource.ToString());

            //var exportFileName = string.Concat(
            //    "客戶資料",
            //    DateTime.Now.ToString("yyyyMMddHHmmss"),
            //    ".xlsx");
            //return new ExportExcelResult
            //{
            //    SheetName = "客戶資料",
            //    FileName = exportFileName,

            //    ExportData = dt
            //};


            DataTable dt = ExcelUtility.ConvertObjectsToDataTable(repo客戶資料.All().
                                                                  Select(x => new { x.客戶名稱, x.統一編號, x.電話, x.傳真, x.地址, x.Email, x.客戶分類, x.帳號 }).ToList());

            System.IO.MemoryStream stream  = ExcelUtility.ExportExcelStreamFromDataTable(dt);
            FileContentResult      fResult = new FileContentResult(stream.ToArray(), "application/x-xlsx");

            fResult.FileDownloadName = "test.xlsx";
            return(fResult);
        }