C# Word Library
C# Word - Run Processing in C#.NET
Provide Various Methods to Setup and Modify Run in Word Document for C# Users
With C#.NET Word document paragraph processing Interface control (XDoc.Word). Users are allowed to process run in an existing word file or a new Word document.
Create Run in Paragraph
The following demo code will show you how to create a run in current paragraph. There's no content in run until you create some in it.
String docFilePath = @"";
//Open the document
DOCXDocument document =DOCXDocument.Open(docFilePath);
//Get the main document
IDocument doc = document.GetDocument();
//Create a empty paragraph for document
IParagraph paragraph = doc.CreateParagraph();
//Create a run for paragraph
IRun run = paragraph.CreateARun();
//Save the document
doc.Save(@"");
Set Properties of Run
We provide a series of APIs to set properties of run in word document. The following demo code will show you how to operate this work.
String docFilePath = @"C:\input.docx";
//Open the document
DOCXDocument document = DOCXDocument.Open(docFilePath);
//Get the main document
IDocument doc = document.GetDocument();
//Create a paragraph for document.
IParagraph paragraph = doc.CreateParagraph();
//Create a run for paragraph.
IRun run = paragraph.CreateARun();
//Create text for run run.CreateText("Text Created");
//Set Properties for run.
//Set highlight color
run.SetHighlightColor(HighLightColor.Cyan);
//Set Italic
run.SetItalic(true);
//Set text color run.SetTextColor(Color.Blue);
//Set strike out
run.SetStrikeOut(true);
//Set underline Color
run.SetUnderlineColor(Color.Black);
//Set underline Style
run.SetUnderlineStyle(UnderlineStyle.Single); //Set Bold
run.SetBold(true);
//Set Shadow Color
run.SetShadowColor(false, Color.Brown);
//Text border
run.CreateBorder();
doc.Save(@"C:\output.docx");
Process Text Content
If you need to process text content in run, you may use following C# demo code.
String docFilePath = @"";
//Open the document
DOCXDocument document = DOCXDocument.Open(docFilePath);
//Get the main document
IDocument doc = document.GetDocument();
//Create a paragraph for document.
IParagraph paragraph = doc.CreateParagraph();
//Create a run for paragraph.
IRun run = paragraph.CreateARun();
//Create text for run
run.CreateText("ABCDEFGHI");
//Delete Char
run.DeleteChar("A");
//Append text
run.AppendText("Text Appended");
//Replace char
run.ReplaceChar('B', 'b');
//MORE TODO:
//
//
doc.Save(@"");