封装Excls数据导出功能 返回一个文件链接地址

Posted 没有热枕,世间便无进步.

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了封装Excls数据导出功能 返回一个文件链接地址相关的知识,希望对你有一定的参考价值。

 1    /// <summary>
 2         /// 获取本地存储地址
 3         /// </summary>
 4         /// <param name="dt"></param>
 5         /// <param name="prefix">前缀类别</param>
 6         /// <returns></returns>
 7         public string GetDwonLoadlPath(DataTable dt, string prefix)
 8         {
 9             string filename = System.Configuration.ConfigurationManager.AppSettings[prefix].ToString() + Guid.NewGuid() + ".xlsx";
10             string filePath = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath + "\\File\\Download\\" + filename;
11             string returnpath = System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath + "/File/Download/" + filename;
12             ExcelHelper.DataTableToExcel(dt, filePath);
13             return System.Configuration.ConfigurationManager.AppSettings["DomainName"] + returnpath;
14         }
 public class DrugParamsHelper
    {
        private static volatile DrugParamsHelper drugParamsHelper = null;
        private static object syncRoot = new Object();
        public DrugParamsHelper()
        {
         
        }
        /// <summary>
        /// 初始化注册
        /// </summary>
        public static DrugParamsHelper Instance
        {
            get
            {
                if (drugParamsHelper == null)
                {
                    lock (syncRoot)
                    {
                        if (drugParamsHelper == null)
                        {
                            if (true)
                            {
                            }
                            drugParamsHelper = new DrugParamsHelper();
                        }
                    }
                }
                return drugParamsHelper;
            }
        }
        /// <summary>
        /// 获取本地存储地址
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="prefix">前缀类别</param>
        /// <returns></returns>
        public string GetDwonLoadlPath(DataTable dt, string prefix)
        {
            string filename = System.Configuration.ConfigurationManager.AppSettings[prefix].ToString() + Guid.NewGuid() + ".xlsx";
            string filePath = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath + "\\File\\Download\\" + filename;
            string returnpath = System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath + "/File/Download/" + filename;
            ExcelHelper.DataTableToExcel(dt, filePath);
            return System.Configuration.ConfigurationManager.AppSettings["DomainName"] + returnpath;
        }}

调用示例 

  //转换列名称成中文名
            Dictionary<string, string> RenameColumDic = new Dictionary<string, string>();
            queryParams.colCollection.ForEach(f =>
            {
                RenameColumDic.Add(f.FieldName, f.DisplayName);
            });
            //将对象转成datatble
            DataTable dataTable = ListTranDataTableHelper.ToDataTable<ClinicalRegistrationCach>(list, RenameColumDic, queryParams.colCollection.Select(c => c.FieldName).ToArray());
            return new Response<string>(DrugParamsHelper.Instance.GetDwonLoadlPath(dataTable, "CDEExclsName"));

 

以上是关于封装Excls数据导出功能 返回一个文件链接地址的主要内容,如果未能解决你的问题,请参考以下文章

把excel导入服务器后台页面显示,java怎么写啊,求答案,最后的效果是下图这样。

素材下载网站代下源码

js导出word

vue导出+导入功能

vue后台导出文件提示,根据后台返回的Content-Type类型导出文件或提示消息

vue后台导出文件提示,根据后台返回的Content-Type类型导出文件或提示消息