15 June,2012 by Tom Collins
Question : I have a list of Microsoft Word Docs , which need to be converted into html . How can I do this with Powershell? I've already checked ConvertTo-Html , but it's a different purpose
Answer: Converting a list of Microsoft Word documents is repetitive and time consuming. Powershell creates a new com object , which filters the Word Doc into html format.
The assembly loads the type [Microsoft.Office.Interop.Word.WdSaveFormat]
This script reads all Word documents in the $srcFiles path and outputs them into the $htmlOutputPath.
Note: the file is saved with the base name. For example, if the word doc is called "test.docx" the file is saved as "test.html"
$wdTypes = Add-Type -AssemblyName 'Microsoft.Office.Interop.Word' -Passthru $docSrc="C:\word\" $htmlOutputPath="C:\word\" $srcFiles = Get-ChildItem $docSrc -filter "*.doc" $saveFormat = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat], "wdFormatFilteredHTML"); $wordApp = new-object -comobject word.application $wordApp.Visible = $False function saveashtml { $openDoc = $wordApp.documents.open($doc.FullName);
$saveas=$doc.Basename
$openDoc.saveas([ref]"$htmlOutputPath\$saveas.html", [ref]$saveFormat); $openDoc.close(); } ForEach ($doc in $srcFiles) { Write-Host "Converting to html :" $doc.FullName saveashtml $doc = $null } $wordApp.quit();
Thanks to Bhargav Shukla for function concepts on this link
Powershell sql server security audit
SQL Server – Send email using Powershell - SQL Server DBA
SQL Server - Powershell and SQL Error Logs
SQL Server DBA Top 10 automation tasks
SQL Server - Top 10 DBA mistakes
This is only a preview. Your comment has not yet been posted.
As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.
Having trouble reading this image? View an alternate.
Posted by: |