#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. oracle sql语句跟踪及性能分析工具实现

    在网上找了一大圈,没找着合适的工具来跟踪oracle一段时间的sql. 我们的场景是打算自动化跑遍所有场景(rft)+fiddler跟踪请求+后端跟踪sql,根据结果去分析慢的请求和sql,本来awr ...

  2. windows环境下,怎么解决无法使用ping命令

    基本都是因为"环境变量"导致的,查看环境变量path在"Path"中追加"C:\Windows\System32"

  3. abelkhan中的rpc框架

    rpc简介:http://www.ibm.com/developerworks/cn/aix/library/au-rpc_programming/index.html 常见的rpc框架有protob ...

  4. smarty模板自定义变量

    一.通过smarty方式调用变量调节器 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" &quo ...

  5. JAVAEE——spring03:spring整合JDBC和aop事务

    一.spring整合JDBC 1.spring提供了很多模板整合Dao技术 2.spring中提供了一个可以操作数据库的对象.对象封装了jdbc技术. JDBCTemplate => JDBC模 ...

  6. 【Android Developers Training】 51. 序言:打印内容

    注:本文翻译自Google官方的Android Developers Training文档,译者技术一般,由于喜爱安卓而产生了翻译的念头,纯属个人兴趣爱好. 原文链接:http://developer ...

  7. Object-C知识点 (三) 单例 蒙版 刷新 KVO底层

    #pragma mark - 单例方法(完整的方法) 系统的单例方法名称 sharedApplication defaultManager standardUserDefaults currentDe ...

  8. Pandas数据处理实战:福布斯全球上市企业排行榜数据整理

    手头现在有一份福布斯2016年全球上市企业2000强排行榜的数据,但原始数据并不规范,需要处理后才能进一步使用. 本文通过实例操作来介绍用pandas进行数据整理. 照例先说下我的运行环境,如下: w ...

  9. Vue.js学习笔记(二) - 常用模板语法

    本篇将在上一篇的基础上记录文本渲染.表达式.过滤器以及常用指令的简单用法. 一.文本渲染 Vue支持动态渲染文本,即在修改属性的同时,实时渲染文本内容.同时为了提高渲染效率,也支持只渲染一次,即第一次 ...

  10. Chrome浏览器扩展开发系列之一:初识Google Chrome扩展

    1.       Google Chrome扩展简介 Google Chrome扩展是一种软件,以增强Chrome浏览器的功能. Google Chrome扩展使用HTML.JavaScript.CS ...