Example #1
0
        /// <summary>
        /// 获得导出的url并导出
        /// </summary>
        /// <param name="pagination">分页</param>
        /// <param name="keyword">条件</param>
        /// <returns></returns>
        public FileResult GetExportExcelUrl(Pagination pagination, string keyword)
        {
            var list = new List <UserExcelOutPut>();

            if (pagination.rows == 0 && pagination.page == 0)
            {
                list = userApp.GetExcelList();
            }
            else
            {
                list = userApp.GetExcelList(pagination);
            }
            //类型转换(将List转化为DataTable)
            var exportDt   = list.ToDataTable(rec => new object[] { list });
            var excelTitle = "用户数据";
            var rootPath   = AppDomain.CurrentDomain.BaseDirectory;

            rootPath = Path.Combine(rootPath, "DownLoad", "Excel", "User");
            var fileName     = "用户数据.xlsx";
            var realFilePath = Path.Combine(rootPath, fileName);

            new NPOIExcel().ToExcel <UserExcelOutPut>(exportDt, realFilePath, excelTitle);
            return(File(realFilePath, "application/vnd.ms-excel", fileName));
        }