Descendants gets zero elements in Word doc

前端 未结 2 1577
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-25 09:29

I am having trouble updating a Hyperlink in a Word doc (Q How to update the body and a hyperlink in a Word doc ) and am zooming in on the Descendants() cal

2条回答
  •  长情又很酷
    2021-01-25 10:23

    If you are sure there are elements in your file that you are searching with linq, and nothing is returning or you are getting exceptions, that typically points to a namespace problem.

    If you post your entire file, I can better help you, but check to see if you can alias your namespace like so:

    using W = DocumentFormat.OpenXml.Wordprocessing;
    

    and then in your Descendants call you do something like this:

    var hLinks = mainPart.Document.Body.Descendants();
    

    This answer demonstrates another namespace trick to try also.

提交回复
热议问题