zoukankan      html  css  js  c++  java
  • 点击安钮生成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();
      }

  • 相关阅读:
    03《软件需求分析教程》
    02《软件需求分析教程》
    01《软件需求分析教程》
    03《需求模式——软件建模与分析》
    02《需求模式——软件建模与分析》
    密码管理器
    01《需求模式——软件建模与分析》
    2020软件工程助教工作期末总结
    第十七周助教工作周小结
    第十六周助教工作周小结
  • 原文地址:https://www.cnblogs.com/lingxzg/p/858671.html
Copyright © 2011-2022 走看看