• 点击安钮生成WORD文档.


      private void Button1_Click(object sender, System.EventArgs e)
      {
       this.Export("1.aaaaaaaaaaaaaaaaa;<bR> 2.bbbbbbbbbbbb;",Response);
       

      }
      public void Export(string html,System.Web.HttpResponse response)
      {

       
       string time = DateTime.Now.ToString("yyyyMMddHHmmss");
       time += DateTime.Now.Millisecond.ToString();
       string tmpPath = Server.MapPath("/")+System.Configuration.ConfigurationSettings.AppSettings["ExcelDir"];
       if( !Directory.Exists(tmpPath))                    
        Directory.CreateDirectory(tmpPath);
       string path = tmpPath + "\\" + time + ".doc";

       StreamWriter sr = new StreamWriter(path,false,System.Text.Encoding.BigEndianUnicode);
      
       sr.WriteLine(html);
       sr.Close();

       response.Clear();
       FileStream objStream = File.Open(path,System.IO.FileMode.Open);
       long fileSize = objStream.Length;
       BinaryReader reader = new BinaryReader(objStream);
       reader.GetType();
       response.AppendHeader("Content-Disposition","attachment; filename=" + HttpUtility.UrlPathEncode(time+".doc"));
       response.AppendHeader("Content-Length",fileSize.ToString());
       response.ContentType = "application/vnd.ms-word";
       response.Charset="utf-8";
       while(reader.PeekChar()>=0)
       {
        response.BinaryWrite(reader.ReadBytes((int)fileSize));
       }
       reader.Close();
       objStream.Close();
       response.Flush();
       response.Clear();
       response.End();
      }

  • 相关阅读:
    Solidity通过合约转ERC20代币
    各种开源协议区别
    shell脚本之函数
    shell脚本之循环和循环控制
    shell脚本之if判断以及case多分支选择
    shell脚本之数组
    shell脚本之变量
    nginx常用内置变量
    nignx配置文件详解
    nginx源码安装./configure常见参数详解
  • 原文地址:https://www.cnblogs.com/lingxzg/p/858671.html
Copyright © 2020-2023  润新知