$ErrorActionPreference = 'Stop' Add-Type -AssemblyName System.Windows.Forms Add-Type -AssemblyName System.Drawing $previewRoot = Join-Path $env:TEMP 'sku-audit-sync-20261123-preview' New-Item -ItemType Directory -Path $previewRoot -Force | Out-Null $assetsPath = Join-Path (Split-Path (Split-Path $PSScriptRoot -Parent) -Parent) 'assets' $workbookPath = (Get-ChildItem -LiteralPath $assetsPath -Filter '*_v0.9.xlsx' | Select-Object -First 1).FullName $excelPreview = $null $previewBook = $null try { $excelPreview = New-Object -ComObject Excel.Application $excelPreview.Visible = $false $excelPreview.DisplayAlerts = $false $excelPreview.AskToUpdateLinks = $false $excelPreview.AutomationSecurity = 3 $previewBook = $excelPreview.Workbooks.Open($workbookPath, 0, $true) $sheetIndex = 0 foreach ($sheet in $previewBook.Worksheets) { $sheetIndex++ $sheet.Activate() $lastColumn = $sheet.UsedRange.Columns.Count $lastRow = [Math]::Min(6, $sheet.UsedRange.Rows.Count) $range = $sheet.Range($sheet.Cells.Item(1, 1), $sheet.Cells.Item($lastRow, $lastColumn)) $range.CopyPicture(1, 2) Start-Sleep -Milliseconds 150 $bitmap = [Windows.Forms.Clipboard]::GetImage() if ($null -eq $bitmap) { throw "Excel did not provide an image for sheet $sheetIndex" } $bitmap.Save((Join-Path $previewRoot ('sheet-{0:d2}.png' -f $sheetIndex)), [Drawing.Imaging.ImageFormat]::Png) $bitmap.Dispose() } foreach ($item in @(@(3, 'A62:F65', 'new-rule'), @(11, 'A34:F35', 'change-record'), @(12, 'A57:F61', 'rule-check'))) { $sheet = $previewBook.Worksheets.Item($item[0]) $sheet.Activate() $sheet.Range($item[1]).CopyPicture(1, 2) Start-Sleep -Milliseconds 150 $bitmap = [Windows.Forms.Clipboard]::GetImage() if ($null -eq $bitmap) { throw 'Excel did not provide detail image' } $bitmap.Save((Join-Path $previewRoot ($item[2] + '.png')), [Drawing.Imaging.ImageFormat]::Png) $bitmap.Dispose() } Write-Output ('Rendered ' + $sheetIndex + ' worksheets and 3 changed ranges to ' + $previewRoot) } finally { if ($null -ne $previewBook) { $previewBook.Close($false) } if ($null -ne $excelPreview) { $excelPreview.Quit() [Runtime.InteropServices.Marshal]::ReleaseComObject($excelPreview) | Out-Null } }