How to Add tables to word processing documents

How to Add tables to word processing documents

2016-01-13 07:49:05 Written by  Koohji
Rate this item
(0 votes)

class Program
    {
        static void Main(string[] args)
        {
            string fileName = "Word10.docx";
            CreateTable(fileName);
        }
        // Insert a table into a word processing document.
        public static void CreateTable(string fileName)
        {
            using (WordprocessingDocument doc = WordprocessingDocument.Create(fileName, WordprocessingDocumentType.Document))
            {
                MainDocumentPart mainPart = doc.AddMainDocumentPart();
                mainPart.Document = new Document();
                Body body = mainPart.Document.AppendChild(new Body());
                Table tb = new Table();
                TableRow row = new TableRow();
                TableCell cel = new TableCell(new Paragraph(new Run(new Text("OpenXML"))));
                row.AppendChild(cel);
                tb.AppendChild(row);
                body.Append(tb);
            }
        }

Additional Info

  • tutorial_title: Add tables to word processing documents
Last modified on Wednesday, 13 January 2016 07:50