[英]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.