Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.
Mon Apr 29, 2024 6:15 pm
it is possible to read a word document and insert it into a table of another document?
-
PolloKulos
-
- Posts: 11
- Joined: Sun Mar 28, 2021 3:23 am
Tue Apr 30, 2024 2:14 am
Hi,
Thanks for your inquiry.
Our Spire.Doc supports the feature. Please check the following sample code.
- Code: Select all
//Initialize a new object of Document class and load the source document.
Document sourceDoc = new Document();
sourceDoc.LoadFromFile("1.docx");
//Initialize another object to load target document.
Document destinationDoc = new Document();
destinationDoc.LoadFromFile("2.docx");
Table table = (Table)destinationDoc.Sections[0].Tables[0];
TableCell tableCell = table.Rows[0].Cells[0];
//Copy content from source file and insert them to the target file.
foreach (Spire.Doc.Section sec in sourceDoc.Sections)
{
foreach (DocumentObject obj in sec.Body.ChildObjects)
{
tableCell.ChildObjects.Add(obj.Clone());
}
}
String result = "Result-CopyContentToAnotherWord.docx";
//Save to file.
destinationDoc.SaveToFile(result, Spire.Doc.FileFormat.Docx2013);
destinationDoc.Close();
destinationDoc.Dispose();
sourceDoc.Close();
sourceDoc.Dispose();
Please feel free to contact us if you have any questions.
Sincerely,
Amy
E-iceblue support team
-
amy.zhao
-
- Posts: 2772
- Joined: Wed Jun 27, 2012 8:50 am
Mon Jul 01, 2024 8:58 am
Hello,
Hope you are doing well.
Has your issue been solved? Could you please give us some feedback?
Sincerely,
Amy
E-iceblue support team
-
amy.zhao
-
- Posts: 2772
- Joined: Wed Jun 27, 2012 8:50 am