I'm creating slides for a PowerPoint Presentation using C#. I've so far managed to create tables for a slide using Shape.AddTable method, and the table is created with a default style. I want to be able to change color and line weight for each cell, but I can't seem to find the method to add borders to the cells.
I've tried using learn.microsoft for help, but no luck: https://learn.microsoft.com/en-us/previous-versions/office/office-12/ff760048(v=office.12)
My code:
int n_rows = 28;
int n_cols = 8;
int row_height = 12;
int font_size = 6;
int top_margin = 1;
int left_margin = 3;
PowerPoint.Shape tb = slide.Shapes.AddTable(n_rows, n_cols, 40, 150, 870, 200);
for (int i = 1; i < n_cols + 1; i++)
{
for(int j=1;j< n_rows + 1;j++)
{
tb.Table.Cell(j, i).Shape.TextFrame.TextRange.Font.Size = font_size;
tb.Table.Cell(j, i).Shape.TextFrame.TextRange.Font.Bold = Office.MsoTriState.msoFalse;
tb.Table.Cell(j, i).Shape.TextFrame.TextRange.Text = "test";
tb.Table.Cell(j, i).Shape.TextFrame.MarginBottom = 0;
tb.Table.Cell(j, i).Shape.TextFrame.MarginTop = top_margin;
tb.Table.Cell(j, i).Shape.TextFrame.MarginLeft = left_margin;
tb.Table.Cell(j, i).Shape.TextFrame.MarginRight = 0;
tb.Table.Cell(j, i).Shape.Fill.ForeColor.RGB = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.White);
}
}
I found out I had to add Dashstyle and Forecolor property to the Borders like this:
tb.Table.Cell(j, i).Borders[PowerPoint.PpBorderType.ppBorderTop].DashStyle = Office.MsoLineDashStyle.msoLineSolid;
tb.Table.Cell(j, i).Borders[PowerPoint.PpBorderType.ppBorderTop].ForeColor.RGB = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Black);
tb.Table.Cell(j, i).Borders[PowerPoint.PpBorderType.ppBorderTop].Weight = 0.2f;
Now it works!