• 关于在Page_Load定义外部变量输出


    string cmd = (string)Common.sink("cmd", MethodType.Get, 255, 0, DataType.Str);      

      protected void Page_Load(object sender, EventArgs e)
            {

                if (cmd == "DownLoad")
                {
                    DownXslFile();
                }

            }

    /// <summary>
            /// 导出Excel文档
            /// </summary>
            protected void DownXslFile()
            {


                System.IO.StringWriter sw = new System.IO.StringWriter();

                Server.Execute("report.aspx?cmd=ssss", sw, false);
                string abcd = sw.ToString();
                string fileName = "考勤报表_" + DateTime.Now.Date.ToString("yyyyMMdd") + ".xls";

                //Response.Headers.Clear();
                Response.Clear();
                Response.AppendHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName));
                Response.Charset = "utf-8";
                Response.ContentEncoding = System.Text.Encoding.UTF8;
                Response.ContentType = "application/ms-excel";
                Response.Write(abcd.ToString());
                Response.End();
            }

     发现生成的文件内容为空.

    后来将string cmd = (string)Common.sink("cmd", MethodType.Get, 255, 0, DataType.Str);      放入page_load方法中才成功.

    如下:

      protected void Page_Load(object sender, EventArgs e)
            {

              string cmd = (string)Common.sink("cmd", MethodType.Get, 255, 0, DataType.Str);      

                if (cmd == "DownLoad")
                {
                    DownXslFile();
                }

            }

  • 相关阅读:
    oracle hint
    oracle资源
    数据迁移相关笔记
    csdn的blog可以直接导入内含图片的word文档吗?
    Windows Live Writer离线博客工具使用教程(适用于博客园、CSDN、51CTO等等博客)
    csdn的博客上传word图片
    怎样将word中的图片插入到CSDN博客中
    测试用Word2007发布博客文章
    用WORD2007发布博客文章
    Word2007发布博客
  • 原文地址:https://www.cnblogs.com/lzppcc/p/1363696.html
Copyright © 2020-2023  润新知