word文档批量合并工具

用于批量合并word文档

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

#SingleInstance Force
FileInstall ,D:\2 IE天使\ICO图标制作\ICO图标文件2\ICO2\s023.ico,c:\3.ico,1
If fileExist("C:\3.ico")
	Menu, Tray, Icon, c:\3.ico, , 1  ;显示图标
try 
{
	wd:=ComObjActive("word.Application")
}catch e{  ;用于捕获错误,未启动word就抛出!!!
	MsgBox 当前未启动word,请先打开word,注意不是WPS!!!
	return
}
SetWorkingDir %A_ScriptDir%
Gui Font, s13
Gui Add, Text, x150 y1 w538 h50 +0x200, word文档合并工具  ;后面可修饰字体颜色,字号等;
Gui, Add, Checkbox, x60 y175 w200 h20  v子文件夹 checked, 合并子文件夹中的文档
Gui, Add, Checkbox, x300 y175 w200 h20  v扩展名, 显示扩展名
Gui Add, Button, x144 y205 w160 h70  g开始合并, 开始合并
Gui Font
Gui Font, s14
Gui Add, Text, x28 y44 w538 h50 +0x200, 将要合并的文件夹拖入,或者定位文件夹(必须先打开word)
Gui Font
Gui Add, Edit, x32 y112 w366 h49 vEdit1
Gui Add, Button, x407 y118 w75 h47 g定位, 定位
Gui Show, w550 h314, Word文档合并工具
Return
;autogui如何反相生成gui?
GuiEscape:
GuiClose:
    ExitApp

; End of the GUI section
开始合并:
Gui, Submit

doc0:=wd.documents.add
Loop  ,%Edit1%\*.doc*, 0, %子文件夹% ;第三个参数:0-仅文件;1-文件+文件夹;2-仅文件夹,但是若是前面仅仅给出个母文件夹的话,可以但限制了具体文件后缀的话2就无效了;最后一个为1时为递归;
{
	st:=doc0.range.end-1
	if(扩展名=1)
		doc0.range.InsertAfter(A_LoopFileName "`r`n")  ;带扩展名
	else
		doc0.range.InsertAfter(RegExReplace(A_LoopFileName,"`ami)\..*$") "`r`n")  ;不带扩展名
	
	  doc0.Range(st,doc0.range.end-1).Style := ("标题 2")
      doc0.Range(st,doc0.range.end-1).Font.Color:=255 ;0x0000FF ;RGB(255, 0, 0)
	doc0.range(doc0.range.end-1,doc0.range.end-1).Insertfile(A_LoopFileLongPath) ;插入文件
}
WinActivate, % doc0.name  ;激活文档
MsgBox  "已完成!!!" 
;~ doc0.saveas "c:\tesd.doc"
return

定位:
FileSelectFolder,fod,,3,文件夹选择 ;FileSelectFolder, OutputVar, ::{20d04fe0-3aea-1069-a2d8-08002b30309d}  ; 我的电脑.
if(fod="")
	return
GuiControl,, Edit1, %fod%
return


GuiDropFiles:  ; 对拖放提供支持.经典代码★★★★★★★★★★★★※※※※※※
SelectedFileName := A_GuiEvent
;获取鼠标下面的控件★★★★★★★★★★★★★★★★★★★★★
MouseGetPos, , , id, control
;~ WinGetTitle, title, ahk_id %id%
WinGetClass, class, ahk_id %id%
;~ ToolTip, ahk_id %id%`nahk_class %class%`n%title%`nControl: %control%
if (control="Edit1")
{
	GuiControl,, Edit1, %SelectedFileName%  ; 在控件中显示文本.
}
if (control="Edit2")
{
	GuiControl,, Edit2, %SelectedFileName%  ; 在控件中显示文本.
}
return


猜你喜欢

转载自blog.csdn.net/zhanglei1371/article/details/53933281