!!!!强烈建议高手见来看看:.net替换word模板问题:在xp,word2000下运行正常,在win2000server,word2000下就会出错!
string strWordTemplate = Server.MapPath("../test/办文单.doc"); //这里是你的模板文件
Word.Application WordApp = new Word.ApplicationClass(); // 定义一个Word.Application 对象
Word.Document doc = OpenDoc(strWordTemplate,ref WordApp,1); //定义一个Word.Document 对象
try
{
//下面是从数据库取数据,不好意思这个代码有点烂
DataTable TempTable=this.CreateTable("Select * from Workflow_BW where AppID="+Convert.ToInt32(AppID)+" and ContentID="+Convert.ToInt32(ContentID));
if(TempTable.Rows.Count>0)
{
string TempTime=TempTable.Rows[0]["SWTime"].ToString().Trim();
int Pos=TempTime.IndexOf(" ");
string All=TempTime.Substring(0,Pos);
int Pre=All.IndexOf("-");
int Next=All.LastIndexOf("-");
string Year=All.Substring(0,Pre).Trim();
string Month=All.Substring(Pre+1,Next-Pre-1).Trim();
string Day=All.Substring(Next+1,All.Length-Next-1).Trim();
foreach(Word.Bookmark BM in doc.Bookmarks) //这是最关键的地方:对文档的所有书签进行便利匹配
{
switch(BM.Name)
{
case "Advice": //替换Advice书签的内容,其他一样
BM.Select();
BM.Range.Text=this.CreateTable("Select Advice from Workflow_Advice where AppID="+Convert.ToInt32(AppID)+" and ContentID="+Convert.ToInt32(this.ContentID)+" and StepID=1").Rows[0]["Advice"].ToString().Trim();
break;
case "Day":
BM.Select();
BM.Range.Text=Day;
break;
case "LWDW":
BM.Select();
BM.Range.Text=TempTable.Rows[0]["LWDW"].ToString().Trim();
break;
case "LWH":
BM.Select();
BM.Range.Text=TempTable.Rows[0]["SWH"].ToString().Trim();
break;
case "Month":
BM.Select();
BM.Range.Text= Month;
break;
case "NowYear":
BM.Select();
BM.Range.Text=Year;
break;
case "Subject":
BM.Select();
BM.Range.Text=TempTable.Rows[0]["Subject"].ToString().Trim();
break;
case "SWH":
BM.Select();
BM.Range.Text=TempTable.Rows[0]["LSH"].ToString().Trim().Substring(4,TempTable.Rows[0]["LSH"].ToString().Trim().Length-4);
break;
}
}
}
object fn = (object)Server.MapPath("../test/temp.doc");
doc.SaveAs(ref fn, ref missing,ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,ref missing, ref missing); //这里是另存为一个一个文件
Response.Redirect("../test/temp.doc"); //直接打开用ie打开另存的文件,然后可直接调用ie里的打印功能
//doc.SaveAs(ref fn, ref missing,ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,ref missing, ref missing, ref missing,ref missing,ref missing,ref missing,ref missing);
}
catch(Exception err)
{
this.tbXml.Text = err.ToString();
}
finally
{
doc.Close(ref missing,ref missing,ref missing);
WordApp.Quit(ref missing,ref missing,ref missing);
WordApp = null;
}
}
上面代码在xp office2000下正常运行,但在win2000server office2000抱下面错误
消息筛选器显示应用程序正在使用中。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.Runtime.InteropServices.COMException: 消息筛选器显示应用程序正在使用中。
源错误:
行 132: //打开word模板
行 133: string strWordTemplate = Server.MapPath("../test/办文单.doc");
行 134: Word.Application WordApp = new Word.ApplicationClass();
行 135: Word.Document doc = OpenDoc(strWordTemplate,ref WordApp,1);
行 136: try
进程里面的winword.exe2000下杀不掉,真是郁闷
Word.Application WordApp = new Word.ApplicationClass(); // 定义一个Word.Application 对象
Word.Document doc = OpenDoc(strWordTemplate,ref WordApp,1); //定义一个Word.Document 对象
try
{
//下面是从数据库取数据,不好意思这个代码有点烂
DataTable TempTable=this.CreateTable("Select * from Workflow_BW where AppID="+Convert.ToInt32(AppID)+" and ContentID="+Convert.ToInt32(ContentID));
if(TempTable.Rows.Count>0)
{
string TempTime=TempTable.Rows[0]["SWTime"].ToString().Trim();
int Pos=TempTime.IndexOf(" ");
string All=TempTime.Substring(0,Pos);
int Pre=All.IndexOf("-");
int Next=All.LastIndexOf("-");
string Year=All.Substring(0,Pre).Trim();
string Month=All.Substring(Pre+1,Next-Pre-1).Trim();
string Day=All.Substring(Next+1,All.Length-Next-1).Trim();
foreach(Word.Bookmark BM in doc.Bookmarks) //这是最关键的地方:对文档的所有书签进行便利匹配
{
switch(BM.Name)
{
case "Advice": //替换Advice书签的内容,其他一样
BM.Select();
BM.Range.Text=this.CreateTable("Select Advice from Workflow_Advice where AppID="+Convert.ToInt32(AppID)+" and ContentID="+Convert.ToInt32(this.ContentID)+" and StepID=1").Rows[0]["Advice"].ToString().Trim();
break;
case "Day":
BM.Select();
BM.Range.Text=Day;
break;
case "LWDW":
BM.Select();
BM.Range.Text=TempTable.Rows[0]["LWDW"].ToString().Trim();
break;
case "LWH":
BM.Select();
BM.Range.Text=TempTable.Rows[0]["SWH"].ToString().Trim();
break;
case "Month":
BM.Select();
BM.Range.Text= Month;
break;
case "NowYear":
BM.Select();
BM.Range.Text=Year;
break;
case "Subject":
BM.Select();
BM.Range.Text=TempTable.Rows[0]["Subject"].ToString().Trim();
break;
case "SWH":
BM.Select();
BM.Range.Text=TempTable.Rows[0]["LSH"].ToString().Trim().Substring(4,TempTable.Rows[0]["LSH"].ToString().Trim().Length-4);
break;
}
}
}
object fn = (object)Server.MapPath("../test/temp.doc");
doc.SaveAs(ref fn, ref missing,ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,ref missing, ref missing); //这里是另存为一个一个文件
Response.Redirect("../test/temp.doc"); //直接打开用ie打开另存的文件,然后可直接调用ie里的打印功能
//doc.SaveAs(ref fn, ref missing,ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,ref missing, ref missing, ref missing,ref missing,ref missing,ref missing,ref missing);
}
catch(Exception err)
{
this.tbXml.Text = err.ToString();
}
finally
{
doc.Close(ref missing,ref missing,ref missing);
WordApp.Quit(ref missing,ref missing,ref missing);
WordApp = null;
}
}
上面代码在xp office2000下正常运行,但在win2000server office2000抱下面错误
消息筛选器显示应用程序正在使用中。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.Runtime.InteropServices.COMException: 消息筛选器显示应用程序正在使用中。
源错误:
行 132: //打开word模板
行 133: string strWordTemplate = Server.MapPath("../test/办文单.doc");
行 134: Word.Application WordApp = new Word.ApplicationClass();
行 135: Word.Document doc = OpenDoc(strWordTemplate,ref WordApp,1);
行 136: try
进程里面的winword.exe2000下杀不掉,真是郁闷
...全文
相关推荐
win7系统64位安装sql2000方法
win7系统64位安装sql2000方法,介绍的很详细,值得拥有。
在Win7系统上成功安装SQL Server 2000的详细步骤
SQL Server 2000虽为一款较旧的数据库管理系统,但对一些遗留系统而言,它仍扮演着关键的角色。它稳定、可靠,并且拥有丰富的功能,对于那些尚未迁移到新版本数据库系统的Win7环境来说,是一个值得考虑的选择。在开始安装 SQL Server 2000 之前,首先要确保所有前期准备工作已经完成,包括硬件和软件的兼容性检查,以及系统设置的调整。一旦确认无误,可以按照以下步骤启动安装向导:插入 SQL Server 2000 安装介质,或者双击下载的安装文件。
SQL SERVER 2008安装必备工具(Win XP)
SQL SERVER 2008安装必备工具(Win XP)(包括Power Shell等)
WIN7下安装SQL2000 莫太太亲自实践,解决WIN7无法安装sql2000
NULL 博文链接:https://maoxy.iteye.com/blog/783601
在win2000/xp/2003server中自定义纸张打印票据
在win2000/xp/2003server中自定义纸张打印票据


