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 ...
随机推荐
- Hadoop 2.0命令手册
1. FS Shell 1.1 简介 调用文件系统(FS)Shell命令应使用 bin/hadoop fs <args>的形式. 所有的的FS shell命令使用URI ...
- Python—进程、线程、协程
一.线程 线程是操作系统能够进行运算调度的最小单位.它被包含在进程之中,是进程中的实际运作单位.一条线程指的是进程中一个单一顺序的控制流,一个进程中可以并发多个线程,每条线程并行执行不同的任务 方法: ...
- POJ 2420:A Star not a Tree?
原文链接:https://www.dreamwings.cn/poj2420/2838.html A Star not a Tree? Time Limit: 1000MS Memory Limi ...
- 【小白入门向】tarjan算法+codevs1332上白泽慧音 题解报告
一.[前言]关于tarjan tarjan算法是由Robert Tarjan提出的求解有向图强连通分量的算法. 那么问题来了找蓝翔!(划掉)什么是强连通分量? 我们定义:如果两个顶点互相连通(即存在A ...
- 我的android学习经历34
用类对象作为ArrayAdapter绑定的基本数据类型(和SimpleAdater效果类似) 一般ArrayAdapter绑定的基本数据类型是String,接下来介绍一下类对象作为基本数据类型: 首先 ...
- 【Unity3D游戏开发】之全局管理类的几种方式 (十六)
如何在Unity中实现全局管理类?由于Unity脚本的运行机制和面向组件编程(COP)的思想,实现起来和普通的方式略有差别. 第一种方式是使用静态类.适合存储一些全局的变量,如游戏当前关卡.玩家得分等 ...
- Linux -- 文件统计常用命令
标签(空格分隔): Linux sort -- 文件内排序命令 sort将文件的每一行作为一个单位,相互比较,比较原则是从首字符向后,依次比较其ASCII码. 按每行升序排序: sort seq.tx ...
- 20个Linux服务器安全强化建议(二)
接上文,继续介绍一些Linux服务器的安全配置. #6.强密码策略. 当我们使用 useradd.usermod 命令创建或维护用户账号时,确保始终应用强密码策略.例如,一个好的密码至少包括8个字 ...
- 微信小程序配置文件
app.json 配置文件中不能有注释 { "pages": [ // 必填 设置页面路径 "pages/index/index", "pages ...
- [css]需警惕CSS3属性的书写顺序
转载张鑫旭:http://www.zhangxinxu.com/wordpress/2010/09/%E9%9C%80%E8%AD%A6%E6%83%95css3%E5%B1%9E%E6%80%A7% ...