[英]How to add border to cell with openxml in PowerPoint?
我试图通过OpenXml在PowerPoint中更改表的顶部边框,但它对我没用。 单元格当前具有左,右和底部边框,但是当我尝试复制底部边框并将其添加到顶部边框时,PowerPoint不会反映更改。
我需要改变什么,或者我做错了让它发挥作用?
我目前有以下代码来复制底部边框并替换它。
BottomBorderLineProperties btp = (BottomBorderLineProperties)celda.TableCellProperties.BottomBorderLineProperties.CloneNode(true);
TopBorderLineProperties tbp = new TopBorderLineProperties()
{
Alignment = btp.Alignment,
CapType = btp.CapType,
CompoundLineType = btp.CompoundLineType,
MCAttributes = btp.MCAttributes,
Width = btp.Width
};
foreach(OpenXmlElement element in btp.ChildElements)
{
tbp.Append(element.CloneNode(true));
}
celda.TableCellProperties.TopBorderLineProperties = tbp;
谢谢!
PS:对不起我的英文
要在PowerPoint表的中间设置单元格的顶部边框,您必须完成两个步骤:
步骤1:将单元格的底部边框设置在相关单元格的正上方
第2步:设置相关单元格的顶部边框(您有该部分)
我通过使用OpenXML Productivity Tool确定了这一点。 我拿了一个简单的1幻灯片PowerPoint文件,名为Before.pptx
,表格单元格有左,右,右边Before.pptx
。
然后我添加了顶部边框(使用PowerPoint 2016)并将文件保存为After.pptx
。 然后我使用Productivity Tool来Before.pptx
2个文件,并反向设计使Before.pptx
看起来像After.pptx
所需的C#代码。 您需要的重要代码显示在此处:
//STEP 1 CODE STARTS HERE
A.Table table1=graphicData1.GetFirstChild<A.Table>();
A.TableRow tableRow1=table1.GetFirstChild<A.TableRow>();
A.TableRow tableRow2=table1.Elements<A.TableRow>().ElementAt(1);
A.TableCell tableCell1=tableRow1.Elements<A.TableCell>().ElementAt(2);
A.TableCellProperties tableCellProperties1=tableCell1.GetFirstChild<A.TableCellProperties>();
A.BottomBorderLineProperties bottomBorderLineProperties1 = new A.BottomBorderLineProperties(){ Width = 12700, CapType = A.LineCapValues.Flat, CompoundLineType = A.CompoundLineValues.Single, Alignment = A.PenAlignmentValues.Center };
A.SolidFill solidFill1 = new A.SolidFill();
A.SchemeColor schemeColor1 = new A.SchemeColor(){ Val = A.SchemeColorValues.Text1 };
solidFill1.Append(schemeColor1);
A.PresetDash presetDash1 = new A.PresetDash(){ Val = A.PresetLineDashValues.Solid };
A.Round round1 = new A.Round();
A.HeadEnd headEnd1 = new A.HeadEnd(){ Type = A.LineEndValues.None, Width = A.LineEndWidthValues.Medium, Length = A.LineEndLengthValues.Medium };
A.TailEnd tailEnd1 = new A.TailEnd(){ Type = A.LineEndValues.None, Width = A.LineEndWidthValues.Medium, Length = A.LineEndLengthValues.Medium };
bottomBorderLineProperties1.Append(solidFill1);
bottomBorderLineProperties1.Append(presetDash1);
bottomBorderLineProperties1.Append(round1);
bottomBorderLineProperties1.Append(headEnd1);
bottomBorderLineProperties1.Append(tailEnd1);
tableCellProperties1.Append(bottomBorderLineProperties1);
//STEP 1 CODE ENDS HERE
//STEP 2 CODE STARTS HERE
A.TableCell tableCell2=tableRow2.Elements<A.TableCell>().ElementAt(2);
A.TableCellProperties tableCellProperties2=tableCell2.GetFirstChild<A.TableCellProperties>();
A.BottomBorderLineProperties bottomBorderLineProperties2=tableCellProperties2.GetFirstChild<A.BottomBorderLineProperties>();
A.TopBorderLineProperties topBorderLineProperties1 = new A.TopBorderLineProperties(){ Width = 12700, CapType = A.LineCapValues.Flat, CompoundLineType = A.CompoundLineValues.Single, Alignment = A.PenAlignmentValues.Center };
A.SolidFill solidFill2 = new A.SolidFill();
A.SchemeColor schemeColor2 = new A.SchemeColor(){ Val = A.SchemeColorValues.Text1 };
solidFill2.Append(schemeColor2);
A.PresetDash presetDash2 = new A.PresetDash(){ Val = A.PresetLineDashValues.Solid };
A.Round round2 = new A.Round();
A.HeadEnd headEnd2 = new A.HeadEnd(){ Type = A.LineEndValues.None, Width = A.LineEndWidthValues.Medium, Length = A.LineEndLengthValues.Medium };
A.TailEnd tailEnd2 = new A.TailEnd(){ Type = A.LineEndValues.None, Width = A.LineEndWidthValues.Medium, Length = A.LineEndLengthValues.Medium };
topBorderLineProperties1.Append(solidFill2);
topBorderLineProperties1.Append(presetDash2);
topBorderLineProperties1.Append(round2);
topBorderLineProperties1.Append(headEnd2);
topBorderLineProperties1.Append(tailEnd2);
tableCellProperties2.InsertBefore(topBorderLineProperties1,bottomBorderLineProperties2);
我在上面的代码上运行了我的Before.pptx
文件,边框已经完成。
为了仔细检查这两个步骤是否必要,我注释掉了Step 1代码,并在新版本的Before.pptx
文件中运行它,并且缺少顶部边框。 这可以验证您遇到的问题。 因此,绘制一个边框需要两个步骤。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.