I have a docx word document that contains table and table cell with mergefield inside.
我想将表格单元格的背景更改为橙色值(#EA6E24),但我找不到字段和方法。
所以这是我的代码处理字段的邮件合并并尝试向表格单元格添加阴影。
fldCode = parent.Descendants<FieldCode>().FirstOrDefault();
if (fldCode != null && fldCode.InnerText.Contains("MERGEFIELD") &&
{
var ancestors = fldCode.Ancestors<TableCell>();
// trouver et colorier le parent
fieldName = "";
var shading = new Shading()
{
Color = "auto",
Fill = "#EA6E24",
Val = ShadingPatternValues.Clear
};
foreach (var ancestor in ancestors)
{
ancestor.Append(shading);
}
}
答案 0 :(得分:0)
解决方案是访问并覆盖着色属性。
foreach (var ancestor in ancestors)
{
var tableCellProperties = ancestor.TableCellProperties;
tableCellProperties.Shading = shading;
}