[APAC]导入图片至Word,然后按规则命名(2/2)

#将所有docx文件改成可读
Set-ItemProperty -Path "e:\screenshot\*.docx" -Name IsReadOnly -Value $false
#从远端服务器剪切截图至本地
$target = "e:\screenshot"
$pw = ConvertTo-SecureString '密码' -AsPlainText -Force
$Creds = New-Object -Typename System.Management.Automation.PSCredential -Argumentlist "apac\814072", $pw
New-PSDrive -Name P -PSProvider FileSystem -Root "\\10.103.22.39\c$\ScreenShot" -Credential $Creds
Get-ChildItem -Path P:\ | Move-Item -Destination $target -Force
Remove-PSDrive -Name P
#文件名命名规则
$filename = (Get-Date).Tostring("yyyyMMdd")
#创建一个空的word文档,供Add-OSCPicture使用
$objWord = New-Object -ComObject Word.Application
$objWord.Visible = $false
$objDoc = $objWord.Documents.Add()
$objSelection = $objWord.Selection
$objDoc.SaveAs([ref]"e:\screenshot\$filename",[ref]16)
$objword.Quit()
#调用外部函数Add-OSCPicture,将多张图片依次导入word
Add-OSCPicture -WordDocumentPath "e:\screenshot\$filename.docx" -ImageFolderPath "e:\screenshot\"
#删除所有JPG文件
#Get-ChildItem -path *.JPEG | Remove-Item

 

posted @ 2015-05-13 16:13  dongdonggeorge  阅读(267)  评论(0编辑  收藏  举报