2013-07-22 3 views
0

단어 문서의 모든 페이지에 머리말과 꼬리말을 추가하고 문서의 시작 부분에 일부 페이지를 추가하려면 어떻게해야합니까? 파이썬? 나는 파이썬 - docx 시도했지만 예상대로 작동하지 않습니다. 내 요구 사항을 달성하기위한 다른 방법이 있습니까?Word 문서 편집, 머리말/꼬리말 추가 및 저장 - Python

+0

내 대답이 사용자의 요구 사항에 맞습니까? – edi9999

답변

3

필자가 취할 수있는 최선의 방법은 파일을 관리하는 방법을보기 위해 python-docx를 보는 것입니다.

+--docProps 
| + app.xml 
| \ core.xml 
+ res.log 
+--word //this folder contains most of the files that control the content of the document 
| + document.xml //Is the actual content of the document 
| + endnotes.xml 
| + fontTable.xml 
| + footer1.xml //Containst the elements in the footer of the document 
| + footnotes.xml 
| +--media //This folder contains all images embedded in the word 
| | \ image1.jpeg 
| + settings.xml 
| + styles.xml 
| + stylesWithEffects.xml 
| +--theme 
| | \ theme1.xml 
| + webSettings.xml 
| \--_rels 
|  \ document.xml.rels //this document tells word where the images are situated 
+ [Content_Types].xml 
\--_rels 
    \ .rels 

먼저 DOCX에 DOCX - 파이썬 추출물과 같은 라이브러리, 그래서 당신이 그것을 찾을 수 :

.docx 형식은 다음과 같은 폴더가 포함 된 압축 파일입니다 : DOCX는 압축 형식 (Docx Tag Wiki)입니다 파이썬 DOCX에 : 나는 당신을 위해 그것을 발견 : 당신은 DOCX의 주요 내용 인 '워드/document.xml'의 xmlcontent를 얻을 수

def opendocx(file): 
    '''Open a docx file, return a document XML tree''' 
    mydoc = zipfile.ZipFile(file) 
    xmlcontent = mydoc.read('word/document.xml') 
    document = etree.fromstring(xmlcontent) 
    return document 

https://github.com/mikemaccana/python-docx/blob/master/docx.py#L65는, DOCX - 파이썬을 사용하거나 변경 (나는 당신에게 권합니다, docx- 파이썬 많은 다른 요소를 추가 할 수있을 것으로 보인다. 문서의 시작 부분에 다른 단어 문서의 내용을 복사하려면 document.xml의 내용을 document.xml에 복사하려고 시도 할 수는 있지만 아마도 몇 가지 오류가 발생할 수 있습니다. 특히 이미지 또는 비 텍스트 콘텐츠를 사용하십시오.

머리글이나 바닥 글을 추가하려면 word/header1.xml 또는 word/footer1.xml 파일을 만들어야합니다. 만든 파일의 header1.xml 내용 만 복사하면됩니다.

희망 하시겠습니까?