Skip to content

Instantly share code, notes, and snippets.

@fearthecowboy
Last active February 3, 2023 03:01
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fearthecowboy/8830876 to your computer and use it in GitHub Desktop.
Save fearthecowboy/8830876 to your computer and use it in GitHub Desktop.
#fixed now!
Param(
[string]$html,
[string]$docx
)
# make the powershell process switch the current directory.
$oldwd = [Environment]::CurrentDirectory
[Environment]::CurrentDirectory = $pwd
$html = resolve-path $html;
$docx = [IO.Path]::GetFullPath( $docx )
[Environment]::CurrentDirectory = $oldwd
[ref]$SaveFormat = "microsoft.office.interop.word.WdSaveFormat" -as [type]
$word = New-Object -ComObject word.application
$word.visible = $false
"Converting $html to $docx..."
$doc = $word.documents.open($html)
$doc.saveas([ref] $docx, [ref]$SaveFormat::wdFormatDocumentDefault)
$doc.close()
$word.Quit()
$word = $null
[gc]::collect()
[gc]::WaitForPendingFinalizers()
@neelaryan
Copy link

Will check this out soon.

@lucianoybanez
Copy link

lucianoybanez commented Jun 15, 2020

I share another script which converts html to docx without having office app installed.

https://github.com/lucianoybanez/ps-useful-scripts/tree/master/html-to-word-openxml

@zoghal
Copy link

zoghal commented Dec 9, 2020

woow 👍
question: :now for docx to html, What to do?

@helios741
Copy link

The layout of Word content after converting has many mistakes.
Do you have met this situation?

@zoghal
Copy link

zoghal commented Feb 1, 2023

The layout of Word content after converting has many mistakes. Do you have met this situation?

yes 🥴

@helios741
Copy link

The layout of Word content after converting has many mistakes. Do you have met this situation?

yes 🥴

Do you have solutions for this the situation?
I have met a problem - how to convert string of Latex formula in the Word document to Omml, so far i cannot a solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment