table finding from doc file using openxml

411 views Asked by At

I want to edit the values in rows of table in doc file using openxml package in c sharp code. Here I am showing the code for finding table but it gives me null and if i use default instead of firstordefault then its gives me exception like sequence contains no elements.

DocumentFormat.OpenXml.Wordprocessing.Table table=doc.MainDocumentPart.Document.Body.Elements<DocumentFormat.OpenXml.Wordprocessing.Table>().FirstOrDefault();

Thanks.

1

There are 1 answers

0
Tarveen On

You can use this: Table table = doc.MainDocumentPart.Document.Descendants().FirstOrDefault();