buks
buks

Reputation: 435

how to add new TextRange.Run to PowerPoint textbox?

I would like to copy some text with its formatting. If whole text is formatted in one way then it is very easy to do, but I can not manage with copying text which is formatted in different ways (for example some part of text is bold some not).

There is something like Run, and I know how to read it (and how to add it using open xml, but the add-in has to work on opened presentation), but how can I add it/insert into some textbox? I can not find any method like Shape.TextFrame2.TextRange.Runs.Add() or Shape.TextFrame2.TextRange.Runs(1).Insert()

Upvotes: 4

Views: 894

Answers (2)

Chandraprakash
Chandraprakash

Reputation: 946

How to assign value to,

Shape1.TextFrame.TextRange.Runs(1).Font.Bold = MsoTriState.msoTrue;

But the above code doesn't make the 1st block of text in run to true, no bold is applied.

Upvotes: 0

buks
buks

Reputation: 435

OK, I've found how to do it:

for (int k = 0; k < sourceShapeProps.textFrame.TextRange.Runs.Count; k++)
   {
    var run = sourceShapeProps.textFrame.TextRange.get_Runs(k + 1, 1);
    var characters = cell.Shape.TextFrame2.TextRange.get_Characters(run.Start, run.Length);
    characters.Font.Fill.ForeColor.RGB = run.Font.Fill.ForeColor.RGB;
    characters.Font.Bold = run.Font.Bold;
    characters.Font.Italic = run.Font.Italic;
   }

Upvotes: 2

Related Questions