2017-06-14 11 views
1

OpenXml経由でPowerPointの表の上端を変更しようとしていますが、それは私のためには機能しませんでした。セルには現在、左、右、下の境界線がありますが、下の境界線をコピーして上の境界線に追加しようとすると、PowerPointに変更が反映されません。PowerPointでopenxmlを使用してセルに枠線を追加するにはどうすればよいですか?

私は変更する必要がありますか、それを機能させるには間違っていますか?

現在、下の罫線をコピーして置き換えるには、次のコードがあります。

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:私の英語

答えて

0

のため申し訳ありませんが、PowerPointのテーブルの真ん中にセルの上罫線を設定するためには、あなたは2つのステップを完了する必要があります。

ステップ1:下の境界を設定します直接当該セルと上記セルの

ステップ2:当該セルの上罫線を設定

私はOpenXMLの生産性向上ツールを使用してこれを決定(あなたはその部分を持っています)。私は Before.pptxという名前のシンプルな1スライドのPowerPointファイルを、左、下、右の枠線を持つ表のセルで取り出しました。

enter image description here

それから私は(パワーポイント2016を使用して)上の境界を追加し、After.pptxとしてファイルを保存しました。その後、生産性向上ツールを使用して2つのファイルを比較し、Before.pptxAfter.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ファイルに対して上記のコードを実行し、境界線が完了しました。二つのステップが必要であることを再確認する目的で

enter image description here

、私はステップ1のコードをコメントアウトしてBefore.pptxファイルの新鮮なバージョンに対してそれを実行し、上部の境界線が欠落していました。これはあなたが見ていた問題を確認します。したがって、1つの境界をペイントするには2つのステップが必要です。

関連する問題