Good morning!
Having some trouble trying to figure out how to do this. My scenario is - I am taking in a word document. Within that worddocument is a placeholder keyword. I want to replace this keyword with a bulleted list. I've gotten close, but not quite. It puts everything in on its own line - but each line doesn't have a bullet. For example:
- LINE 1
LINE 2
LINE 3
LINE 4
versus the desired output
- LINE 1
- LINE 2
- LINE 3
- LINE 4
I've been trying to follow examples. But most seem to be creating things and appending them, so I'm wondering what I might be doing wrong. Any suggestions would be greatly appreaciated! :)
TextSelection[] selections = sourceDocument.FondAll(placeholderKey, false, false);
foreach (TextSelection selection in selections)
{
IWParagraph paragraph = selection.GetAsOneRange().OwnerParagraph;
...
paragraph.ListFormat.ApplyDefBulletStyle();
foreach (string item in valueList)
{
paragrapgh.ListFOrmat.ApplyDefBulletStyle();
paragraph.AppendText(item);
paragraph.ListFormat.ContinueListNumbering();
}
sourceDocument.Replace(placeholderKey, ....)
}
Hi Sydney,
From the given code snippet, we found that a line break
is appended to add multiple values to multiple lines, which will not be
considered as multiple paragraphs. However, according to the Microsoft Word
application, list formats are applied to paragraphs and not multiple lines.
Thus, the bullet list is applied to the first line, and the remaining lines do
not have the bullet list. To apply the list format to multiple values, you need
to append each value to different paragraphs and apply the list format to all
the paragraphs. This is not an issue but a behavior in the Microsoft Word
application. DocIO also behaves the same way.
To fulfill this requirement, we have prepared a sample that follows the
steps below:
1. Open Word document.
2. Use the Find API to find the text in the Word
document.
3. Clone the owner paragraph of the finding text.
4. Then, the text in the cloned paragraph was
replaced with values from the list.
5. Apply the bulleted list to the paragraph and
add each paragraph to the TextBodyPart.
6. Replace text with the TextBodyPart in the Word
document.
7. Save the Word document.
You can find the sample in the below.
Find-text-and-replace-with-multiple-list-paragraphs
Regards,
Anto Nihil S
Exactly what I'm looking for and appreciate you showing how that works. :) Had a system where it was about 5 times more code to even get close. Appreciated! <3