【发布时间】:2019-12-19 16:43:26
【问题描述】:
我正在尝试为 PowerPoint 幻灯片中的段落设置字体大小。在我的代码中,当我打印出字体大小时,它显示为 9,但是当我打开 PowerPoint 时,它设置为 12。
注意事项:
我在我的电脑上没有管理员权限,因此我无法安装工具来帮助对某些东西进行逆向工程,正如我在几篇文章中所读到的那样。
_bulletParagraphOuterXML是我在寻找如何通过代码设置子弹数小时后从预制段落中抓取的字符串。仍然不知道如何,学习如何是未来的另一篇文章。即使它在此字符串中显示 Arial,项目符号点文本也是 Times New Roman。在代码中它打印的字体大小为 9,但在 PowerPoint 中显示的字体大小为 12。
下面是我从用于修改和更新我的 PowerPoint 文档的类中提取的代码。
using System;
using System.Collections.Generic;
using System.Linq;
using DocumentFormat.OpenXml.Packaging;
using D = DocumentFormat.OpenXml.Drawing;
using P = DocumentFormat.OpenXml.Presentation;
static string _bulletParagraphOuterXML = "<a:pPr marL=\"285750\" indent=\"-285750\" xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\"><a:buFont typeface=\"Arial\" panose=\"020B0604020202020204\" pitchFamily=\"34\" charset=\"0\" /><a:buChar char=\"•\" /></a:pPr>";
public static void ReplaceShapeBulletsText(this SlidePart slidePart, string ShapeName, List<string> newTexts)
{
P.Shape shape = slidePart.GetShapeByName(ShapeName);
D.Paragraph paragraph = shape.TextBody.Elements<D.Paragraph>().FirstOrDefault();
shape.TextBody.RemoveAllChildren<D.Paragraph>();
foreach (string text in newTexts)
{
shape.AddBulletParagraph(text);
}
}
public static void AddBulletParagraph(this P.Shape shape, string NewText)
{
D.Paragraph p = new D.Paragraph();
P.TextBody docBody = shape.TextBody;
p.ParagraphProperties = new D.ParagraphProperties(_bulletParagraphOuterXML);
D.Run run = new D.Run(new D.Text(NewText));
D.RunProperties runProp = new D.RunProperties() { Language = "en-US", FontSize = 9, Dirty = false };
run.AppendChild(runProp);
Console.WriteLine("--------------------------------------------------------------");
Console.WriteLine(runProp.FontSize.ToString());
Console.WriteLine("--------------------------------------------------------------");
p.Append(run);
docBody.Append(p);
}
【问题讨论】:
-
如果您破解打开生成文件的 XML,您会看到什么?如果运行属性如下所示:
,则幻灯片母版和布局正在控制文本大小。如果运行属性如下所示: ,您已正确设置大小,但可能需要重置幻灯片(Home>重置)以更新其外观。
标签: c# powerpoint openxml