Имя пользователя:
Пароль:  
Помощь | Регистрация | Забыли пароль?  

Показать сообщение отдельно

Ветеран


Сообщения: 27449
Благодарности: 8087

Профиль | Отправить PM | Цитировать


Цитата voha:
Это не принципиально. »
Это очень даже принципиально.

Цитата voha:
Что-бы Вы посоветовали в рамках поставленной задачи? »
Я бы посоветовал, например, WSH:
читать дальше »
Код: Выделить весь код
Option Explicit

Const WindowsFolder   = 0
Const SystemFolder    = 1
Const TemporaryFolder = 2

Const WshRunning  = 0
Const WshFinished = 1
Const WshFailed   = 2

Const wdDoNotSaveChanges    =  0
Const wdPromptToSaveChanges = -2
Const wdSaveChanges         = -1

Const wdPrintFromTo         = 3
Const wdPrintRangeOfPages   = 4


Dim strFolder

Dim objFile

Dim objWshShell
Dim objWshExec
Dim objRegExp

Dim strOut
Dim strFileName
Dim strTempFile

Dim objWord


strFolder = "E:\Песочница\0254"

Set objWshShell = WScript.CreateObject("WScript.Shell")
Set objRegExp   = WScript.CreateObject("VBScript.RegExp")
Set objWord     = Nothing

With WScript.CreateObject("Scripting.FileSystemObject")
	If .FolderExists(strFolder) Then
		For Each objFile In .GetFolder(strFolder).Files
			Select Case LCase(.GetExtensionName(objFile.Name))
				Case "rar", "zip", "arj"
					WScript.Echo "Archive:  " & objFile.Name
					
					Set objWshExec = objWshShell.Exec("""%ProgramFiles%\7-Zip\7z.exe"" l -sccWIN """ & objFile.Path & """ *.doc")
					
					strOut = ""
					
					If objWshExec.Status <> WshFailed Then
						Do
							strOut = strOut & objWshExec.StdOut.ReadAll()
							objWshExec.StdErr.ReadAll()
						Loop Until objWshExec.Status = WshFinished
						
						objRegExp.Pattern = "\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} .{5} +\d+ +\d+ +(.+\.doc)"
						
						If objRegExp.Test(strOut) Then
							strFileName = objRegExp.Execute(strOut).Item(0).SubMatches(0)
							WScript.Echo "Document: " & strFileName
							
							If objWshShell.Run("""%ProgramFiles%\7-Zip\7z.exe"" e -sccWIN """ & objFile.Path & """ -y -o" & .GetSpecialFolder(TemporaryFolder) & " """ & strFileName & """", 1, True) = 0 Then
								strTempFile = .GetFile(.BuildPath(.GetSpecialFolder(TemporaryFolder), strFileName)).Path
								
								OpenAndPrint strTempFile, objFile.Path
								
								.DeleteFile strTempFile, True
							Else
								WScript.Echo "Can't extract [" & strFileName & "] from archive [" & objFile.Path & "]."
							End If
							
							WScript.Echo
						End If
					Else
						WScript.Echo "Can't execute [""%ProgramFiles%\7-Zip\7z.exe"" l -sccWIN """ & objFile.Path & """ *.doc]."
					End If
					
					Set objWshExec = Nothing
			End Select
		Next
	Else
		WScript.Echo "Folder [" & strFolder & "] not found."
	End If
End With

If Not objWord Is Nothing Then
	objWord.Quit wdDoNotSaveChanges
	Set objWord = Nothing
End If

Set objRegExp   = Nothing
Set objWshShell = Nothing

WScript.Quit 0
'=============================================================================

'=============================================================================
Sub OpenAndPrint(strPath2File, strPath2Archive)
	If objWord Is Nothing Then
		Set objWord = WScript.CreateObject("Word.Application")
	End If
	
	With objWord.Documents.Open(strPath2File, False, True, False)
		With .Paragraphs.Item(1).Range
			.InsertParagraphBefore
			.InsertBefore strPath2Archive
		End With
		
		.PrintOut True, False, wdPrintFromTo, "", "1", "1"
		
		Do
			WScript.Sleep 100
		Loop Until objWord.BackgroundPrintingStatus = 0
		
		.Close wdDoNotSaveChanges
	End With
End Sub
'=============================================================================
Это сообщение посчитали полезным следующие участники:

Отправлено: 11:17, 16-05-2013 | #5