Free Support Forum - aspose.com

Loosing format when cloning paragraphs

Hi,

I'm trying to add paragraphs to a TextFrame and want to keep the original formatting. I saw in various posts, that you achieve this by cloning the first portion of the first paragraph.

I have following code:

paragraphIndex++;

m_textFrame.Paragraphs.Insert(paragraphIndex, new Paragraph(m_textFrame.Paragraphs[0]));

m_textFrame.Paragraphs[paragraphIndex].Portions.Clear();

m_textFrame.Paragraphs[paragraphIndex].Portions.Add(new Portion(m_textFrame.Paragraphs[0].Portions[0]));

m_textFrame.Paragraphs[paragraphIndex].Portions[0].Text = "blah!";

But it's not retaining the formatting (I get one paragraph nicely formatted followed by all others unformatted) accross paragraphs. It does work if I only have one paragraph and clone its portions.

Is there something wrong with the code or do you know of another way of storing formatting info?

Thanks for your help,

Dominic

Dear Dominic,

In whole your code is correct and I don’t see any mistakes.
Maybe you clear formatting of 0,0 portion in the loop after cloning first paragraph?

You shouldn’t always use Paragraphs[0].Portions[0] only.
It can be any Paragraph and Portion with formatting you like.
From the same or another TextFrame or even from another presentation.

Thanks Alexey, I keep trying (didn't get to it today unfortunately). Other question: Does Slides support joining multiple .ppt into one (e.g. I have three different powerpoints and want to 'stick' them together)?

Thanks,

Dominic

Yes, you can copy slides to another presentation.
Please check CloneSlides demo.