Issues 375 - Add support for Strict Open XML document
This commit is contained in:
Mikael Karlsson
2025-11-11 18:59:35 +11:00
parent f1fdf5c078
commit cd26450a10
+34 -2
View File
@@ -63,8 +63,17 @@ function Add-WordOptionsControl
$global:spWordCustomProperties.Visibility = (?: ($global:cbWordDocumentationProperties.SelectedValue -ne "custom") "Collapsed" "Visible")
$global:txtWordCustomProperties.Visibility = (?: ($global:cbWordDocumentationProperties.SelectedValue -ne "custom") "Collapsed" "Visible")
$global:cbWordDocumentationFormat.ItemsSource = ("[ { Name: `"Docx`",Value: `"docx`" }, { Name: `"PDF`",Value: `"pdf`" }]" | ConvertFrom-Json)
$global:cbWordDocumentationFormat.SelectedValue = (Get-Setting "Documentation" "WordDocumentFormat" "docx")
$global:cbWordDocumentationFormat.ItemsSource = ("[ { Name: `"Word default document (docx)`",Value: `"wdFormatDocumentDefault`" }, { Name: `"Strict Open XML document`",Value: `"wdFormatStrictOpenXMLDocument`" }, { Name: `"PDF`",Value: `"wdFormatPDF`" }]" | ConvertFrom-Json)
$currentFormat = (Get-Setting "Documentation" "WordDocumentFormat" "wdFormatDocumentDefault")
if($currentFormat -eq "pdf")
{
$currentFormat = "wdFormatPDF"
}
elseif($currentFormat -eq "docx")
{
$currentFormat = "wdFormatDocumentDefault"
}
$global:cbWordDocumentationFormat.SelectedValue = $currentFormat
$global:cbWordDocumentationLevel.ItemsSource = ("[ { Name: `"Full`",Value: `"full`" }, { Name: `"Limited`",Value: `"limited`" }, { Name: `"Basic`",Value: `"basic`" }]" | ConvertFrom-Json)
$global:cbWordDocumentationLevel.SelectedValue = (Get-Setting "Documentation" "WordDocumentationLevel" "full")
@@ -405,6 +414,17 @@ function Invoke-WordPostProcessItems
$script:doc.TablesOfFigures | ForEach-Object -Process { $_.Update() | Out-Null }
$script:doc.TablesOfAuthorities | ForEach-Object -Process { $_.Update() | Out-Null }
Write-Log "Using document format: $($global:cbWordDocumentationFormat.SelectedValue)"
try {
$format = [Microsoft.Office.Interop.Word.WdSaveFormat]$global:cbWordDocumentationFormat.SelectedValue
}
catch
{
Write-LogError "Document validation failed" $_.Exception
$format = [Microsoft.Office.Interop.Word.WdSaveFormat]::wdFormatDocumentDefault
}
<#
if($global:cbWordDocumentationFormat.SelectedValue -eq "pdf")
{
$format = [Microsoft.Office.Interop.Word.WdSaveFormat]::wdFormatPDF
@@ -412,6 +432,7 @@ function Invoke-WordPostProcessItems
else {
$format = [Microsoft.Office.Interop.Word.WdSaveFormat]::wdFormatDocumentDefault
}
#>
$fileName = $global:txtWordDocumentName.Text
if(-not $fileName)
@@ -436,6 +457,7 @@ function Invoke-WordPostProcessItems
Write-LogError "Failed to save file $fileName" $_.Excption
}
try {
if($global:chkWordOpenDocument.IsChecked -eq $true -and $global:hideUI -ne $true)
{
$script:wordApp.Visible = $true
@@ -449,6 +471,16 @@ function Invoke-WordPostProcessItems
$script:wordApp.Quit()
}
}
catch
{
Write-LogError "Failed to close the Word application" $_.Exception
}
finally {
[void][Runtime.InteropServices.Marshal]::ReleaseComObject($script:doc)
[void][Runtime.InteropServices.Marshal]::ReleaseComObject($script:wordApp)
[GC]::Collect(); [GC]::WaitForPendingFinalizers()
}
}
function Set-WordContentControlText
{