在OpenXml文档中,有一些内容控件可以填充数据,但CRLF不会绑定或使用Word文档。句子一起运行而不是换行。
在将值写入内容控件的代码中,有一个换行符,&#34; \ n&#34;添加,所以 <w:br w:type="textWrapping" w:clear="all" />
customer1 +&#34; \ n&#34; + customer2 +&#34; \ n&#34;
没有效果,没有CRLF
在HTML textarea中然而它看到了格式并且应用它很好,但是当它放入docx这个词时,句子没有CRLF。尝试添加0x0a,0x0d。在文档中看起来应该添加的内容是:
function renderCategoryList (receivedCategories) {
var allCategories = [];
for (var i in receivedCategories) {
var category = {}
category.categoryName = receivedCategories[i].Name;
category.categoryId = receivedCategories[i].Id;
category.categoryParentCategoryId = receivedCategories[i].ParentCategoryId;
if (receivedCategories[i].ParentCategoryId != null) {
var parentLevel = 0;
var parentId = receivedCategories[i].ParentCategoryId;
for (var z = 0; receivedCategories.length > z; z++) {
var parentName = "parentName" + parentLevel;
if (receivedCategories[z].Id == parentId) {
category.parentName = receivedCategories[z].Name; // the "category.parentName" should be dynamic. At first run this should be category.parentName0.
parentId = receivedCategories[z].ParentCategoryId
var parentExists = true;
parentLevel++; //if a parentId exists this should raise the level with +1 and therefore at the next run the name should be "category.parentName1".
z = 0;
}
}
}
allCategories.push(category);
}
return allCategories;
}
在应该有CRLF的部分之后,所以或许另一个问题是如何在openxml中添加这样的标签+有效负载呢?
答案 0 :(得分:0)
在OpenXml中,段落的构造是特殊的。 标签文本应该只包含文本,CRLR是格式而不是文本。
要做你想做的事,你必须:
示例是
case "custname":
Run run = cc.Descendants<Run>().First();
foreach(string customer in customers)
{
run.Append(new Text(customer));
run.Append(new Break());
}
您必须将此代码改编为: