zoukankan      html  css  js  c++  java
  • ASP.NET MVC RDLC-导出

            #region 导出
            /// <summary>
            /// 导出Excel或Pdf文件,通过文件扩展名自动识别
            /// </summary>
            /// <param name="name">文件路径及名称(包括扩展名)</param>
            /// <returns>导出成功返回true,否则返回false</returns>
            private bool ReportExport(string name)
            {
                bool result = false;

                string Name = name;
                string strFileName;//文件名
                string strExtend = ".xls";//扩展名
                string strFormat = "Excel";//文件格式
                bool validate = false;

                if (name != null || name.Trim() != String.Empty)
                {
                    Name = name.Trim();
                    strFileName = Path.GetFileName(Name);
                    if (strFileName.Trim() != String.Empty)
                    {
                        strExtend = Path.GetExtension(Name).Trim().ToLower();

                        switch (strExtend)
                        {
                            case ".xls":
                                strFormat = "EXcel";
                                break;
                            case ".pdf":
                                strFormat = "PDF";
                                break;
                            default:
                                strFormat = "Excel";
                                break;
                        }
                        validate = true;
                    }
                }

                if (validate)
                {
                    Warning[] Warnings;
                    string[] strStreamIds;
                    string strMimeType;
                    string strEncoding;
                    string strFileNameExtension;

                    byte[] bytes = this.rptView.LocalReport.Render(strFormat, null, out strMimeType,
       out strEncoding, out strFileNameExtension, out strStreamIds, out Warnings);

                    using (System.IO.FileStream fs = new FileStream(Name, FileMode.Create))
                    {
                        fs.Write(bytes, 0, bytes.Length);
                    }

                    result = true;
                }

                return result;
            }
            #endregion 导出

  • 相关阅读:
    C# 将数据导出到Excel汇总
    jquery 常用技巧
    JavaScript:世界上误解最深的语言
    对于jQuery中$.ajax方法的新认识
    JQuery上传插件Uploadify使用详解
    HTTP中Get与Post的区别
    Javascript中最常用的55个经典技巧
    C# params参数的应用
    10种JavaScript特效实例让你的网站更吸引人
    jQuery设计思想
  • 原文地址:https://www.cnblogs.com/xhety/p/3682739.html
Copyright © 2011-2022 走看看