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