1、只能导出成word2007格式(.docx),可直接导出到客户端

2、服务器上不需要装任何东西,也没有权限限制,比较适合导出表格(支持图片)
3、需要一个国外的DocX.dll插件
4、需要添加引用:System.Drawing
5、需要引用:
using Novacode;
using System.Drawing;
using System.IO;
using System.Drawing.Imaging;
using System.Threading.Tasks;
using System.Data;
6、方法样例如下:

        public static void aa()
{
// Create a document.
using (DocX document = DocX.Create("F:/测试/test2/生成的word/111table.docx"))
{
// Add a hyperlink into the document.
//Hyperlink link = document.AddHyperlink("link", new Uri("http://www.google.com"));
Paragraph title = document.InsertParagraph().Append("Test").FontSize();//.Font(new FontFamily("Comic Sans MS"));
title.Alignment = Alignment.center;
Table table = document.InsertTable(, );
table.Design = TableDesign.TableGrid;
//table.AutoFit = AutoFit.ColumnWidth;
//宽度设置(每个单元格都得设置),默认每个单元格宽度:154,表格总宽度大约:687
table.Rows[].Cells[].Width = ;
table.Rows[].Cells[].Width = ;
table.Rows[].Cells[].Width = ;
table.Rows[].Cells[].Width = ;
//table.Design = TableDesign.ColorfulGridAccent2;
table.Alignment = Alignment.center;
table.SetBorder(TableBorderType.InsideH, new Border());
table.SetBorder(TableBorderType.InsideV, new Border());
table.SetBorder(TableBorderType.Top, new Border());
table.SetBorder(TableBorderType.Right, new Border());
table.SetBorder(TableBorderType.Left, new Border());
table.SetBorder(TableBorderType.Bottom, new Border()); //table.AutoFit = AutoFit.ColumnWidth;//.Window;
table.Rows[].Cells[].Paragraphs[].Append(table.Rows[].Cells[].Paragraphs.Count.ToString());
table.Rows[].Cells[].Paragraphs[].Alignment = Alignment.right;
table.Rows[].Cells[].Paragraphs[].Append("").FontSize();//字体大小设置
table.Rows[].Cells[].Paragraphs[].InsertText("测试1");
//颜色设置
table.Rows[].Cells[].Paragraphs[].Color(Color.DarkBlue);
//加粗
table.Rows[].Cells[].Paragraphs[].Bold();
table.Rows[].MergeCells(, );
for (; table.Rows[].Cells[].Paragraphs.Count != ; )
table.Rows[].Cells[].Paragraphs.Last().Remove(false);
table.Rows[].Cells[].Paragraphs[].InsertText("测试2");
table.Rows[].Cells[].Paragraphs[].Append("");
table.Rows[].Cells[].Paragraphs[].Append(table.Rows[].Cells[].Paragraphs[].Text.Length.ToString());
Paragraph p2 = document.InsertParagraph(); Table table1 = document.InsertTable(, );
table1.AutoFit = AutoFit.Window;
table1.Alignment = Alignment.center;
table1.SetBorder(TableBorderType.InsideH, new Border());
table1.SetBorder(TableBorderType.InsideV, new Border());
table1.SetBorder(TableBorderType.Top, new Border());
table1.SetBorder(TableBorderType.Right, new Border());
table1.SetBorder(TableBorderType.Left, new Border());
table1.SetBorder(TableBorderType.Bottom, new Border());
table1.Rows[].MergeCells(, ); table1.Rows[].Cells[].Paragraphs[].Append(table1.Rows[].Cells[].Paragraphs.Count.ToString());
table1.Rows[].Cells[].Paragraphs[].Alignment = Alignment.right;
table1.Rows[].Cells[].Paragraphs[].Append("");
table1.Rows[].Cells[].Paragraphs[].InsertText("测试1");
table1.Rows[].Cells[].Paragraphs[].Bold();
for (; table1.Rows[].Cells[].Paragraphs.Count > ; )
table1.Rows[].Cells[].Paragraphs.Last().Remove(false);
table1.Rows[].Cells[].Paragraphs[].InsertText("测试2");
table1.Rows[].Cells[].Paragraphs[].Append("31\r\n");
table1.Rows[].Cells[].Paragraphs[].Append(table1.Rows[].Cells[].Paragraphs[].Text.Length.ToString()); System.IO.MemoryStream stream = new MemoryStream();
//document.Save();
document.SaveAs(stream);
byte[] bytes = stream.ToArray();
stream.Close();
stream.Dispose();
context.Response.ContentType = "application/octet-stream";
//通知浏览器下载文件而不是打开
context.Response.AddHeader("Content-Disposition", "attachment; filename=" +
HttpUtility.UrlEncode("test.docx", System.Text.Encoding.UTF8));
context.Response.BinaryWrite(bytes);
context.Response.Flush();
HttpContext.Current.ApplicationInstance.CompleteRequest();
context.Response.End();
}
}

asp.net导出word(word2007)的更多相关文章

  1. ASP.NET导出word实例

    ASP.NET导出word实例 最近遇到一个题目就是如何在asp.net中将数据导出到word中,由于数据是动态的,所以需要在后台拼出想要的的格式,翻遍了网页找出了一个比较满意的代码,感谢那位高手.代 ...

  2. 【原创】asp.net导出word 检索 COM 类工厂中 CLSID 为 {000209FF-0000-0000-C000-000000000046} 的组件失败,原因是出现以下错误: 8000401a

    我的服务器:windows server 2008(64位)+microsoft office 2007 企业版 业务:网站导出应聘word简历. 出现以下错误: 检索 COM 类工厂中 CLSID ...

  3. Asp.Net导出文件名中文乱码

    Asp.Net导出word为例,Excel等其他文件也一样 protected void Page_Load(object sender, EventArgs e) {string html = “网 ...

  4. 【C#点滴记录】ASP.NET 使用C# 导出Word 和Excel

    原文摘自 慧优米网,链接地址:http://huiyoumi.wang/upload/forum.php?mod=viewthread&tid=797&extra= 好了正文来了 今天 ...

  5. asp.net导出excel-一行代码实现excel、xml、pdf、word、html、csv等7种格式文件导出功能而且美观-SNF快速开发平台

    分享: 腾讯微博  新浪微博   搜狐微博   网易微博  腾讯朋友  百度贴吧  豆瓣   QQ好友  人人网 作者:王春天  原文地址:http://www.cnblogs.com/spring_ ...

  6. Asp.net通过模板(.dot/Html)导出Word,同时导出图片

    一.Office组件导出Word(服务器配置麻烦) 需要引用Office的DLL,在下文的附件中,不同的Offic版本用的不一样,虽然高级版本可以兼容低级的,不过,还是统一版本最好 贴上核心代码(转载 ...

  7. ASP.NET MVC 导出Word报表

    最近要做MVC导出Word报表功能.查了查资料发现一个好用的插件就是Aspose.Word.这个插件也很有名气,也很好用. 1.首先就是引用该插件 2.填充Word模版 3.后台操作 private ...

  8. 导出Excel And 导出word

      <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default6.aspx. ...

  9. asp.net操作word的表格

    近日开发中用户要求实现导出数据为Word,本来想使用html保存为word的实现,但因用户要求样式很高,使用html不好控制,并且导出中包括图片,使用页面导出时图片还是一个路径,不能把图片包括在wor ...

随机推荐

  1. C语言笔试常考知识点

    1. const 关键字 a)  const int a; b)  int const a; c)  const int *a; d)  int * const a; e)  int const * ...

  2. CentOS 7 防火墙和端口配置

    centos 7 防火墙和端口配置--解决 RHEL 7/ CentOS 7/Fedora 出现Unit iptables.service failed to load # 第一步,关闭firewal ...

  3. 【转】DQL、DML、DDL、DCL的概念与区别

    转自 http://blog.csdn.net/tomatofly/article/details/5949070 SQL(Structure Query Language)语言是数据库的核心语言. ...

  4. YTU 3023: 树的遍历

    原文链接:https://www.dreamwings.cn/ytu3023/2617.html 3023: 树的遍历 时间限制: 1 Sec  内存限制: 128 MB 提交: 3  解决: 2 题 ...

  5. JS去掉数组的重复项

    自己知道思路怎么去,但是就是自己不会写,在网上找了一些来看,有些还是没有怎么看明白.学习到了这么一种方法 var a=['ss','dd','ss','cc','dd',1,2,1] var b={} ...

  6. python中的正则表达式(re模块)

    一.简介 正则表达式本身是一种小型的.高度专业化的编程语言,而在python中,通过内嵌集成re模块,程序媛们可以直接调用来实现正则匹配.正则表达式模式被编译成一系列的字节码,然后由用C编写的匹配引擎 ...

  7. jenkins插件开发-此路是我开

    一:前置环境 1. JDK1.6+ 2. maven已安装 3. jenkins已搭建 4. eclipse已安装(并安装了maven插件) 以上环境可以百度搜索并安装 我的环境是WIN7 64位系统 ...

  8. android 布局优化常用技巧

    android对多个模块都要是要的UI逻辑的致辞除了fragment之外,没有别的东西可以支持了, include,merge,viewstub只能支持公用的ui,但是这个通用支持不能包含逻辑(jav ...

  9. 制作登录界面,登录成功后把用户名放在session里,在第3个页面读取session显示用户名

    <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...

  10. Trying to hack Redis via HTTP requests

    Trying to hack Redis via HTTP requests Context Imagine than you can access a Redis server via HTTP r ...