2017-02-21 3 views
1

Ich erstelle dynamisch eine PowerPoint mit C# und ich muss eine Tabelle mit variablen Zeilen und Spalten erstellen Der folgende Code erstellt die Tabelle.Wie fügt man eine Tabelle in PowerPoint mit C# Interop-Bibliothek hinzu?

objShape = MySlide.Shapes.AddTable(10, 5, ConvertCmtoPx(4), ConvertCmtoPx(2.5), ConvertCmtoPx(15), ConvertCmtoPx(10)); 
table = objShape.Table; 

for (int i = 1; i <= table.Rows.Count; i++) 
{ 
    for (int j = 1; j <= table.Columns.Count; j++) 
    { 
    table.Cell(i, j).Shape.Fill.Solid.SolidFill.BackColor.RGB = 0xffffff; 
    table.Cell(i, j).Shape.TextFrame.TextRange.Font.Size = 12; 
    // table.Cell(i, j).Shape.Line.Style.BackColor.RGB = 0xFF3300; 
    table.Cell(i, j).Shape.TextFrame.TextRange.ParagraphFormat.Alignment = PowerPoint.PpParagraphAlignment.ppAlignCenter; 
    table.Cell(i, j).Shape.TextFrame.VerticalAnchor = MsoVerticalAnchor.msoAnchorMiddle; 
    table.Cell(i, j).Shape.TextFrame.TextRange.Text = string.Format("[{0},{1}]", i, j); 
    } 

} 

Nun, wie die Tabelle Grenze Stil setzen?

Antwort

0

Sie können den folgenden Code-Schnipsel in Ihrem hinzufügen for-Schleife die Zellenrandstärke, Linientyp zu optimieren, Farbe, Schattierung, etc. Es gibt viel mehr Elemente aus abgesehen von DashStyle, ForeColor usw.

wählen
table.Cell(i, j).Borders[Microsoft.Office.Interop.PowerPoint.PpBorderType.ppBorderLeft].DashStyle = MsoLineDashStyle.msoLineLongDashDot; 
table.Cell(i, j).Borders[Microsoft.Office.Interop.PowerPoint.PpBorderType.ppBorderLeft].ForeColor.RGB = 0xff00ff; 
table.Cell(i, j).Borders[Microsoft.Office.Interop.PowerPoint.PpBorderType.ppBorderLeft].Weight = 1.0f; 
+0

Nach dem Versuch, ist Ihr Code richtig – doo0301

Verwandte Themen