Last active
August 29, 2015 14:27
-
-
Save kemadz/90d28d3e225767311b38 to your computer and use it in GitHub Desktop.
Append one doc file to another and save as html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
# https://msdn.microsoft.com/en-us/library/Microsoft.Office.Interop.Word.aspx | |
from win32com import client as win32 | |
import sys | |
reload(sys) | |
sys.setdefaultencoding('utf-8') | |
word = win32.gencache.EnsureDispatch("Word.Application") | |
doc1 = word.Documents.Open("D:\\part1.doc") | |
doc2 = word.Documents.Open("D:\\part2.doc") | |
doc1.Range().InsertAfter(doc2.Content) | |
# https://msdn.microsoft.com/en-us/library/aa432511(v=office.12).aspx | |
# msoEncodingSimplifiedChineseGBK <==> 936 | |
doc1.WebOptions.Encoding = 936 | |
# https://msdn.microsoft.com/en-us/library/bb238158(v=office.12).aspx | |
# win32com.client.constants.wdFormatFilteredHTML <==> 10 | |
doc1.SaveAs("D:\\file.html", FileFormat=10) | |
doc1.Close() | |
doc2.Close() | |
word.Quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment