Guest User

Untitled

a guest
Dec 14th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. param(
  2. [parameter(position=0)]
  3. [string] $Path
  4. )
  5.  
  6. # make the powershell process switch the current directory.
  7. $oldwd = [Environment]::CurrentDirectory
  8. [Environment]::CurrentDirectory = $pwd
  9.  
  10. $htmlFiles = (Get-ChildItem "$Path\*" -Include *.html,*.htm) # -Recurse)
  11.  
  12. $word = New-Object -ComObject Word.Application
  13. $word.visible = $false
  14. [ref]$SaveFormat = "Microsoft.Office.Interop.Word.WdSaveFormat" -as [type]
  15.  
  16. foreach ($hf in $htmlFiles)
  17. {
  18. #Write-Host "Got $hf"
  19. $html = resolve-path $hf;
  20. # $docx = [IO.Path]::GetFullPath( $docx )
  21. $docx = "$html.docx"
  22.  
  23. #[Environment]::CurrentDirectory = $oldwd
  24.  
  25. Write-Host "Converting $html to $docx..."
  26.  
  27. # Write-Host $html.GetType()
  28. # System.Management.Automation.PathInfo
  29. $doc = $word.Documents.Open($html.toString())
  30. #$doc.Activate()
  31.  
  32. $doc.ActiveWindow.View = 3 #wdPrintView
  33.  
  34. $doc.saveas([ref] $docx, [ref]$SaveFormat::wdFormatDocumentDefault)
  35. $doc.close()
  36. #break
  37. }
  38.  
  39. $word.Quit()
  40. $word = $null
  41. [gc]::collect()
  42. [gc]::WaitForPendingFinalizers()
Add Comment
Please, Sign In to add comment