jenkins - 为什么在 word 文件中更新日期和版本不起作用
问题描述
在我的项目中,我有以下代码可以在 word 文档中查找和替换版本号和日期,但由于某种原因它不起作用。我可以从你们那里得到帮助以了解它为什么不起作用吗?这是我在 Jenkins + MSBuild 中使用的 ps1 文件。谢谢
<#
Uses Microsoft Word automation to substitute Version and ReleaseDate values, and yield a PDF.
#>
function UpdateDocumentation {
param (
[string] $Path,
[string] $Version,
[string] $ReleaseDate
)
$path = Resolve-Path -Path $Path;
$word = New-Object -ComObject Word.Application;
$doc = $word.Documents.Open($path);
$selection = $word.Selection
$Forward = $MatchWholeWord = $true;
$Format = $MatchAllWordForms = $MatchCase = $MatchSoundsLike = $MatchWildcards = $Wrap = $false;
$FindText = "%Version%";
$ReplaceWith = [System.Version]::Parse($Version).ToString(3);
$selection.Find.Execute($FindText, $MatchCase, $MatchWholeWord, $MatchWildcards, $MatchSoundsLike, $MatchAllWordForms, $Forward, $Wrap, $Format,
$ReplaceWith, [Microsoft.Office.Interop.Word.WdReplace]::wdReplaceAll);
$FindText = "%ReleaseDate%";
$ReplaceWith = [DateTime]::Today.ToString("MMMM yyyy");
$selection.Find.Execute($FindText, $MatchCase, $MatchWholeWord, $MatchWildcards, $MatchSoundsLike, $MatchAllWordForms, $Forward, $Wrap, $Format,
$ReplaceWith, [Microsoft.Office.Interop.Word.WdReplace]::wdReplaceAll);
$pdf = [System.IO.Path]::ChangeExtension($(Resolve-Path $Path), '.pdf');
$doc.SaveAs($pdf, [Microsoft.Office.Interop.Word.WdSaveFormat]::wdFormatPDF);
$doc.Close([Microsoft.Office.Interop.Word.WdSaveOptions]::wdDoNotSaveChanges);
$word.Quit();
}
以及对它的调用:
UpdateDocumentation -Path '.\assureid-documentation\assureid-word-pdf-docs\assureid-sentinel\AssureID Sentinel Deployment Guide.docx' `
-Version $Version -ReleaseDate [DateTime]::Today
该文档包含以下文本:版本 %VERSION% %RELEASEDATE%
解决方案
我对一些 Excel 方法也有类似的问题。您是否可以尝试不定义不需要使用的可选参数:
$selection.Find.Execute($FindText, $MatchCase, $MatchWholeWord, $null, $null, $null, $null, $null, $null,
$ReplaceWith, [Microsoft.Office.Interop.Word.WdReplace]::wdReplaceAll);
推荐阅读
- reactjs - 将本机插件与本机基本选项卡一起反应轮播
- node.js - 使用 Mongoose findOneAndUpdate() 或 updateOne() 哪个模式选择子对象?
- python - 如何在twint中获取位置数据
- javascript - 使用 javascript Fetch 函数从 Feed URL 获取唯一值
- javascript - prevItem 如何获取前一项的值?
- powershell - Powershell 无法使用 New-SelfSignedCertificate 加载私钥
- r - R如何将十进制数字(年.月)转换为日期格式
- corda - 如何从我的 API 处理医院异常?
- c - 如何在 C 中的可变参数函数中操作作为参数传递的 void 指针
- ios - 在 SwiftUI 中异步加载存储在可观察对象中的 UIImages