Pythonのwin32comマージモジュールファイルフォルダにA、複数のdocxのdocx

Pythonのwin32comマージモジュールファイルフォルダにA、複数のdocxのdocx

!は/ usr / binに/のenvのpython      - * -コーディング:UTF-8 - * -      
から win32com.client 輸入ディスパッチ
 輸入OS、SYS
 #のPDとして輸入パンダ

以下はシステムを得るために、3つの定数である来る
から win32com.client インポート定数CON ASの
 win32com.client.gencacheインポートEnsureDispatchからEnsureDispatch(「Word.Application」)
DEF MKDIR(パス):
    導入モジュール
    インポートOS

    第1空間の除去
    #1 パス= path.strip() 
    削除末尾\シンボル
    #1 パス= path.rstrip( "\\")

    #は、パスがあるか否かを判定する
    #の存在真
    偽不在 
    isExists = os.path.exists(パス)

    判定結果
    IF  ないisExists:
        あなたが存在しない場合は、ディレクトリの作成
        #はディレクトリ操作関数を作成します
        os.makdirs(パス) 
         を印刷する(パス+ 正常に作成を返す真の
     #をそこに作成された何のディレクトリではありません、そしてプロンプトディレクトリがすでに存在する場合
        印刷(パス+ ディレクトリが存在するの戻り


PWD = __file__ 
PWD = os.path.dirname(PWD)
 プリント(PWD)

MKDIR(os.path.join(PWD、' hebing ' ))
xlApp =ディスパッチ( 'まずExcel.Application') 
wdApp =ディスパッチ(' Word.Application ' xlApp.Visible = 1 

docB = wdApp.Documents.Add( )
 =====页面设置====== 
PS = 56.7 
docB.PageSetup.TopMargin = PS
docB.PageSetup.BottomMargin = PS
docB.PageSetup.LeftMargin = PS
docB.PageSetup.RightMargin = PS
docB.SaveAs(PWD + ' \\ \\ hebing.docx hebing '、14 文書保存====== =========


以下のためのルート、dirsに、ファイル os.walk(os.path.join(PWD、単語ドキュメントフォルダを置く)、トップダウン= 偽):
     印刷(ファイル)
     のための名前ファイル:
        DOCT = wdApp.Documents.Open(os.path.join(ルート、名前))
        docT.Range(0、0)カーソル文書番号開始 
        wdApp.Selection.WholeStory() 選択ワード文書
        wdApp.Selection.Copy ()
        docB.Activate()
        WdApp.Selection.EndKey(単位= con.wdLine)        
        docB.Range() カーソル原稿端
        wdApp.Selection.Delete()
        wdApp.Selection.Paste()
        
        docT.Close()
    
docB.Save()
docB.Close()
wdApp.Quit()

 

おすすめ

転載: www.cnblogs.com/ukeedy/p/11817386.html