需安装有Microsoft Office
以下代码复制粘贴到记事本,另存为xx.bat,编码选ANSI,跟要处理的文件放一起双击运行- /*&cls&echo off&cd /d "%~dp0"
- type "%~f0"|cscript -nologo -e:jscript "%~f0">"%tmp%\v.v"
- dir /a-d-h/b|findstr /ie "\.doc \.docx"|cscript -nologo -e:vbscript "%tmp%\v.v"
- pause
- exit
- */
- var text=WSH.StdIn.ReadAll();
- var vbs=text.match(/\/\*\r\n([\s\S]+)\*\/\s*$/);
- WSH.echo(vbs[1]);
- /*
- On Error Resume Next
- Set fso=CreateObject("Scripting.Filesystemobject")
- Set word=CreateObject("Word.Application")
-
- If Err.Number <>0 Then
- WSH.StdErr.WriteLine "Microsoft Word 未安装"
- WSH.Quit
- End If
- On Error Goto 0
- word.DisplayAlerts=False
- word.Visible=True
-
-
- Do While WSH.StdIn.AtEndOfStream<>True
- On Error Resume Next
- it=WSH.StdIn.ReadLine
- basename=fso.GetBaseName(it)
- Set docfile=fso.GetFile(it)
- If Left(docfile.shortname, 2) <> "~$" Then
- Set doc=word.Documents.Open(docfile.Path,,,,"pwd")
- If doc Is Nothing Then
- doc.Close
- End If
- doc.Activate
- doc.Range(0).Select
- word.Selection.HomeKey 6
- word.Selection.Font.Name="宋体"
- word.Selection.Font.Size=14
- word.Selection.TypeText basename
- word.Selection.TypeParagraph
- word.Selection.TypeParagraph
- doc.Close True
- WSH.echo "[Done]" &it
- End If
- If Err.Number <>0 Then
- WSH.StdErr.WriteLine "[Error]" &it
- End If
- On Error Goto 0
- Loop
-
- word.Quit
- WSH.Quit
- */
复制代码
|