The paragraph.GetText and runs[x].Text What is the difference?

the paragraph.GetText and runs[x].Text What is the difference?Paragraph have only GetText,have not SetText, runs collection quantities are not fixed, I want change paragraph value again, what to do?

Hi Lovecomputer,

Thanks for your query.

Paragraph.GetText Method gets the text of this paragraph including the end of paragraph character.

Node.ToTxt Method Exports the content of the node into a string in plain text format. Please check the following code snippet for details.

Document doc = new Document();
// Enter a dummy field into the document.
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertField("MERGEFIELD Field");
// GetText will retrieve all field codes and special characters
Console.WriteLine("GetText() Result: " + doc.GetText());
// ToTxt will not retrieve fields code or special characters, but will still contain some natural formatting characters
// such as paragraph markers etc. This is the same as "viewing" the document as if it was opened in a text editor
// Only the results of fields are shown without any internal codes or characters
Console.WriteLine("ToTxt() Result: " + doc.ToTxt());

Run.Text* Property Gets or sets the text of the run. Please check the attached images.

// Create a new run of text and add it to our paragraph.
Run run = new Run(doc);
run.Text = "Hello World!";
run.Font.Color = System.Drawing.Color.Red;
para.AppendChild(run);
// As a matter of interest, you can retrieve text of the whole document and
// see that \x000c is automatically appended. \x000c is the end of section character.
Console.WriteLine("Hello World!\x000c", doc.GetText());

Thank you for your answer, I’m not trying to get all the document information, I want to Gets a paragraph,and adjusting the paragraph format, similar to the word inside the foreach (paragraph in paragraphs),I have this code

foreach(paragraph p in doc.paragraphs)
{
    p.ParagraphFormat.CharacterUnitLeftIndent = 0;
    p.Range.Text = p.Range.Text + "test";
}

I want use aspose.words,can you give aspose.words code?

Hi Lovecomputer,

Thanks for sharing the information. Please use the following code snippet for your requirement. Use the Run.Text Property to change the text. Please read following documentation links for your kind reference.

https://docs.aspose.com/words/net/aspose-words-document-object-model/
https://reference.aspose.com/words/net/aspose.words/paragraph/

Document doc = new Document(MyDir + "in.docx");
NodeCollection paras = doc.GetChildNodes(NodeType.Paragraph, true);
foreach(Paragraph para in paras)
{
    para.ParagraphFormat.LeftIndent = 0.0;
    foreach(Run run in para.GetChildNodes(NodeType.Run, true))
    {
        // Change the text of Run
        run.Text = run.Text + "_Changed";
    }
}
doc.Save(MyDir + "AsposeOut.docx");

Please let us know if you have any more queries.

this way:

para(NodeCollection paras = doc.GetChildNodes(NodeType.Paragraph, true);

foreach (Paragraph para in paras)) Contains the entire contents of the document, such as a header, footer, field, and I just want to get a body of content, how to do

it?Can I do with this?

foreach (Aspose.Words.Paragraph p in doca.Sections[0].Body.Paragraphs)

this way:

para(NodeCollection paras = doc.GetChildNodes(NodeType.Paragraph, true);

foreach (Paragraph para in paras)) Contains the entire contents of the document, such as a header, footer, field, and I just want to get a body of content, how to do

it?Can I do with this?

foreach (Aspose.Words.Paragraph p in doca.Sections[0].Body.Paragraphs)

I already solved. section.body.range

Hi,

Thanks for your feedback. It is nice to hear from you that you have solved your query. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.