Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- param(
- [parameter(position=0)]
- [string] $Path
- )
- # make the powershell process switch the current directory.
- $oldwd = [Environment]::CurrentDirectory
- [Environment]::CurrentDirectory = $pwd
- $htmlFiles = (Get-ChildItem "$Path\*" -Include *.html,*.htm) # -Recurse)
- $word = New-Object -ComObject Word.Application
- $word.visible = $false
- [ref]$SaveFormat = "Microsoft.Office.Interop.Word.WdSaveFormat" -as [type]
- foreach ($hf in $htmlFiles)
- {
- #Write-Host "Got $hf"
- $html = resolve-path $hf;
- # $docx = [IO.Path]::GetFullPath( $docx )
- $docx = "$html.docx"
- #[Environment]::CurrentDirectory = $oldwd
- Write-Host "Converting $html to $docx..."
- # Write-Host $html.GetType()
- # System.Management.Automation.PathInfo
- $doc = $word.Documents.Open($html.toString())
- #$doc.Activate()
- $doc.ActiveWindow.View = 3 #wdPrintView
- $doc.saveas([ref] $docx, [ref]$SaveFormat::wdFormatDocumentDefault)
- $doc.close()
- #break
- }
- $word.Quit()
- $word = $null
- [gc]::collect()
- [gc]::WaitForPendingFinalizers()
Add Comment
Please, Sign In to add comment