求救。。关于读取WORD问题
代码
public string ReadAllFromWord()
{
Word.ApplicationClass app = null;
Word.Document doc = null;
object missing = System.Reflection.Missing.Value;
object FileName = @"c:\test.doc";
object readOnly = false;
object isVisible = false;
try
{
app = new Word.ApplicationClass();
doc = app.Documents.Open(ref FileName, ref missing, ref readOnly,
ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref isVisible, ref missing,
ref missing, ref missing, ref missing);
string textString = "";
//读取全部内容
textString = doc.Content.Text.Trim();
// int ParCount = this.getParCount(doc);//段数
// for (int i = 1 ; i <= ParCount ; i++)
// {
// textString = textString + doc.Paragraphs[i].Range.Text.Trim();//doc.Content.Text.Trim();//
// }
textString = textString.Replace("\a",""); //替换空串为空。(word中\a代表空串,但在C#中,代表响铃 晕~~)否则显示控制台程序时会响
textString = textString.Replace("\r","\n"); //替换回车为回车换行
return textString;
}
catch(Exception ex)
{
//Response.Write(ex.Source);
throw ex;
}
finally
{
if (doc != null)
{
try
{
doc.Close(ref missing, ref missing, ref missing);
}
catch
{}
doc = null;
}
if (app != null)
{
try
{
app.Quit(ref missing, ref missing, ref missing);
}
catch
{}
app = null;
}
GC.Collect();
GC.WaitForPendingFinalizers();
}
我放到服务器上导出数据。说无法打开宏储存。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.Runtime.InteropServices.COMException: 无法打开宏储存。
源错误:
然后我看到有人说是DCOM里配置的WORD属性,安全权限问题。我该添的都添了。然后选择了标示 交互式然后出现
为配置类型不正确,系统无法开始服务器进程。请检查用户名和密码。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.Runtime.InteropServices.COMException: 因为配置类型不正确,系统无法开始服务器进程。请检查用户名和密码。
头都大了。。。。。。请问大侠怎么样才不能出问题啊5555