computingvasup.blogg.se

Change spacing between lines in word 2010
Change spacing between lines in word 2010















Remove_contextual_spacing_from_style('path_to. # overwrite old docx file with modified docx

#Change spacing between lines in word 2010 archive#

# store xml file in modified docx archive If xml_item.filename = 'word/styles.xml':Ĭspace = re.search(b'"%s".*?'%(style_byte), content)Ĭontent = re.sub(cspace, wo_cspace, content) # search style_name section in word/styles.xml With ZipFile(docx_path, 'r') as old_docx, ZipFile(mod_docx, 'w') as new_docx: My work-around is to rewrite the docx file (archive) without that contextualSpacing entry: from io import BytesIOĭef remove_contextual_spacing_from_style(docx_path, style_name): When examining the underlying xml files, I found a "w:contextualSpacing" entry in the "List Number" section of word/styles.xml. I tried David Zemens answer with an ordered list of style "List Number", but still had the check on "Dont't add space between paragraphs of the same style" in my docx file. You can remove these from the underlying XML like so: for p in document.paragraphs:Ĭspacing = p_element.xpath(r'w:pPr/w:contextualSpacing')Īfter removing those elements, open the document again and observe the toggle has been turned off, and the paragraphs observe the space_after: This is given by the element of the (I notice this by examining the \word\document.xml part of the Docx). From the 'Line spacing' drop-down list, choose the spacing you would like Word to use. From the Indents and Spacing tab > Locate the 'Spacing' section. In the lower-right corner of the 'Paragraph' group, click the arrow. So, clearly the space_after is retained, but it's not being observed in the document as it's overridden by the checkbox option. To change the default line spacing: Click the Home tab > Locate the 'Paragraph' group. > document = Document(r'c:\debug\doc1.docx') Save and close the document from Word, then examine it via docx: > from docx import Document Doing so overrides the line spacing settings of whatever style set you are currently using. Once you do, the entire document will have double spacing between every line. In the context menu that appears, click on Double. Select all paragraphs and toggle the "Dont' add space between paragraphs of the same style" to checked. Open the Word document you want to have double spacing between lines in. I've built a document with a few paragraphs of the same style ("Normal") and various space_after:















Change spacing between lines in word 2010