-
Notifications
You must be signed in to change notification settings - Fork 37
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
AttributeError: 'DocumentPart' object has no attribute '_numbering_part' #68
Comments
campanya
pushed a commit
to campanya/docxcompose
that referenced
this issue
Aug 24, 2021
Could you upload the .docx files ? Thank you |
This is a file that triggers the same error message. |
This is an issue with 'python-docx'. You can temporarily fix it using the following methods, and I have already submitted a PR in 'docxcompose' to fix this issue. from docxcompose.composer import Composer
from docxcompose.utils import xpath
from docxcompose.utils import NS
from copy import deepcopy
import glob
from docx import Document
def add_numberings(self, doc, element):
"""Add numberings from the given document used in the given element."""
# Search for numbering references
num_ids = set([n.val for n in xpath(element, './/w:numId')])
if not num_ids:
return
next_num_id, next_anum_id = self._next_numbering_ids()
try:
src_numbering_part = doc.part.numbering_part
except NotImplementedError:
src_numbering_part = self.numbering_part()
for num_id in num_ids:
if num_id in self.num_id_mapping:
continue
# Find the referenced <w:num> element
res = src_numbering_part.element.xpath(
'.//w:num[@w:numId="%s"]' % num_id)
if not res:
continue
num_element = deepcopy(res[0])
num_element.numId = next_num_id
self.num_id_mapping[num_id] = next_num_id
anum_id = num_element.xpath('//w:abstractNumId')[0]
if anum_id.val not in self.anum_id_mapping:
# Find the referenced <w:abstractNum> element
res = src_numbering_part.element.xpath(
'.//w:abstractNum[@w:abstractNumId="%s"]' % anum_id.val)
if not res:
continue
anum_element = deepcopy(res[0])
self.anum_id_mapping[anum_id.val] = next_anum_id
anum_id.val = next_anum_id
# anum_element.abstractNumId = next_anum_id
anum_element.set('{%s}abstractNumId' % NS['w'], str(next_anum_id))
# Make sure we have a unique nsid so numberings restart properly
nsid = anum_element.find('.//w:nsid', NS)
if nsid is not None:
nsid.set(
'{%s}val' % NS['w'],
"{0:08X}".format(int(10 ** 8 * random.random()))
)
self._insert_abstract_num(anum_element)
else:
anum_id.val = self.anum_id_mapping[anum_id.val]
self._insert_num(num_element)
# Fix references
for num_id_ref in xpath(element, './/w:numId'):
num_id_ref.val = self.num_id_mapping.get(
num_id_ref.val, num_id_ref.val)
Composer.add_numberings = add_numberings
lstFile = list(glob.glob('r:/*.docx'))
master = Document(lstFile[0])
composer = Composer(master)
for fnDoc in lstFile[1:]:
doc1 = Document(fnDoc)
composer.append(doc1)
composer.save("r:/combined.docx") |
That's great. I may need this next month. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
the simple code
can't run as expected, instead, it says
The text was updated successfully, but these errors were encountered: