asp.net导出word(word2007)
1、只能导出成word2007格式(.docx),可直接导出到客户端
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)的更多相关文章
- ASP.NET导出word实例
ASP.NET导出word实例 最近遇到一个题目就是如何在asp.net中将数据导出到word中,由于数据是动态的,所以需要在后台拼出想要的的格式,翻遍了网页找出了一个比较满意的代码,感谢那位高手.代 ...
- 【原创】asp.net导出word 检索 COM 类工厂中 CLSID 为 {000209FF-0000-0000-C000-000000000046} 的组件失败,原因是出现以下错误: 8000401a
我的服务器:windows server 2008(64位)+microsoft office 2007 企业版 业务:网站导出应聘word简历. 出现以下错误: 检索 COM 类工厂中 CLSID ...
- Asp.Net导出文件名中文乱码
Asp.Net导出word为例,Excel等其他文件也一样 protected void Page_Load(object sender, EventArgs e) {string html = “网 ...
- 【C#点滴记录】ASP.NET 使用C# 导出Word 和Excel
原文摘自 慧优米网,链接地址:http://huiyoumi.wang/upload/forum.php?mod=viewthread&tid=797&extra= 好了正文来了 今天 ...
- asp.net导出excel-一行代码实现excel、xml、pdf、word、html、csv等7种格式文件导出功能而且美观-SNF快速开发平台
分享: 腾讯微博 新浪微博 搜狐微博 网易微博 腾讯朋友 百度贴吧 豆瓣 QQ好友 人人网 作者:王春天 原文地址:http://www.cnblogs.com/spring_ ...
- Asp.net通过模板(.dot/Html)导出Word,同时导出图片
一.Office组件导出Word(服务器配置麻烦) 需要引用Office的DLL,在下文的附件中,不同的Offic版本用的不一样,虽然高级版本可以兼容低级的,不过,还是统一版本最好 贴上核心代码(转载 ...
- ASP.NET MVC 导出Word报表
最近要做MVC导出Word报表功能.查了查资料发现一个好用的插件就是Aspose.Word.这个插件也很有名气,也很好用. 1.首先就是引用该插件 2.填充Word模版 3.后台操作 private ...
- 导出Excel And 导出word
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default6.aspx. ...
- asp.net操作word的表格
近日开发中用户要求实现导出数据为Word,本来想使用html保存为word的实现,但因用户要求样式很高,使用html不好控制,并且导出中包括图片,使用页面导出时图片还是一个路径,不能把图片包括在wor ...
随机推荐
- iOS使用textfield注意的细节
一般做登录界面或者要填写表之类的页面会经常使用到textfield.使用很简单,但是其实他有很多小的处理细节,这回让你显得有经验,交互性很好.在这里呢,我就直接拿stroyboard中的截图来说. c ...
- 关于file的上传文件
http://blog.csdn.net/wclxyn/article/details/7090575/
- Uva 11478 Halum操作
题目链接:http://vjudge.net/contest/143318#problem/B 题意:给定一个有向图,每条边都有一个权值.每次你可以选择一个结点v和一个整数d,把所有以v为终点的边的权 ...
- Linux 各文件夹介绍
http://www.cnblogs.com/amboyna/archive/2008/02/16/1070474.html linux下的文件结构,看看每个文件夹都是干吗用的/bin 二进制可执行命 ...
- Dialog , ProgressDialog , PopWindow 区别
本质区别: Dialog:非阻塞对话框,弹出对话框时时,后台还可以做事情,点击背景时,对话框消失 ProgressDialog:带有圆形进度或者条形进度的对话框,一般结合handler使用.任务完成后 ...
- How To Use DBLink In Oracle Forms 6i
You want to connect multiple databases in oracle forms to perform certain tasks, for example you nee ...
- Key Figure、Exception Aggreagion、Non-Cumulative KeyFigure
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- JQuery对表格进行排序
添加相关jar <script type="text/javascript" src="jquery-1.1.3.pack.js"></scr ...
- fifter常见的运用场景
没配置过滤器 package servlet; import java.io.IOException; import javax.servlet.ServletException; import ja ...
- 转!!log4j基础
log4j组件介绍 Log4j主要有三个组件: Logger:负责供客户端代码调用,执行debug(Object msg).info(Object msg).warn(Object msg).erro ...