【发布时间】:2018-04-05 05:16:38
【问题描述】:
德尔福西雅图,PPT 2013。
我正在使用 Delphi 以编程方式构建 PPT 平台。我有一个我正在使用的 PPT 模板。我提取了一个嵌入在可执行文件中的 PPT 文件作为资源,我启动 PPT,打开文件,转到幻灯片,然后填充内容。我目前正在解决的问题与字体属性有关。我有一个文本框。我想在由 CR/LF 分隔的文本框中写入各种行。 PPT显示这些是我想要的单独的项目符号。每行的第一个词是一个类别,所以我想要粗体字。它最终应该看起来像这样......
- 类别 1 - 产品 1、产品 2
- Category2 - product3、product4
在代码中,我将第一行添加到文本框,然后说...从字符 1-9 将其设置为粗体。现在将第 2 行添加到文本框,并将第 20 个字符到接下来的 9 个字符设置为粗体...等。这是一个 4 行操作。添加第一行,设置粗体,添加第二行,设置粗体。第 1 行和第 2 行有效,但是一旦我添加了第二行文本,所有内容都会变为粗体。如果我更改代码的顺序,添加第 1 行,添加第 2 行,将第一个子字符串设置为粗体,将第二个子字符串设置为粗体,这将起作用,但根据我做其他各种事情的方式,这会更加困难。
我尝试添加第 1 行,将字符 1 到 9 设为粗体,SET CHARACTER 10 NOT BOLD,现在添加第 2 行……但这似乎没有任何区别。
这是一个代码 sn-p。
uses ... Office2000, msppt2000;
var
lFinalDeck: PowerPointPresentation;
lApplication: PowerPointApplication;
sl: _Slide;
sh1 : Shape;
FoundIt : Boolean;
i : Integer;
CRLF : String;
PPTFileName : String;
begin
lApplication := CoPowerPointApplication.Create;
...
// Open File
lFinalDeck := lApplication.Presentations.Open(PPTFileName, msoFalse, msoFalse, msoFalse);
// The second parameter specifies whether the presentation should be opened in read-only mode.
// If the third parameter is True, an untitled copy of the file is made.
// The last parameter specifies whether the opened presentation should be visible.
// Get a handle to my slide and go to it.
sl := lFinalDeck.Slides.Item(2);
sl.Select;
FoundIt := False;
CRLF := #13#10;
// Now look for the textframe that has the TEXT 'TEXTBOX1'
for i := 1 to sl.Shapes.Count do
begin
sh1 := sl.Shapes.Item(i);
if sh1.HasTextFrame = msoTrue then
if sh1.TextFrame.TextRange.Text = 'TEXTBOX1' then
begin
FoundIt := True;
sh1.TextFrame.TextRange.Text := '';
Break;
end;
end;
// Put data in the textframe, setting first 5 characters of each line bold
sh1.TextFrame.TextRange.Text := '1234567890' + CRLF;
sh1.TextFrame.TextRange.Characters(1,5).Font.Bold := msoTrue;
sh1.TextFrame.TextRange.Text := sh1.TextFrame.TextRange.Text + 'ABCDEFGHIJKLMNOP' + CRLF;
sh1.TextFrame.TextRange.Characters(13,5).Font.Bold := msoTrue;
end;
任何想法如何解决这个问题?
【问题讨论】:
-
我相信这就是 Powerpoint 和办公程序的一般行为方式。当您添加一个新段落时,它会采用前一段的字体,这有时会有点麻烦,即使您是手动进行的。我可以建议这样做的唯一方法是将文本选择设置为您计划插入新参数的位置并将字体显式设置为粗体关闭,或者添加您的选择并设置粗体关闭,也许在一个单独的过程中以简化事情当你多次这样做时。
-
so I want JUST THAT WORD in bold- 既然您使用的是 Microsoft Office,那么几乎所有这些问题都有一个通用答案:只需阅读 office 是如何做到的。开始“录制 Visual Basic 宏”。然后选择单词并将其设为粗体并取消选择它。然后“停止录制宏”。然后打开宏的管理器,找到你的新宏并进入它的编辑器。您将看到执行此操作的 Visual Basic 代码。将其从 Basic 转换为 Pascal。 PS。我不知道那些与宏相关的命令在 Office 2013 中隐藏在哪里。如果找不到,请尝试经典菜单 for Office 试用 -
录制宏功能在 MOST Office 产品中,但在 Powerpoint 中没有。 Powerpoint 2007 是拥有它的最后一个版本...
标签: vba delphi com ms-office powerpoint