#region 通过word域去插入相应的数据
/// <summary>
/// 通过word域去进行指定位置替换数据
/// </summary>
public void WordHelpers() {
       string filepath = FileHelper.GetDateDir();
       FileHelper.CreateDirectory(System.Web.HttpContext.Current.Server.MapPath("/Upload/" + filepath + ""));
       string pathsrc =System.Web.HttpContext.Current.Server.MapPath("~\\Content\\word.docx");//word文件路径
       string[] filedName = new string[] { "Test", "Text1" };//域名
       object[] values = new object[] {"2","2"};//相应数据
       Document dm = new Document(pathsrc);
       dm.MailMerge.Execute(filedName, values);
       dm.Save(System.Web.HttpContext.Current.Server.MapPath("~\\Upload\\" + filepath + "\\" + Guid.NewGuid() +".doc" + ""));
}
#endregion

  对于上面这种既有要循环展示的数据又有固定展示的数据  循环列添加《TableStart:List》   《TableEnd:List》 
 

    /// <summary>
/// 订单打印
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void BtnPrint_Click(object sender, EventArgs e)
{
     string FilePath = FileHelper.GetDateDir();//根据时间得到目录名
     FileHelper.CreateDirectory(System.Web.HttpContext.Current.Server.MapPath("/upload-file/order/Orders/"+ FilePath));//创建一个目录
     string OrderTemp = System.Web.HttpContext.Current.Server.MapPath("~\\upload-file\\detail\\order\\ScHt.docx");//获取模板
     Document dm = new Document(OrderTemp);
     string[] filedName = new string[] { "Buyer", "orderId", "ForderId",
     "TotalPirce", "BackPirce", "YfPirce", "Payment", "Delivery", "Receive", "CName" , "DateTime","ChPrice" };//对应的域名
     HttpCookie userName = Request.Cookies[Cookie.UserNameCookieName];
     Member member = new MemberBusiness().GetEntityByUserName(userName.Value);
     OrderBusiness orderBusiness = new OrderBusiness();
     Order ordermodel=orderBusiness.GetEntity(lOrderNo.Text);
     object[] values = new object[] { member.CusName,ordermodel.GroupOrderId,lOrderNo.Text,ordermodel.TotalMoney,ordermodel.DiscountMoney, (ordermodel.TotalMoney - ordermodel.Disco      untMoney).ToString(),
     lPaymentMethod.Text, lShoppingMethod.Text, lShoppingDate.Text, lReceiver.Text,ordermodel.CreateDate, MoneyConvertChinese.MoneyToChinese((ordermodel.TotalMoney - ordermodel.Dis      countMoney).ToString())};//相对应的值内容
     OrderItemBusiness orderItemBusiness = new OrderItemBusiness();
     string where = "order_id='" + lOrderNo.Text + "'";
     string fieldList = "afd_stkNo,product_id,price,quantity,total_money";
     DataTable table = orderItemBusiness.GetList(fieldList, "Id", false, 1, 20, where).Table;
     table.TableName = "List";//这边要注意的是datatable的名称一定要和域循环的名称相对应
     table.Columns.Add("ProName");
     com.eshop.www.BLL.ProductDetailBusiness bllProd = new ProductDetailBusiness();
     foreach (DataRow dr in table.Rows) {
     dr["ProName"]= bllProd.GetEntity(int.Parse(dr["product_id"].ToString())).ProductName;
     }      dm.MailMerge.ExecuteWithRegions(table);//datatable列名要和循环内的域名称保持一致
     dm.MailMerge.Execute(filedName, values);
     string url = System.Web.HttpContext.Current.Server.MapPath("~\\upload-file\\order\\Orders\\" + FilePath + "\\" + Guid.NewGuid() + ".doc");
     dm.Save(url);
     Response.Clear();
     Response.Buffer = true;
     Response.Charset = "utf-8";
     Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(url, System.Text.Encoding.UTF8));
     Response.ContentType = "application/octet-stream";
     Response.WriteFile(url);
     Response.Flush();
     Response.Close();
     Response.End();
     dm.Clone();      JavascriptHelper.Alert("打印成功!");
}
目前我只应用过这两种导出方式下面在添加一种方式只是简单测试一下

        public void WordHelpers(DataTable dt)
{
    string filepath = FileHelper.GetDateDir();
    FileHelper.CreateDirectory(System.Web.HttpContext.Current.Server.MapPath("/Upload/" + filepath + ""));
    //创建字符输出流
    StreamWriter sw = new StreamWriter("~\\Upload\\" + filepath + "\\" + Guid.NewGuid() + ".doc" + "", true, System.Text.UnicodeEncoding.UTF8);
    //需要导出的内容
    string str = "";
    str += "<html><head><title>无标题文档</title></head><body>";
    str += "<div>部门表格</div>";
    str += "<table> <thead>";
    str += "<tr> <th>部门名称</th> <th> 添加时间 </th> <th> 介绍 </th> </tr>";
    str += " <tbody>";
    foreach (DataRow dr in dt.Rows)
    {
    str += "<tr>";
    str += "<td>" + dr[""] + "</td>";
    str += "</tr>";
    }
    str += " </tbody>";
    str += "</table></body></html>";
    //写入
    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(dirpath + fileName);
    //Response.Flush();
    //Response.Close();
    //Response.End();
}

Aspose.Words关于域的应用的更多相关文章

  1. .net MVC使用Aspose.Words 获取文本域获取文档

    controller 1 using Aspose.Words; 2 using Aspose.Words.Saving; 3 using System.IO; 4 5 6 /// 7 /// 获取导 ...

  2. Aspose Word模板使用总结

    Aspose Word模板使用总结 1.创建word模版,使用MergeFeild绑定数据     新建一个Word文档,命名为Template.doc     注意:这里并不是输入"< ...

  3. aspose输出表格

    利用aspose在word中输出表格 序号 姓名 性别  <<TableStart:T>><<Index>>  <<Name>> ...

  4. aspose.word使用简单方法

    概念介绍 使用aspose生成word报表步骤: 加载word模板 提供数据源 填充 加载模板 提供了4种重载方法 public Document(); public Document(Stream ...

  5. Aspose.word总结

    1.创建word模版,使用MergeFeild绑定数据     新建一个Word文档,命名为Template.doc     注意:这里并不是输入"<”和“>”就可以了,而是必须 ...

  6. Aspose.Words 总结

    生成答题卡 try { string tempPath = @"D:\moban\ttt.doc"; //Open document and create Documentbuil ...

  7. 关于ASPOSE.WORD使用上的一个小问题

    最近实习期间负责了公司某个项目的一个功能模块里面的word导出功能,使用的是ASPOSE.WORD类库,但是经常导出时候会遇到图中的问题,大概意思就是两个表格不能跨在一起,调试了好几次还是没发现具体的 ...

  8. Aspose.Words的Merge Field

    今天应客户要求,修改导出word模板.使用的是Aspose.Words插件.这个程序原是同事所写,且自己对Aspose不是很了解.在替换模板上花费了一些时间. 先来一张图:下图是原来的模板.现在要求删 ...

  9. Aspose.Words五 MergeField

    通过MegerField来循环,将数据保存到dataset的table中,dataset通过关联datarelation字段来指定主从表关系.模板中通过标签TableStart和TableEnd来框定 ...

随机推荐

  1. Redis的安装与使用(单节点)

    IP:192.168.4.111 环境:CentOS 6.6 Redis版本:redis-3.0 (考虑到Redis3.0在集群和性能提升方面的特性,rc版为正式版的候选版,而且很快就出正式版) 安装 ...

  2. 怎样用DOS命令创建txt文本文档

    单击运行, 打开命令提示符. 例如在D盘创建文本文档,那么就先进入D盘,在后面写 D: 于是就进入了D盘怎样用DOS命令创建txt文本文档 然后在后面写命令 copy con 文件名.txt ,然后回 ...

  3. AS中layout_gravity与gravity的区别

    gravity 这个英文单词是重心的意思,在这里就表示停靠位置的意思. android:layout_gravity 和 android:gravity 的区别 从名字上可以看到,android:gr ...

  4. Bootstrap下拉菜单

    前面的话 网页交互的时候经常会需要上下文菜单或者隐藏/显示菜单项,Bootstrap默认提供了用于显示链接列表的可切换.有上下文的菜单.而且在各种交互状态下的菜单展示需要和javascript插件配合 ...

  5. ReactJS基础(续)

    前边的ReactJS基础,我们可以了解到,对于React,可以说是万物皆组件 React的组件应该具有 可组合(Composeable)可重用(Reusable)可维护(Maintainable)的特 ...

  6. weblogic 部署问题定位与解决

    weblogic 做为商用中间件在(EJB.jndi 数据源.日志管理.内存管理.资源配置管理...)  是一些开源免费小型容器无法望其项背的. weblogic 最早由 weblogic Inc. ...

  7. Python爬虫学习之爬美女图片

    最近看机器学习挺火的,然后,想要借助业余时间,来学习Python,希望能为来年找一份比较好的工作. 首先,学习得要有动力,动力,从哪里来呢?肯定是从日常需求之中来.我学Python看网上介绍.能通过P ...

  8. MySQL(二)--事务与视图

    一.事务 1.提交 2.回滚 3.ACID特性 二.视图 1.创建视图 2.删除视图 3.更新视图 4.使用视图 三.子查询 1. 使用子查询 2. 标量子查询 3. 关联子查询 一.事务 在 RDB ...

  9. [图形学] Chp8.4 OpenGL 二维观察函数——视口

    这节有几个显示窗口的控制函数,可以调整视口,创建子窗口,最小化为图标,设置图标名称,隐藏显示等. gluOrtho2D (xwmin, xwmax, ywmin, ywmax); // 定义二维裁剪窗 ...

  10. mysql性能监控工具

    参考文档: http://www.linuxidc.com/Linux/2012-09/70459.htm 1.记录慢查询SQL #配置开启 (linux)修改my.cnf: log-slow-que ...