本文演示如何使用C#和VB.NET中的Spire.Presentation在PowerPoint文档中设置现有表的行高和列宽。
以下屏幕截图显示了设置行高和列宽之前的表。
详细步骤:
Step 1: 实例化Presentation对象并加载PowerPoint文档。
Presentation ppt = new Presentation(); ppt.LoadFromFile("Input.pptx");
Step 2: 获得第一张幻灯片。
ISlide slide = ppt.Slides[0];
Step 3:获取幻灯片上的第一张表。
ITable table = ppt.Slides[0].Shapes[0] as ITable;
Step 4:设置表行高和列宽。
table.TableRows[1].Height = 50; table.ColumnsList[1].Width = 100;
Step 5:保存文档。
ppt.SaveToFile("Output.pptx", FileFormat.Pptx2013);
截图:
完整代码:
[C#]
using Spire.Presentation; namespace Set_table_column_width_and_row_height { class Program { static void Main(string[] args) { Presentation ppt = new Presentation(); ppt.LoadFromFile("Input.pptx"); ISlide slide = ppt.Slides[0]; ITable table = ppt.Slides[0].Shapes[0] as ITable; table.TableRows[1].Height = 50; table.ColumnsList[1].Width = 100; ppt.SaveToFile("Output.pptx", FileFormat.Pptx2013); } } }End Namespace
[VB.NET]
Imports Spire.Presentation Namespace Set_table_column_width_and_row_height Class Program Private Shared Sub Main(args As String()) Dim ppt As New Presentation() ppt.LoadFromFile("Input.pptx") Dim slide As ISlide = ppt.Slides(0) Dim table As ITable = TryCast(ppt.Slides(0).Shapes(0), ITable) table.TableRows(1).Height = 50 table.ColumnsList(1).Width = 100 ppt.SaveToFile("Output.pptx", FileFormat.Pptx2013) End Sub End Class