Ske*_*363 1 c# ms-word office-interop
我正在尝试生成一个表并将其插入到Word文档中,如下所示:
object missing = System.Reflection.Missing.Value;
var paragraph = miDoc.Paragraphs.Add(ref missing);
Microsoft.Office.Interop.Word.Table tablaEvaluacion =
Globals.ThisDocument.Tables.Add(paragraph.Range, lstContacto.Count + 1, lstEvaluacion.Count + 3, ref missing, ref missing);
Run Code Online (Sandbox Code Playgroud)
但是当行数超过63时,这会导致异常:" COMException was unhandled by user code. The number must be between 1 and 63."
首先 - 你100%确定你的意思是行吗?您可以从下面的答案中读到,我在表中插入超过63行没有问题,但是插入超过63列但会导致与您描述的问题相同的问题.
无论如何,我试过调查这个 - 这是我发现的:
使用Google:
使用文档:
使用dotPeek:
Microsoft.Office.Interop.Word.Tables类型,希望找到描述限制的评论 - 但没有运气.代码只是在Word中使用函数调用函数,COM因此Exception很可能从Word,interop程序集到代码中一直冒泡.使用我自己的示例实现:
documentA.Tables.Add(range, 01, 64); // COMException -> "The number must be between 1 and 63."
documentA.Tables.Add(range, 01, 63); // All good
documentA.Tables.Add(range, 64, 01); // All good
Run Code Online (Sandbox Code Playgroud)
示例代码显示当我尝试使用超过63列时,COMException您引用的是抛出的.我正在使用Interop API btw的15版运行MS Office 2013.
使用MS Word 2013:

因此,归结为63列似乎是允许插入的最大列数.
希望这有助于解决问题;)