Skip to content

feature analysis: section columns #355

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

vik378
Copy link

@vik378 vik378 commented Jan 29, 2017

Provides analysis page for section-columns feature (with a final intention to fix #167):

  • XML schema analysis
  • candidate API
  • specimen XML

@vik378 vik378 changed the title feature analysis: section columns #167 feature analysis: section columns Jan 29, 2017
@vik378
Copy link
Author

vik378 commented Feb 1, 2017

@scanny, could you please review the proposed API? It would help a lot as I may get some time to move this feature forward over the weekend. Thanks!

@scanny
Copy link
Contributor

scanny commented Feb 1, 2017

Hi @electron378, thanks for this, I've had a look over it.

I'd say it's a great start. The main thing is it doesn't look like you've referred to the Microsoft API for Word (MS API). That turns out to be a critical piece of the puzzle for avoiding mis-steps in defining the python-docx API.

If it's not immediately apparent how to do what I'm defining using the MS API, I search on something like "vba word section columns" and that will generally get me close enough to find what I'm looking for in the Word API reference: http://msdn.microsoft.com/en-us/library/office/ff837519.aspx

In this case, it turns out to be critical, because it points to a shared object, a PageSetup object I believe, that appears both in sections and perhaps for the document overall. So the protocol would look something like:

section = document.sections[-1]
page_setup = section.page_setup
text_columns = page_setup.text_columns
text_column = text_columns[0]
text_column.width = Inches(2)
text_column.space_after = Inches(0.25)

This is the neighborhood in which to look in the Word API:

https://msdn.microsoft.com/en-us/library/office/ff194295.aspx
https://msdn.microsoft.com/en-us/library/office/ff191765.aspx
https://msdn.microsoft.com/en-us/library/office/ff840256.aspx
etc. ...

It looks like there is also a Document.PageSettings property in the MS API, so if we add that later it can reuse the PageSettings objects we create here.

In general, I've found it best to mirror the MS API whenever possible, using pythonicized names. There are two parts to the rationale. First is that the designers put a lot of thought into it, more than we're likely to, and what they have works as a complete whole. This is a big plus, because we're adding on individual features incrementally, and its easy to "re"-design yourself into a box where you later have to change the API. Changing the API is the one big no-no in a library. Folks build things that depend on the API and if you change it you break their code.

The second reason is because at least some folks are already familiar with the MS API, so might as well not make it any harder for them than necessary.

@scanny
Copy link
Contributor

scanny commented Feb 1, 2017

Also make sure you include the relevant XML Schema excerpts. The XML schemas are in the code tree here:
https://github.com/python-openxml/python-docx/tree/master/ref/xsd

Most of the elements for this will probably be in wml.xsd. Check out the other analysis pages for examples of proper layout.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feature: columnar layout in Section
2 participants