Hello,
is it possible to open an existing document that contains tables and edit the content of the tables? (for example replace text and add rows)
Thank you for your help!
using System;
using System.Collections.Generic;
using System.Text;
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using Spire.Doc.Interface;
namespace EditTable
{
class Program
{
static void Main(string[] args)
{
Document doc = new Document(@"..\..\Table.doc");
Section section = doc.Sections[0];
ITable table = section.Tables[0];
#region replace text
TableCell cell1 = table.Rows[1].Cells[1];
Paragraph p1 = cell1.Paragraphs[0];
p1.Text = "abc";
TableCell cell2 = table.Rows[1].Cells[2];
Paragraph p2 = cell2.Paragraphs[0];
p2.Items.Clear();
p2.AppendText("def");
TableCell cell3 = table.Rows[1].Cells[3];
Paragraph p3 = cell3.Paragraphs[0];
(p3.Items[0] as TextRange).Text = "hij";
#endregion
#region add row
TableRow newRow = table.AddRow(true, true);
foreach (TableCell cell in newRow.Cells)
{
cell.AddParagraph().AppendText("new row");
}
#endregion
doc.SaveToFile("Table2.doc");
System.Diagnostics.Process.Start("Table2.doc");
}
}
}
TableRow newRow = table.AddRow(true, true);
table.Rows.Insert(4, newRow);