![]() Write_and_close_docx(word_doc, soup, new_word_doc) If 'margin-left:0pt' in shape.get('style'): New_word_doc = 'edited/' + file.rstrip('.docx') + '-edited.docx' ![]() # Now, create the new zip file and add all the filex into the archiveĭocx = zipfile.ZipFile(zip_copy_filename, "w")ĭocx.write(os.path.join(tmp_dir, filename), filename) # Get a list of all the files in the original docx zipfile With open(os.path.join(tmp_dir, 'word/document.xml'), 'w') as f: Write the modified xml to word/document.xml """ Create a temp directory, expand the original docx zip. With zipfile.ZipFile(docx_filename) as zf:ĭef write_and_close_docx(self, edited_xml, output_filename): Return content of document.xml file inside docx document Also, for more speed you can use lxml instead of Soup. They just placed the header's and footer's images in a top of page. Also, my docx documents doesn't have header and footer in xml. I'm using BeautifulSoup, because standart xml parser can't get a valid xml-tree. ![]() This is my final version (it's usefull for me, because I need to edit many. P.S.I have an idea to use lxml or BeautifulSoup to parse xml and replace some parts, but it looks dirty Is there any way to achieve that in Python?Īs I understand, docx is a xml-based format, but I don't know how to use it. I was currently trying using python-docx library, but it doesn't support header and footer in docx document at this time (work in progress). I need to remove headers and footers in many docx files. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |