C# 请求的集合成员不存在,MS Word
我试着从dotnetpearls.com运行一个示例程序,但一开始该程序根本不起作用 显然,在启动应用程序对象之前,我必须以管理员身份运行VS Express 2012。在那之后,下一次它出错时,是我试图打印文档中的文本时。错误发生在C# 请求的集合成员不存在,MS Word,c#,ms-word,C#,Ms Word,我试着从dotnetpearls.com运行一个示例程序,但一开始该程序根本不起作用 显然,在启动应用程序对象之前,我必须以管理员身份运行VS Express 2012。在那之后,下一次它出错时,是我试图打印文档中的文本时。错误发生在string text=doc.Words[i].text using System; using Microsoft.Office.Interop.Word; namespace WordTestProgram { class Program {
string text=doc.Words[i].text代码>
using System;
using Microsoft.Office.Interop.Word;
namespace WordTestProgram
{
class Program
{
static void Main(string[] args)
{
Application app = new Application();
Document doc = app.Documents.Open("C:\\word.doc");
int count = doc.Words.Count;
for (int i = 0; i <= count; i++)
{
string text = doc.Words[i].Text;
Console.WriteLine("Word {0} = {1}",i,text);
}
app.Quit();
}
}
}
使用系统;
使用Microsoft.Office.Interop.Word;
名称空间WordTestProgram
{
班级计划
{
静态void Main(字符串[]参数)
{
应用程序app=新应用程序();
Document doc=app.Documents.Open(“C:\\word.doc”);
int count=doc.Words.count;
对于(inti=0;i我自己找到了答案
而不是:int i=0;我花了一个小时来做这件事。为什么VSTO从1开始收集?花了这么长时间的是,在调试过程中查找局部变量时,收集显然从[0]开始。哇。