#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. .Net上传文件大小配置

    1.起因 今天同事在上传文件的时候,发现一直失败,说文件比较大.一听就明白了,肯定是上传文件大小的问题啊.然后查看web.config文件,发现设置过文件上传的大小限制.配置文件上传大小,分为2部分. ...

  2. CentOS yum 安装 PHP 5.6.24

    配置yum源 追加CentOS 6.5的epel及remi源. # rpm -Uvh http://ftp.iij.ad.jp/pub/linux/fedora/epel/6/x86_64/epel- ...

  3. 【Android Developers Training】 23. 序言:保存数据

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

  4. python3中socket套接字的编码问题解决

    一.TCP 1.tcp服务器创建 #创建服务器 from socket import * from time import ctime #导入ctime HOST = '' #任意主机 PORT = ...

  5. 【转】iOS 9 Storyboard 教程(一上)

    转自:http://blog.csdn.net/yangmeng13930719363/article/details/49886547 Storyboard是在iOS5之后新增的一个令人兴奋的功能, ...

  6. C#开发移动应用系列(4.调用系统应用,以及第三方应用(调用与被调用))

    前言 上篇文章地址: C#开发移动应用系列(1.环境搭建) C#开发移动应用系列(2.使用WebView搭建WebApp应用) C#开发移动应用系列(3.使用照相机扫描二维码+各种基础知识) 写完这篇 ...

  7. vue.js+UEditor集成 [前后端分离项目]

    首先,谈下这篇文章中的前后端所涉及到的技术框架内容. 虽然是后端的管理项目,但整体项目,是采用前后端分离的方式完成,这样做的目的也是产品化的需求: 前端,vue+vuex+vue router+web ...

  8. VMvare虚拟机的安装及新建虚拟机.

    一.VMvare虚拟机的安装 1.首先双击--你下载的安装包,这里我分享百度云盘,供大家下载:http://pan.baidu.com/s/1jImQSZG 2.VMware Workstation ...

  9. 安装GPU版本的tensorflow填过的那些坑!---CUDA说再见!

    那些坑,那些说不出的痛! --------回首安装的过程,真的是填了一个坑又出现了一坑的感觉.记录下了算是自己的笔记也能给需要的人提供一点帮助. 1 写在前面的话 其实在装GPU版本的tensorfl ...

  10. JavaWeb 后端 <五> 之 JSP 学习笔记

    一.JSP简介 1.也是SUN公司推出的开发动态web资源的技术,属于JavaEE技术之一.由于原理上是Servlet, 所以JSP/Servlet在一起. 二.HTML.Servlet和JSP 1. ...