Skip to content

Instantly share code, notes, and snippets.

@kemadz
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kemadz/90d28d3e225767311b38 to your computer and use it in GitHub Desktop.
Save kemadz/90d28d3e225767311b38 to your computer and use it in GitHub Desktop.
Append one doc file to another and save as html
# -*- 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