Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#:写入word文档;“字符串参数太长”;_C#_Winforms_Office Interop - Fatal编程技术网

C#:写入word文档;“字符串参数太长”;

C#:写入word文档;“字符串参数太长”;,c#,winforms,office-interop,C#,Winforms,Office Interop,我正在用C#和WinForms编写一个桌面应用程序。应用程序搜索文本并将其替换为用户输入 问题在于,当使用多行属性设置为true的文本框时,如果输入的字符串参数超过254个字符,则系统.Runtime.InteropServices.COMException返回错误 方法如下: private void FindAndReplace(Word.Application WordApp, object findText, object replaceWithText) { o

我正在用C#和WinForms编写一个桌面应用程序。应用程序搜索文本并将其替换为用户输入

问题在于,当使用多行属性设置为
true
文本框时,如果输入的
字符串参数超过254个字符,则
系统.Runtime.InteropServices.COMException
返回错误

方法如下:

private void FindAndReplace(Word.Application WordApp, object findText, object replaceWithText)
    {
        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);          
    }
我已经读到解决这个问题的一种可能方法是将值分解为多个字符串数组,但这是唯一的解决方法还是有更简单的方法

其他一些解决方案已经在ASP.NET中编写了JS包装器,但我没有服务器端功能


另外,在使用Interop.Word时,为什么多行
文本框的长度限制为254?

将maxLength设置为0:

然后可以为文本框输入最大字符数()


将maxLength设置为0:

然后可以为文本框输入最大字符数()


有几件事:1。您真的需要这么多参数吗?它们真的需要通过引用传递吗?你想改变他们的价值吗?你在这里省不了多少开销。2.为什么要将布尔值和整数隐式转换为
对象
?您意识到,当您这样做时,您会丢失该类型的所有属性和方法。如果它是一个对象,你就不能这样做,那么你会如何使用它们呢?3.为什么不直接使用
var
var
隐式检测类型,并保留其属性和方法。4.为什么不创建一个存储所有这些变量的参数对象呢?这个特殊的答案可能会有帮助:1。您真的需要这么多参数吗?它们真的需要通过引用传递吗?你想改变他们的价值吗?你在这里省不了多少开销。2.为什么要将布尔值和整数隐式转换为
对象
?您意识到,当您这样做时,您会丢失该类型的所有属性和方法。如果它是一个对象,你就不能这样做,那么你会如何使用它们呢?3.为什么不直接使用
var
var
隐式检测类型,并保留其属性和方法。4.为什么不创建一个存储所有这些变量的参数对象呢