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. Word Reversal

    For each list of words, output a line with each word reversed without changing   the order of the wo ...

  2. Script 简单语句的练习题

    猜拳 <body>请输入剪刀或者石头或者布:<br /><input type="text" id="A"/><inp ...

  3. jQuery和Ajax的使用(杂记)

    在jsp文件的获取绝对路径标签,其他jsp文件调用就行了 <%@ page language="java" contentType="text/html; char ...

  4. ios html5 网页取消默认样式

    ios的的默认样式修改成扁平化的样式 重要的一句css  -webkit-appearance: none;  将样式清除 单数会出现将raido的选择按钮也会消失 所以需要对radio的样式进行重新 ...

  5. prototype与原型链

    1.今天翻看 阮一峰老师的博客看到了,一篇讲javascript为什么要设计出prototype,跳转      大意就是new 的方式有缺陷,没有共同的属性,一下明白了很多. 在来一张原型链的图:

  6. [bzoj1103][POI2007]大都市meg(树状数组+dfs序)

    1103: [POI2007]大都市meg Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2031  Solved: 1069[Submit][Sta ...

  7. 转{QQ浏览器X5内核问题汇总}

    转自https://www.qianduan.net/qqliu-lan-qi-x5nei-he-wen-ti-hui-zong/ 常常被人问及微信中使用的X5内核的问题,其实我也不是很清楚,只知道它 ...

  8. [Prodinner项目]学习分享_第四部分(完结篇)_Controller层(控制器)

    Controller作用: 数据从数据库查询出来后,通过一定的业务逻辑,筛选出来一个结果集,我们最终的目的是要将这个结果集在页面中显示的. Controller就是起到这个作用,将业务逻辑层的结果集调 ...

  9. mac 显示set a breakpoint in malloc_error_break to debug 终端显示进程已完成怎么办?

    mac 终端显示 ,0x7fff73dbd300) malloc: *** error for object 0x7fce52d15100: pointer being freed was not a ...

  10. Html_Img元素 设置图片与其他元素横排高度一致

    <img id="numAdd" src="~/Images/jia.jpg" style="width:30px;height:30px;ve ...