C#: Online Guide
How To: Word SDK
Paragraph Processing
Paragraph Processing
  |  
Home ›› XDoc.Word ›› C# Word: Process Paragraph

C# Word - Paragraph Processing in C#.NET


Provide Various Methods to Setup and Modify Paragraphs in Word Document for C# Users




Overview



C#.NET Word document paragraph processing Interface control (XDoc.Word).//More TODO is a tool which enable users to process paragraph on a new document by using our API.


Related .net document control helps:
document annotation asp.net: ASP.NET Document Annotation Control: text comment, drawing on files online using ASP.NET component
asp.net open pdf password: ASP.NET PDF Password Edit Control: online add, remove, update PDF file open password using C#
asp.net azure pdf editor: ASP.NET Azure PDF Editor Control: view, edit, annotate, redact PDF files online
asp.net sharepoint pdf editor: ASP.NET SharePoint PDF Editor Control: view, edit, annotate, redact PDF document in SharePoint sites
asp.net document viewer: ASP.NET Document Viewer Control in C#: View, Annotate, Redact web document files in ASP.NET using C#
asp.net image viewer: ASP.NET Image Document Viewer Control: view, annotate, redact, convert image files in html web browser
asp.net webforms document viewer: ASP.NET WebForms application document viewer control: view, annotate, redact, convert files online in ASP.NET




C# DLLs: Word Paragraph Processing



Add references:


  RasterEdge.Imaging.Basic.dll


  RasterEdge.XDoc.Office.Inner.Common.dll


  RasterEdge.Imaging.Drawing.dll


  RasterEdge.Imaging.Processing.dll


  RasterEdge.XDoc.Office.Inner.Office03.dll


  RasterEdge.Imaging.Font.dll


  RasterEdge.XDoc.Word.dll


  RasterEdge.XImage.Raster.Core.dll


  RasterEdge.XImage.Raster.dll


Use corresponding namespaces;


  using RasterEdge.Imaging.Basic;


  using RasterEdge.XDoc.Word;




Create Paragraph in Word



The following demo code will show you how to create an empty paragraph in body only. You can create paragraphs in other story in the same way.




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();
//Save the document
doc.Save(@"");





Set Paragraph Properties in Word



In C# class programming, you can use specific APIs to process paragraph in Word document. C# users can set paragraph properties and create content such as run, footnote, endnote and picture in a paragraph. The following demo code shows you how to set paragraph properties.




String docFilePath = @"";
//Open the document
DOCXDocument document = DOCXDocument.Open(docFilePath);
//Get the main ducument
IDocument doc = document.GetDocument();
//Document clone
IDocument doc0 = doc.Clone();
//Create a paragraph for document
IParagraph para = doc0.CreateParagraph();
//Create a run for para
IRun run = paragraph.CreateARun();
//Create text for run
run.CreateText("ABCDEFG");
//Paragraph properties.
//Create borders for para
para.CreateBorders();
//Indent setup
para.SetLeftIndent(500);
//Spacing setup
para.SetBoforeSpacing(300);
para.SetLineSpacing(200);
//Shadow
para.SetShadowFillColor(false, Color.Blue);
//Alignment
para.SetParagraphAlignment(ParagraphAlign.Center);
//MORE TODO:
//
//
//Save the document
doc0.Save(@"");





Create Footnote & Endnote  in Paragraph



If you need to create a footnote or endnote in a paragraph, you may use this sample code.




String docFilePath = @"";
//Open the document
DOCXDocument document = DOCXDocument.Open(docFilePath);
//Get the main ducument
IDocument doc = document.GetDocument();
//Document clone
IDocument doc0 = doc.Clone();
//Create a paragraph for document
IParagraph para = doc0.CreateParagraph();
//Create a run for para
IRun run = paragraph.CreateARun();
//Create text in run
run.CreateText("Run for footnote and endnote!");
//Create a footnote for paragraph
IFootNote footnote = para.CreateFootNote();
//Create a paragraph for footnote
IParagraph ftnPara = footnote.CreateParagraph(0);
//Create a Run and text for footnote content
IRun ftnRun = ftnPara.CreateARun();
ftnRun.CreateText("Footnote created!");

//Create a endnote for paragraph
IEndtNote endnote = para.CreateEndNote();
//Create a paragraph for endnote
IParagraph endnPara = endnote.CreateParagraph(0);
//Create a Run and text for endnote content
IRun endnRun = endnPara.CreateARun();
endnRun.CreateText("Endnote created!");

//Save the document
doc0.Save(@"");





Create Picture in Paragraph



If you want to insert picture in a paragraph, you can use demo code below.




String docFilePath = @"";
String imageSrcPath = @"";
//Open the document
DOCXDocument document = DOCXDocument.Open(docFilePath);
//Get the main ducument
IDocument doc = document.GetDocument();
//Document clone
IDocument doc0 = doc.Clone();
//Create a paragraph for document
IParagraph para = doc0.CreateParagraph();
//Create a picture for para
IPicture picture = para.CreatePicture(imageSrcPath);
//Save the document
doc0.Save(@"");





Run Processing in Paragraph



We know a paragraph is made up of runs, if you want to modify paragraph content, you can modify run firstly. The following demo code provide a method to create run in paragraph.




String docFilePath = @"";
String imageSourcePath = @"";

//Open the document on local disk by given path.
DOCXDocument document = DOCXDocument.Open(docFilePath);

//Get the main document for edit
IDocument doc = document.GetDocument();

//Create a paragraph for document.
IParagraph paragraph = doc.CreateParagraph();

//Create a run for paragraph, now no content in run before edit.
IRun run = paragraph.CreateARun();
//Edit run
run.CreateText("Text created in run");

//Save the document after edit
doc.Save(@"");