We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
<w:commentRangeStart w:id="0"/> <w:r>...</w:r> <w:commentRangeEnd w:id="0"/>
how to get <w:r>...</w:r> above
The text was updated successfully, but these errors were encountered:
Maybe you can use lxml.etree to have a try, like below:
lxml.etree
from lxml import etree import zipfile ooXMLns = {'w': 'http://schemas.openxmlformats.org/wordprocessingml/2006/main'} docxFilePath = "Your Docx File Path." docxZip = zipfile.ZipFile(docxFilePath) documentXML = docxZip.read('word/document.xml') et = etree.XML(documentXML) commentRangeStarts = et.xpath('//w:commentRangeStart', namespaces=ooXMLns) elem = commentRangeStarts[0].getnext()
getnext() will help you to get the element of <w:r>...</w:r>.
getnext()
Sorry, something went wrong.
For anyone coming to this from Google (like me), this worked for me:
def get_document_comments(docxFileName): comments_dict = {} comments_of_dict = {} docx_zip = zipfile.ZipFile(docxFileName) comments_xml = docx_zip.read('word/comments.xml') comments_of_xml = docx_zip.read('word/document.xml') et_comments = etree.XML(comments_xml) et_comments_of = etree.XML(comments_of_xml) comments = et_comments.xpath('//w:comment', namespaces=ooXMLns) comments_of = et_comments_of.xpath('//w:commentRangeStart', namespaces=ooXMLns) for c in comments: comment = c.xpath('string(.)', namespaces=ooXMLns) comment_id = c.xpath('@w:id', namespaces=ooXMLns)[0] comments_dict[comment_id] = comment for c in comments_of: comments_of_id = c.xpath('@w:id', namespaces=ooXMLns)[0] parts = et_comments_of.xpath( "//w:r[preceding-sibling::w:commentRangeStart[@w:id=" + comments_of_id + "] and following-sibling::w:commentRangeEnd[@w:id=" + comments_of_id + "]]", namespaces=ooXMLns) comment_of = '' for part in parts: comment_of += part.xpath('string(.)', namespaces=ooXMLns) comments_of_dict[comments_of_id] = comment_of return comments_dict, comments_of_dict
Courtesy: https://stackoverflow.com/a/75169632/3016570
No branches or pull requests
Uh oh!
There was an error while loading. Please reload this page.
<w:commentRangeStart w:id="0"/>
<w:r>...</w:r>
<w:commentRangeEnd w:id="0"/>
how to get <w:r>...</w:r> above
The text was updated successfully, but these errors were encountered: