Office Open XML
Office Open XML is introduced by Microsoft to work with documents. For e.g.: - read/write MS word documents.
Prerequisites
- Visual Studio
- MS Word Document
- Open XML SDK
Execute below command to Install DocumentFormat.OpenXml SDK in your project
- Install-Package DocumentFormat.OpenXml Install-Package DocumentFormat.OpenXml
Note
In this example, I am using a windows form application to interact with word document and display the result on the screen.
In this example, I am using a windows form application to interact with word document and display the result on the screen.
How to find first table from word document?
- Table table = doc.MainDocumentPart.Document.Body.Elements<Table>().First();
Here .First() is extension method to find first table from word document.
The WordprocessingDocument Methods
|
EXTENSION METHOD
|
DESCRIPTION
|
|
.Elements<Table>().First()
|
To get the first table from the word document
|
|
.Elements<Table>().Last()
|
To get the last table from the word document
|
|
.Elements<Table>().FisrtOrDefault()
|
To get the first table from the word document or return the default value if the document does not contain table.
|
|
.Elements<Table>().LastOrDefault()
|
To get the Last table from word document or return the default value if the document does not contain table.
|
|
.Elements<Table>().ElementAt(Index)
|
To get the exact table from the word document by index number. Default index number is 0.
|
|
Table.Elements<TableRow>().ElementAt(index)
|
To get the exact table row from selected table by index number. Default index number is 0.
|
|
Row.Elements<TableCell>().ElementAt(Index)
|
To get the exact row cell from selected row by index number. Default index number is 0.
|
Execute the following code to read the first table from the word document,


Join the conversation! Your thoughts help the community grow.