-
Notifications
You must be signed in to change notification settings - Fork 1.2k
section.bottom_margin fails #1335
New issue
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
Comments
Hmm, interesting. That string "1133.8582677165355" is not a valid value for that XML attribute according to the XML Schema. https://github.com/python-openxml/python-docx/blob/master/ref/xsd/shared-commonSimpleTypes.xsd#L104 But I expect Word accepts it. I'll register it here as something to accommodate. In the meantime you'll need to work around it somehow. I think I'd be inclined to pro-actively patch that value in my code before trying to access the margins. You can access the |
"You can access the w:sectPr element from Section._sectPr and you XPath and lxml calls from there to find and fix any of those before calling the margin attributes." - This is a little advanced for a non programmer like me, lol I did get into your code and put the str_value variable inside a float() function, nested inside a round() function, nested inside the int() function where you were directly passing str_value as its argument. So it looks like I would however like to know how to fix my document margins float values in code without having to hack yours, haha |
Fixed in v1.1.1 circa Apr 30, 2024. |
section.bottom_margin for googledocs document
self.inner_width, self.inner_height = inner_sizes(section)
File "/Users/vhdev/PycharmProjects/word_split/help.py", line 8, in inner_sizes
print(section.bottom_margin())
File "/Users/vhdev/PycharmProjects/word_split/venv/lib/python3.9/site-packages/docx/section.py", line 42, in bottom_margin
return self._sectPr.bottom_margin
File "/Users/vhdev/PycharmProjects/word_split/venv/lib/python3.9/site-packages/docx/oxml/section.py", line 185, in bottom_margin
return pgMar.bottom
File "/Users/vhdev/PycharmProjects/word_split/venv/lib/python3.9/site-packages/docx/oxml/xmlchemy.py", line 211, in get_attr_value
return self._simple_type.from_xml(attr_str_value)
File "/Users/vhdev/PycharmProjects/word_split/venv/lib/python3.9/site-packages/docx/oxml/simpletypes.py", line 26, in from_xml
return cls.convert_from_xml(xml_value)
File "/Users/vhdev/PycharmProjects/word_split/venv/lib/python3.9/site-packages/docx/oxml/simpletypes.py", line 319, in convert_from_xml
return Twips(int(str_value))
ValueError: invalid literal for int() with base 10: '1133.8582677165355'
The text was updated successfully, but these errors were encountered: