用户登录
用户注册

分享至

asp.netword

  • 作者: 白日梦o
  • 来源: 51数据库
  • 2020-06-05

1. asp.net 生成一定格式的word文档并下载

cs模式。

把word库导入到项目中,然后,在功能页面中创建word对象,操作此对象就可以了。

bs模式。

解决方法有两种

1.先把数据装载到gridview或repeater等中,然后,通过response把数据刷到页面上。

2.把word库导入到项目中,然后,在cs文件中编写相应的word控制代码,类似在cs模式下操作word.

以上只是思路,呵呵。具体的实现代码在网络上有很多。

2. 请问asp.net如何将整个页面或部分页面导出到word

//EnableEventValidation="false" //页面上的设定 Response.ContentType = "application/ms-word";//指定到word Response.AddHeader("Content-Disposition", "inline;filename=test.doc"); StringBuilder sb = new StringBuilder();//没用上 StringWriter sw = new StringWriter(sb); HtmlTextWriter hw = new HtmlTextWriter(sw); sb.Append("");//没用上 pnlToWord.RenderControl(hw);//指定一个区域pnlToWord是Panel控件 //Page.RenderControl(hw);//整个页面 Response.Write(sw.ToString()); Response.End();。

3. asp.net导出word

public void Download() { Random rd = new Random(); string fileName = DateTime.Now.ToString("yyyyMMddhhmm") + rd.Next() + ".doc"; //存储路径 string path = Server.MapPath(fileName); //创建字符输出流 StreamWriter sw = new StreamWriter(path, true, System.Text.UnicodeEncoding.UTF8); //需要导出的内容 string str = "无标题文档这里放从数据库导出的word文档内容"; //写入 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(); }标准word文档的格式微软暂未公布,由此我们可将需要导出的内容转为标准HTML文件储存,后缀名为.doc也可以将要导出内容转为标准XML格式存储,改后缀为.doc具体格式随意新建个word文档,输入内容,另存为.XML可见另外一种导出方式为word导出标准格式,服务器需要安装Microsoft Office word,需要预先设置好一个word文档并在要插入内容的地方设置书签做为模版,导出word文档时需要先遍历模版文件中的所有书签,然后给书签赋值就能实现导出数据了还有不懂的可以直接百度HI我是否可以解决您的问题?。

4. ASP.NET导出word文档让客户端下载,用户下载后怎么及时把服务器

生成word文档的时候,将内容直接以流的方式用页面输出就可以了

比如:

Response.ClearContent();

Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(file.Name)+".doc");

Response.ContentType = "application/msword";

Response.BinaryWrite(ms.ToArray());

Response.Flush();

Response.End();

转载请注明出处51数据库 » asp.netword

软件
前端设计
程序设计
Java相关