没有找到合适的产品?
联系客服协助选型:023-68661681
提供3000多款全球软件/控件产品
针对软件研发的各个阶段提供专业培训与技术咨询
根据客户需求提供定制化的软件开发服务
全球知名设计软件,显著提升设计质量
打造以经营为中心,实现生产过程透明化管理
帮助企业合理产能分配,提高资源利用率
快速打造数字化生产线,实现全流程追溯
生产过程精准追溯,满足企业合规要求
以六西格玛为理论基础,实现产品质量全数字化管理
通过大屏电子看板,实现车间透明化管理
对设备进行全生命周期管理,提高设备综合利用率
实现设备数据的实时采集与监控
利用数字化技术提升油气勘探的效率和成功率
钻井计划优化、实时监控和风险评估
提供业务洞察与决策支持实现数据驱动决策
翻译|使用教程|编辑:况鱼杰|2020-10-09 14:19:52.380|阅读 522 次
概述:MailMerge是一个强大的,可扩展的框架,允许您将自定义逻辑注入合并过程。TXTextControl.DocumentServer.MailMerge.FieldMerged事件可用于处理结果,但也可以访问TXTextControl.TableCell类的周围实例。这使您可以根据特定的过滤器指令来实现诸如条件表单元格颜色之类的功能。
# 界面/图表报表/文档/IDE等千款热门软控件火热销售中 >>
相关链接:
TX Text Control Server for ASP.NET (incl. WPF)是一个企业级的服务器端文字处理控件。它为用于ASP.NET服务器环境提供一个完全可编程的文字处理引擎,并且包含一个WPF客户端版本。
点击下载TX Text Control Server for ASP.NET (incl. WPF)最新试用版
MailMerge是一个强大的,可扩展的框架,允许您将自定义逻辑注入合并过程。
TXTextControl.DocumentServer.MailMerge.FieldMerged事件可用于处理结果,但也可以访问TXTextControl.TableCell类的周围实例。这使您可以根据特定的过滤器指令来实现诸如条件表单元格颜色之类的功能。
在此示例中,如果数量大于10,则表单元格“数量”应突出显示为红色,否则应为绿色。

该示例显示了两个有趣的方面:
该示例实现HTML表单元素以设置表单元格的条件。如果输入位置在表格单元格内部,则以下代码用于通过将对象序列化为Json字符串将条件存储在表格单元格中:
// stores the selected conditions in the cell name
function setTableCellConditions(empty = false) {
TXTextControl.tables.getItem(function (table) {
if (table === null)
return; // no table
// create a cellFilterInstructions object
var cellFilterInstructions = {
compareValue: document.getElementById("compareValue").value,
operator: document.getElementById("operator").value,
trueColor: document.getElementById("trueColor").value,
falseColor: document.getElementById("falseColor").value
}
table.cells.getItemAtInputPosition(function (cell) {
if (cell === null)
return; // no cell
if (empty === true)
cell.setName(""); // delete instructions
else
// sel instructions to cell name
cell.setName(JSON.stringify(cellFilterInstructions));
});
})
}
如果将输入位置更改为另一个单元格,则会更新表单元素以反映该单元格的条件:
// check cell status on input position changes
TXTextControl.addEventListener("inputPositionChanged", function () {
TXTextControl.tables.getItem(function (table) { // table at input pos?
if (table === null) { // return if no table available
EnableFormElements(
["operator", "compareValue", "trueColor", "falseColor", "enableCondition"],
false); return;
}
// enable form elements
EnableFormElements(
["operator", "compareValue", "trueColor", "falseColor", "enableCondition"],
true);
table.cells.getItemAtInputPosition(function (cell) { // cell at input pos
if (cell == null) { // return if more cells are selected
enableCellConditions(false);
document.getElementById("enableCondition").setAttribute(
"disabled", "disabled");
return;
}
// check the cell name that stores the conditions
cell.getName(function (cellName) {
if (cellName === "") { enableCellConditions(false); return; }
updateSettings(JSON.parse(cellName));
});
});
})
});
最后,当单击合并时,将保存文档并将其发送到后端控制器:
function mergeDocument() {
TXTextControl.saveDocument(TXTextControl.streamType.InternalUnicodeFormat,
function (e) {
var serviceURL = "/Home/MergeDocument";
$.ajax({
type: "POST",
url: serviceURL,
contentType: 'application/json',
data: JSON.stringify({
Document: e.data,
}),
success: successFunc,
error: errorFunc
});
function successFunc(data, status) {
TXTextControl.loadDocument(TXTextControl.streamType.InternalUnicodeFormat, data);
}
function errorFunc(error) {
console.log(error);
}
});
}
在控制器中,HttpPost方法接受文档并调用MergeJsonData方法以将数据合并到给定的模板中:
[HttpPost]
public string MergeDocument(string Document)
{
using (TXTextControl.ServerTextControl tx = new TXTextControl.ServerTextControl())
{
tx.Create();
tx.Load(Convert.FromBase64String(Document),
TXTextControl.BinaryStreamType.InternalUnicodeFormat);
using (TXTextControl.DocumentServer.MailMerge mailMerge =
new TXTextControl.DocumentServer.MailMerge())
{
mailMerge.TextComponent = tx;
mailMerge.FieldMerged += MailMerge_FieldMerged;
string data = System.IO.File.ReadAllText(Server.MapPath("~/App_Data/data.json"));
mailMerge.MergeJsonData(data, false);
}
byte[] results;
tx.Save(out results, TXTextControl.BinaryStreamType.InternalUnicodeFormat);
return Convert.ToBase64String(results);
}
}
附加了FieldMerged事件以处理自定义条件。 如果字段在表格单元格内,则将TableCell.Name属性反序列化为CellFilterInstructions对象,以便根据定义的指令应用表格单元格的颜色。
private void MailMerge_FieldMerged(object sender,
TXTextControl.DocumentServer.MailMerge.FieldMergedEventArgs e)
{
// custom field handling
if (e.TableCell == null)
return;
// if TableCell.Name has instructions, create a CellFilterInstructions object
// and evaluate the instructions and set the table cell color
if (e.TableCell.Name != "")
{
CellFilterInstructions instructions =
(CellFilterInstructions)JsonConvert.DeserializeObject(
e.TableCell.Name, typeof(CellFilterInstructions));
// retrieve the color
Color? color = instructions.GetColor(e.MailMergeFieldAdapter.ApplicationField.Text);
// apply the color
if (color != null)
e.TableCell.CellFormat.BackColor = (Color)color;
}
}
关注慧聚IT微信公众号 ☟☟☟,了解产品的最新动态及最新资讯。
本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@ke049m.cn
文章转载自:



注意: Cogent DataHub 软件 v11 包含一些新功能,您的目标操作系统可能不支持这些功能。
本教程主要为大家介绍如何使用DevExpress WinForms数据网格控件进行数据排序的基础知识,欢迎下载最新版组件体验!
在使用Parasoft C/C++test执行BugDetective数据流分析时,可能会遇到用户自定义的资源API,那在这种情况下,若要判断是否存在资源问题,如资源泄露等,则需要手动配置测试配置。
大型SaaS系统的自动化测试常常受制于界面变化快、结构复杂、加载机制多变等因素。从元素识别到脚本管理,SmartBear TestComplete帮助Salesforce建了可靠的自动化测试体系。
相关产品
一个将文档处理集成到 Web 应用程序中的文档管理控件。
最新文章 MORE
半岛外围网上直营相关的文章 MORE
服务电话
重庆/ 023-68661681
华东/ 13452821722
华南/ 18100878085
华北/ 17347785263
客户支持
技术支持咨询服务
服务热线:400-700-1020
邮箱:sales@ke049m.cn
关注我们
地址 : 重庆市九龙坡区火炬大道69号6幢
半岛外围网上直营