zoukankan      html  css  js  c++  java
  • 关于在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();
                }

            }

  • 相关阅读:
    B站14天数据分析笔记6次课笔记
    B站14天数据分析笔记5次课作业
    B站14天数据分析笔记5次课Pandas
    1037 在霍格沃茨找零钱 (20 point(s))
    第一章:第三节探索性数据分析
    Java没有运行选项
    Eclipse截图的时候错误提示消失/复制粘贴错误信息
    错误记录_css属性的值一定不需要引号么?
    错误记录_语法哪里错了?
    微软输入法使用
  • 原文地址:https://www.cnblogs.com/lzppcc/p/1363696.html
Copyright © 2011-2022 走看看