我想使用 C# 创建一个世界文档。所以这是我替换word文档变量的代码。
private void FindAndReplace(Microsoft.Office.Interop.Word.Application WordApp, object findText, object replaceWithText)
{
try {
object matchCase = true;
object matchWholeWord = true;
object matchWildCards = false;
object matchSoundsLike = false;
object nmatchAllWordForms = false;
object forward = true;
object format = false;
object matchKashida = false;
object matchDiacritics = false;
object matchAlefHamza = false;
object matchControl = false;
object read_only = false;
object visible = true;
object replace = 2;
object wrap = 1;
WordApp.Selection.Find.Execute(ref findText,
ref matchCase, ref matchWholeWord,
ref matchWildCards, ref matchSoundsLike,
ref nmatchAllWordForms, ref forward,
ref wrap, ref format, ref replaceWithText,
ref replace, ref matchKashida,
ref matchDiacritics, ref matchAlefHamza,
ref matchControl);
} catch (Exception error) {
lblerror.Visible = true;
lblerror.Text = error.ToString();
}
}
但是在这里,如果“replaceWithText”太孤单,就会出现错误,它会说
String parameter too long.
那么如何替换长字符串呢?