Free Support Forum - aspose.com

Iterating through paragraphs

After inserting some html text into my document I want to set the left indent of all paragraphs. I tried to select the entire document to set all paragraphs at the same time but couldn't find a way of doing this. Is there a way to select the entire document?

The second way I tried was to iterate through all the paragraphs using the following code but even though the paragraph count returns a value of 40 I get an error at the 'MoveTo' statement when the count reaches 1. The error is 'Specified argument was out of the range of valid values. parameter name: paraidx'.

Could you please explain what I'm doing wrong? Thanks

Dim cnt As Integer

letter.UpdateWordCount()

cnt = letter.BuiltInDocumentProperties.Paragraphs

For cnt = 0 To letter.BuiltInDocumentProperties.Paragraphs - 1

docBuilder.MoveToParagraph(cnt, 0)

docBuilder.ParagraphFormat.LeftIndent = 20

Next

letter.Save("EnquiryLetter.doc", SaveFormat.Doc, SaveType.OpenInWord, Response)

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. Please use the following code:

'Open document

Dim doc As Document = New Document("in.doc")

'Get collection of paragraphs

Dim parCollection As NodeCollection = doc.GetChildNodes(NodeType.Paragraph, True)

For Each par As Paragraph In parCollection

par.ParagraphFormat.LeftIndent = 20

'Do something

Next

Best regards.

Thanks - that has got my paragraphs lined up where I went them. I now discover though that the bulleted list formatting is not correct. Is there a way of detecting that the current paragraph you are in is a list?

If there is, I can do something different with it or leave it out of the formatting change I am applying.

While I think about it, is there a particular way that html tags are dealt with when usig the inserthtml method? If Iknew how it deals with things like

,
and other tags, I could predict how I need to deal with them.

Apart from the bulleted list example, the
and

tags seem to be handled differently.

Thanks for your help.

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry.

You can use IsListItem property to determine whether paragraph is list item.

If (par.IsListItem) Then

'Do something

End If


is line break and

is paragraph so
is rendered as Line break and

tags is rendered as paragraph.

Best regards.