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

C# Word - Table Cell Processing in C#.NET


Online Tutorial for Users to Set and Modify Table Cells in Word Document




Overview



C#.NET Word document table cell processing Interface control (XDoc.Word).//More TODO allows users to process table cells on an existing Word file.


Related .net document control helps:
asp.net dotnetnuke pdf editor control: ASP.NET DNN PDF Editor Control: view, edit PDF files in Dotnetnuke application
asp.net mvc pdf editor control: ASP.NET MVC PDF Editor: view, annotate, redact, edit PDF document in C# ASP.NET MVC
file redact asp.net: Redact document ASP.NET: add, delete, apply redaction on PDF files in web browser using C#.net
view file asp.net: View multiple document formats in ASP.NET, MVC, Ajax, Azure using C# control
asp.net office file viewer: ASP.NET Office Word Document Viewer: view MS Office Word files online using C# in ASP.NET web applications
asp.net edit pdf image control: ASP.NET PDF Image Edit Control: online insert, edit PDF images in C#
asp.net edit pdf page control: ASP.NET PDF Pages Edit Control: add, remove, sort, replace PDF pages online using C#




C# DLLs: Word Table Cell 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 and Add Cells in Table



The following demo code will show how to create a table cell and add to table.



String docFilePath = @"";
//Open the document
DOCXDocument document = DOCXDocument.Open(docFilePath);
//Get the main document
IDocument doc = document.GetDocument();
//Create a table in body
ITable table = doc.CreateTable(3, 3);
//Create a table row for table
ITable row = table.CreateRow(3);
//Creta a table cell for table row
ITableCell cell = row.CreateCell();
//Save the document
doc.Save(@"");





Properties Setup in Table Cell



In C#.NET applications, users can set and modify property of each cell in table by using following sample code.




String docFilePath = @"";
//Open the document
DOCXDocument document = DOCXDocument.Open(docFilePath);
//Get the main document
IDocument doc = document.GetDocument();
//Create a Table for document
ITable table = doc.CreateTable(3, 3);
//Get all rows in table
List<ITableRow> rows = table.GetRows();
//Get first row
ITableRow row = rows[0];
//Get all cells in first row
List<ITableCell> cells = row.GetCells();
//Get first cell
ITableCell cell = cells[0];
//Set properties for cell
//Cell width fit text
cell.SetFitText(true);
//Text flow direction
cell.SetTextFlowDirection(TextDirection.LrTbV);
//Shadow fill Color
cell.SetShadowFillColor(false, Color.Red);
//Cell width
cell.SetCellWidth(200);
//MORE TODO:
//
//
doc.Save(@"");





Create, Add and Modify Paragraph in Table Cell



Sometimes you may need to create some text content or nest table in Word document, the following demo code will show you how to create a text paragraph in table cell.




String docFilePath = @"";
//Open the document
DOCXDocument document = DOCXDocument.Open(docFilePath);
//Get the main document
IDocument doc = document.GetDocument();
//Create a Table for document
ITable table = doc.CreateTable(3, 3);
//Get all rows in table
List<ITableRow> rows = table.GetRows();
//Get first row
ITableRow row = rows[0];
//Get all cells in first row
List<ITableCell> cells = row.GetCells();
//Get first cell
ITableCell cell = cells[0];
//Create text content for cell
IParagraph paragraph = cell.CreateParagraph();
IRun run = paragraph.CreateARun();
run.CreateText("This is the first cell in table");
doc.Save(@"");




Create, Add and Modify Nest Table in Table Cell



The following demo code shows how to create nest tables in a cell.




String docFilePath = @"";
//Open the document
DOCXDocument document = DOCXDocument.Open(docFilePath);
//Get the main document
IDocument doc = document.GetDocument();
//Create a Table for document
ITable table = doc.CreateTable(3, 3);
//Get all rows in table
List<ITableRow> rows = table.GetRows();
//Get first row
ITableRow row = rows[0];
//Get all cells in first row
List<ITableCell> cells = row.GetCells();
//Get first cell
ITableCell cell = cells[0];
//Create a nest table with 2 columns and 2 rows for cell
ITable nestTable = cell.CreateTable(2, 2);

doc.Save(@"");