首页 .NET/Web C#导出word

C#导出word

作者:胡同里的砖头 围观群众:2407 更新于:2014-03-12

int examid=Convert.ToInt32(e.CommandArgument.ToString());//试卷编号

        Random rd = new Random();
        string fileName = DateTime.Now.ToString("yyyyMMddhhmm") + rd.Next() + ".doc";
        //存储路径
        string path = Server.MapPath("~/word/"+fileName);
        //创建字符输出流
        StreamWriter sw = new StreamWriter(path, true, System.Text.UnicodeEncoding.UTF8);

        //需要导出的内容
        string str = GetURLContent("http://localhost:2183/SF/Test/Admin/Conctrl/ExamOne.aspx?id="+examid,"utf-8");

        //写入
        sw.Write(str);
        sw.Close();
        Response.Clear();
        Response.Buffer = true;
        this.EnableViewState = false;
        Response.Charset = "utf-8";
        Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
        Response.ContentType = "application/octet-stream";
        Response.WriteFile(path);
        Response.Flush();
        Response.Close();
        Response.End();

  • 本文标题: C#导出word
  • 文章分类:【.NET/Web】
  • 非特殊说明,本文版权归【胡同里的砖头】个人博客 所有,转载请注明出处.
留言评论
站点声明:
1、本站【胡同里的砖头】个人博客,借鉴网上一些博客模板,取其各优点模块自行拼装开发,本博客开发纯属个人爱好。
2、所有笔记提供给广大用户交流使用,可转载,可复制,纯个人开发所遇问题锦集记录使用
Copyright © huzlblog.com All Rights Reserved. 备案号:苏ICP备2021056683号-8