-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Restart numbering of an ordered list in document. #25
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
+1 |
+1 :) |
Hi @scanny . I have a problem with workaround way you mentioned in stackoverflow.com. In order to restarting the list numbering, you said one need to locate the numbering definition of the style as well as the abstract numbering definition it points to. I tried but failed to locate these two definitions. Can you explain in detail how they can be located? Cuz I haven't found any documents about them. |
Can you link to the SO response? that would save me from taking the time to search it up. |
Here is the link, the same as the link you answered for issue #87 : http://stackoverflow.com/questions/23446268/python-docx-how-to-restart-list-lettering/23464442#23464442 |
@downtown12 I don't have time to develop step-by-step instructions for you, but if you're looking for the right direction to start looking for yourself, these might be helpful:
|
Thanks a lot @scanny .Your instructions help me connect the attributes you mentioned above with the elements of numbering.xml. They are pretty helpful. |
@downtown12, I also use this feature. I see that all infrastructure is already in python-docx. Enabling it is easy - Below is a patch. I also added accessors for numId, ilvl and ind.left for
|
@yurac Thanks. |
@downtown12, I also thought about adding new abstract number node per list, but was too lazy to implement it:) Thanks! |
@yurac, do you plan to submit a pull request? |
@nesnahnoj , I submitted one: #210 |
Thanks @yurac. Can you explain how you are accessing/using numId, ilvl and ind.left? I've been using the same command described in the original post of this issue: Add the list of strings
|
You have to set ilvl and numid for each item. You can set them using the accessors in the pull request. You need to understand class relationship in python-docx to do so. Generate numid using the function in pull request using the abstract numid as parameter. Get abstract numid from your template file. For your example you do not need to set ind.left. I will try to get you some example when i have time. |
@nesnahnoj |
This appears to work reasonably well for numbered lists, but not so good for multi-levels bullet lists. From my tests, it looks like you need to have a Those are used to define the list style (bullet character and indentation, mostly). When they are missing, it looks like Word picks reasonable defaults for a numbered list but not for a bullet list. @yurac, PR #110 generates random values for |
@nesnahnoj here is code that should generate the example you asked:
|
@jeberger multi-level bullet list work for me the same way. I create an abstractNumId for such a list using Word and then reference it the same way I do for numbered lists |
@yurac and the result when opened in word looks like:
instead of:
|
Note that this depends on your docx template. My results are with the |
@jeberger I do not use default.docx. I created a template and added there a numbered multi level list and a bulleted multi level list of the style I want to use. Then I opened the template file numbering.xml component and found there the cirresponding abstractNumId's for the numbered list and the bulleted list I created. Now I always use these ids together with the pull request I posted above and I get the expected results for both numbered and bulleted multi level lists |
That's more or less the point I wanted to make: this requires a specific docx template and code that is tailored to use the same IDs as this template. It will not work with a generic template, and you may have to change the IDs in the code each time you change the template. |
Yes. I think a better approach would be adding abstractNumId per list. However there is currently no API for adding new abstractNumId so you can only use ones defined in your template |
+1 |
Hi Adam, you're more than welcome to contribute. The key thing that stops most folks is getting the tests done. Python folks just don't seem to be test-driven as a whole and this project is strictly test-driven. No commit gets merged without tests. You can look at the commit history to get an idea the granularity and flow of how these feature additions go. Generally look for a commit that starts with 'docs: document analysis for ...' followed by one starting 'acpt: add scenarios for xxx'. Then the implementation follows and then the pattern repeats. The first step is developing the enhancement proposal, also known as the "analysis page". This is where the API is resolved and so it's a natural first step. It's also separately committable, whether you go on to develop the feature or not. After that, you can pick and choose whatever you want from the existing pull requests to use in yours. Neither one of the two PRs look like they went in the right direction, which is typically what happens when you don't start with the analysis document. There's a lot to think through and inputs to be collected and understood, like the relevant XML Schema excerpts, Word's own behaviors with respect to lists, what the spec has to say about it (little generally :), and what the MS API is for doing the same from VBA. Let me know if you need more to go on :) |
Any updates on this issue or we can contrib? |
Are there any updates to this? |
how to read bullets or numbering in an existing document |
So I've made a thing that searches the existing abstract numbering schemes for the style of the current paragraph, and sets a reasonable abstract style based on that if possible:
This is in no way comprehensive or particularly robust, but it works pretty well for what I am trying to do. |
thanks |
In a document have one table |
All kudos to @jlovegren0. He added low-level support for numbering styles |
Yes, excellent work indeed by @jlovegren0 Nested numbering lists work with correct numbering. |
We have a good discussion on PR: #582 again approbation for @jlovegren0 for all the crafted inputs and workarounds |
Hi @downtown12, I know it has been quite a few years since you posted this but I have encountered this issue and wanted to try your solution. Would you mind elaborating on how you parsed the document_part (which property?) using lxml and located the numbering list paragraphs? Furthermoer, how did you manage to create and where/how to insert the abstract number nodes? I've iterated through the document.part._element, and its children, but that didn't seem to show anything insightful (no list number objects etc even though the document has lists). Wasn't clear if the docs for python-docx also elaborated on how to do this. |
We can easily add ordered list with
document.add_paragraph(style='ListNumber')
code. But how can we restart its numbering?The text was updated successfully, but these errors were encountered: