qvw-preserve-interface/templates/inject_include.ps1

42 lines
1.4 KiB
PowerShell
Raw Permalink Normal View History

# inject_include.ps1 — rewrite a QVW's embedded Script to include a different
# MustInclude .qvs file (typical use: version bump from 9.QVSv8 -> 9.QVSv9).
#
# IMPORTANT: The legacy $doc.SetScript($s) method does NOT exist on modern
# QlikView Document COM (>= QV11). Use GetProperties() -> .Script -> SetProperties().
#
# Usage:
# powershell -ExecutionPolicy Bypass -File inject_include.ps1 `
# -QvwPath "C:\path\to\app.qvw" `
# -NewInclude "C:\path\to\9.QVSv9\0100.MustInclude.qvs"
param(
[Parameter(Mandatory=$true)][string]$QvwPath,
[Parameter(Mandatory=$true)][string]$NewInclude
)
$ErrorActionPreference = "Stop"
if (-not (Test-Path $QvwPath)) { throw "QVW not found: $QvwPath" }
if (-not (Test-Path $NewInclude)) { throw "Include file not found: $NewInclude" }
$qv = New-Object -ComObject QlikTech.QlikView
$doc = $qv.OpenDoc($QvwPath, "", "")
if (-not $doc) { throw "OpenDoc returned null for $QvwPath (check filename for spaces/typos)" }
Start-Sleep -Seconds 3
$newScript = @"
SET ErrorMode = 0;
SET DateFormat='YYYY-MM-DD';
`$(Include=$NewInclude);
"@
$props = $doc.GetProperties()
Write-Host "Current script head: $($props.Script.Substring(0, [Math]::Min(120, $props.Script.Length)))"
$props.Script = $newScript
$doc.SetProperties($props)
$doc.Save()
Write-Host "Saved $QvwPath with include -> $NewInclude"
Start-Sleep -Seconds 2
$qv.Quit()