2017-02-21 50 views
1

我使用C#動態創建一個PowerPoint,我需要創建一個包含變量行和列的表格下面的代碼創建表格。如何使用C#interop庫在PowerPoint中添加表格?

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); 
    } 

} 

現在,如何設置表格邊框的風格?

回答

0

您可以添加內部下面的代碼片段你的for循環來調整單元格邊框厚度,線型,顏色,陰影,等有很多更多的項目從距DashStyle,前景色等

選擇
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

嘗試之後,您的代碼是正確的 – doo0301

相關問題