C# 设置PowerPoint表格的默认字体
我可以创建包含许多单元格的PowerPoint表格,但默认字体(28点)太大。如果无法访问用户的PowerPoint模板,如何为我创建的表格设置字体?目前我所能做的就是:C# 设置PowerPoint表格的默认字体,c#,powerpoint,office-interop,C#,Powerpoint,Office Interop,我可以创建包含许多单元格的PowerPoint表格,但默认字体(28点)太大。如果无法访问用户的PowerPoint模板,如何为我创建的表格设置字体?目前我所能做的就是: 创建表 用单个空格填充每个单元格,否则将忽略字体更改 (尽管它使用PowerPoint用户界面工作) 创建包含所有单元格的区域并设置字体: List<string> names = new List<string>(); foreach (PowerPoint.Column column in tabl
List<string> names = new List<string>();
foreach (PowerPoint.Column column in table.Columns)
foreach (PowerPoint.Cell cell in column.Cells) {
cell.Shape.TextFrame.TextRange.Text = "";
names.Add(cell.Shape.Name);
}
PowerPoint.ShapeRange range = ppt.ActivePresentation.Slides.Item(1).Shapes.Range(names.ToArray());
range.TextFrame.TextRange.Font.Size = 12;
列表名称=新列表();
foreach(PowerPoint.Column列在table.Columns中)
foreach(PowerPoint.Cell在column.Cells中的单元格){
cell.Shape.TextFrame.TextRange.Text=”“;
Name.Add(cell.Shape.Name);
}
PowerPoint.shaperage range=ppt.ActivePresentation.Slides.Item(1).Shapes.range(names.ToArray());
range.TextFrame.TextRange.Font.Size=12;
我正在使用C#通过其COM API控制PowerPoint 2003..2010。我的实验是使用PowerPoint 2003。在PPT 2010中,这项工作不需要在单元格中输入文本(vba,但应该很容易翻译)。出于演示目的,我正在使用当前选定的表;将本表的任何其他参考替换为oTbl:
Dim oTbl As Table
Dim lCol As Long
Dim lRow As Long
Set oTbl = ActiveWindow.Selection.ShapeRange(1).Table
With oTbl
For lCol = 1 To .Columns.Count
For lRow = 1 To .Rows.Count
.Cell(lRow, lCol).Shape.TextFrame.TextRange.Font.Size = 28
Next
Next
End With
如您所见,在PPT2003中,您需要向单元格中添加文本,以便“采用”格式(不幸的是,这会严重减慢速度)
由于PPT自动化中还有其他实例,您可能需要临时填充文本,然后将其删除,因此您可能需要编写一个更通用的例程,以便将形状传递给它
With Shape.TextFrame.TextRange
If Len(.Text) = 0 Then
.Text = "!@#$%" ' or some other lunatic string not likely to be found in nature
End If
End With
使用此选项“预处理”形状,执行任何必要的操作,然后使用配套例程“取消处理”,该例程测试文本=“!@#$%”是否返回到“”,如果是,则不进行处理。感谢有关不同版本的说明。我已开始在单独的线程中在PowerPoint 2003上执行操作,而且速度要快得多。希望它能持续到2007年+。我把这件事再公开一点,希望其他人知道一个狡猾的把戏。[公开]好计划。我也很乐意看到更好的主意。