-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Upgrade python-docx to 0.8.2. breaks script with KeyError: u"no style with name 'Light Shading Accent 1' #149
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
Hi Peter, I'll need to see the line of code that's triggering this along with a few lines of context. Also I'll need to know if you're starting the document from the default or opening a "template" document of your own, i.e. I have a suspicion we'll have to change the default behavior upon adding a new table. It hadn't shown up before because it's only in this latest release that assigned style names are validated against styles actually available in the document. |
This is the complete traceback
Nowhere in the script I use 'Light Shading Accent 1'. I know this is one of the built-ins.
I can look into this further coming weekend. |
Ah, got it. It's as I suspected. This is a useful catch. You can work around it by adding table_stories = document.add_table(1, 4, style=None) I'm going to need to rethink using a default style on .add_table(). It escaped without notice before because there was no lookup to validate that a style existed in the document. I'll get a patch out for this probably this weekend. Thanks for reporting it :) |
I had several places where tables were created, so applied the workaround there. Have some rework to do for this 👍
|
On that one it's worth a try to use the style name just as it appears in the user interface (UI). Style lookup is now based on the style name rather than the style_id. Based on the localized document you sent, it looks like the name for a custom (user created as opposed to built-in) style is assigned in the local language, with exactly the name you give it. If that doesn't work, you may need to inspect the styles.xml with opc-diag to see the exact name it's using. But I think it's going to work. I don't know where it would get the spelling to use in the UI otherwise :) If it's a built-in style, you'll need to use the English name for it. Inspecting the styles.xml part will give you that or there's a link in the docs here for a page where you can get them all translated for your localized language:http://python-docx.readthedocs.org/en/latest/user/styles-using.html |
Fixed in release v0.8.5, pushed on Feb 21, 2015. Table style no longer defaults to 'Light Shading Accent 1'. |
Updated to v0.8.5. Seems OK. Still struggling with some table styles. Do not completely understand how table style name and id are handled. Will investigate further to describe it clearly.
Produces this list: Normal Table The style I'm actually using is not in this list. How to prevent this warning is not so obvious to me.
|
I suspect a localization related problem.
The text was updated successfully, but these errors were encountered: