Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用C#interop库在PowerPoint中添加表格?_C# - Fatal编程技术网

如何使用C#interop库在PowerPoint中添加表格?

如何使用C#interop库在PowerPoint中添加表格?,c#,C#,我正在使用C#动态创建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 (

我正在使用C#动态创建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);
  }

}
objShape=MySlide.Shapes.AddTable(10,5,ConvertCmtoPx(4),ConvertCmtoPx(2.5),ConvertCmtoPx(15),ConvertCmtoPx(10));
表=对象形状表;

对于(int i=1;i您可以在for循环中添加以下代码片段,以调整单元格边框的厚度、线型、颜色、着色等。除了DashStyle、ForeColor等之外,还有很多项目可供选择

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;