Aspose.Words关于域的应用
#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关于域的应用的更多相关文章
- .net MVC使用Aspose.Words 获取文本域获取文档
controller 1 using Aspose.Words; 2 using Aspose.Words.Saving; 3 using System.IO; 4 5 6 /// 7 /// 获取导 ...
- Aspose Word模板使用总结
Aspose Word模板使用总结 1.创建word模版,使用MergeFeild绑定数据 新建一个Word文档,命名为Template.doc 注意:这里并不是输入"< ...
- aspose输出表格
利用aspose在word中输出表格 序号 姓名 性别 <<TableStart:T>><<Index>> <<Name>> ...
- aspose.word使用简单方法
概念介绍 使用aspose生成word报表步骤: 加载word模板 提供数据源 填充 加载模板 提供了4种重载方法 public Document(); public Document(Stream ...
- Aspose.word总结
1.创建word模版,使用MergeFeild绑定数据 新建一个Word文档,命名为Template.doc 注意:这里并不是输入"<”和“>”就可以了,而是必须 ...
- Aspose.Words 总结
生成答题卡 try { string tempPath = @"D:\moban\ttt.doc"; //Open document and create Documentbuil ...
- 关于ASPOSE.WORD使用上的一个小问题
最近实习期间负责了公司某个项目的一个功能模块里面的word导出功能,使用的是ASPOSE.WORD类库,但是经常导出时候会遇到图中的问题,大概意思就是两个表格不能跨在一起,调试了好几次还是没发现具体的 ...
- Aspose.Words的Merge Field
今天应客户要求,修改导出word模板.使用的是Aspose.Words插件.这个程序原是同事所写,且自己对Aspose不是很了解.在替换模板上花费了一些时间. 先来一张图:下图是原来的模板.现在要求删 ...
- Aspose.Words五 MergeField
通过MegerField来循环,将数据保存到dataset的table中,dataset通过关联datarelation字段来指定主从表关系.模板中通过标签TableStart和TableEnd来框定 ...
随机推荐
- jquery提交form表单插件jquery.form.js
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Log4j中配置日志文件相对路径
方法一. 解决的办法自然是用相对路径代替绝对路径,其实log4j的FileAppender本身就有这样的机制,如:log4j.appender.logfile.File=${WORKDIR}/logs ...
- [leetcode-543-Diameter of Binary Tree]
Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of a b ...
- 2.vue 安装教程
安装node.js 从node.js官网下载并安装node,安装过程很简单,一路"下一步"就可以了(傻瓜式安装). 安装完成之后,打开命令行工具,输入 node -v,如下图,如果 ...
- 多表链接 Left join
select * from( select U_User.LinkMan, SP_Approval.* ,SP_Approval_Msg.ApprovalUserID,ROW_NUMBER() ...
- Java算法-------无序数组中的最长连续序列---------leetcode128
Given an unsorted array of integers, find the length of the longest consecutive elements sequence. F ...
- IP协议详解
Internet地址结构 表示IP地址 目前的IP版本有4和6. 目前最流行的就是IPv4,有十进制和二进制两种表示方法.分别是: 点分四组十进制.每一组范围是[0~255],如:255.255.25 ...
- bzoj1041题解
求一个给定的圆(x^2+y^2=r^2),在圆周上有多少个点的坐标是整数.r<=2000 000 000 这道题刚看时,就明白暴力不能解决一切.要是r^2<=20亿,还可以sqrt循环, ...
- Python学习笔记——import模块
OS模块 直接输出系统命令到屏幕,该方法获取的命令返回值不可被赋值给变量,输出结果受编码影响会乱码: import os os.system("ipconfig") 将执行获取的系 ...
- spring boot 拦截器添加
@Configuration public class WebMvcConfig extends WebMvcConfigurerAdapter { @Autowired private XxxInt ...