| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 480 人关注过本帖
标题:webMethod问题[再次求助!]火急
只看楼主 加入收藏
fququ
Rank: 1
等 级:新手上路
威 望:1
帖 子:181
专家分:0
注 册:2004-5-30
收藏
 问题点数:0 回复次数:1 
webMethod问题[再次求助!]火急

[WebMethod]
public bool Write(string args,string sfilename)
{
try
{
Microsoft.Office.Interop.Word.Document wDoc = null;
Microsoft.Office.Interop.Word.Application wApp = null;
Object SaveFileName = sfilename;
CreateWordDocument("c:\\sqsp.doc", ref wDoc, ref wApp);
Object missing = Type.Missing;
string[] bookmarks ={ "age", "agep", "copyno", };
string[] bookmarktexts = args.Split('|');
FillData(bookmarks, bookmarktexts, ref wDoc, ref wApp);
wDoc.SaveAs(ref SaveFileName, 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);
wDoc.Close(ref missing, ref missing, ref missing);
return true;
}
catch
{
return false;
}
}
private string CreateWordDocument(string FileName, ref Microsoft.Office.Interop.Word.Document wDoc, ref Microsoft.Office.Interop.Word.Application WApp)
{
if (FileName == "") return;
Microsoft.Office.Interop.Word.Document thisDocument = null;
Microsoft.Office.Interop.Word.FormFields formFields = null;
Microsoft.Office.Interop.Word.Application thisApplication = new Microsoft.Office.Interop.Word.ApplicationClass();//error
thisApplication.Visible = false;
thisApplication.Caption = "";
thisApplication.Options.CheckSpellingAsYouType = false;
thisApplication.Options.CheckGrammarAsYouType = false;

Object filename = FileName;
Object ConfirmConversions = false;
Object ReadOnly = false ;
Object AddToRecentFiles = false;

Object PasswordDocument = System.Type.Missing;
Object PasswordTemplate = System.Type.Missing;
Object Revert = System.Type.Missing;
Object WritePasswordDocument = System.Type.Missing;
Object WritePasswordTemplate = System.Type.Missing;
Object Format = System.Type.Missing;
Object Encoding = System.Type.Missing;
Object Visible = System.Type.Missing;
Object OpenAndRepair = System.Type.Missing;
Object DocumentDirection = System.Type.Missing;
Object NoEncodingDialog = System.Type.Missing;
Object XMLTransform = System.Type.Missing;

try
{
Microsoft.Office.Interop.Word.Document wordDoc =
thisApplication.Documents.Open(ref filename, ref ConfirmConversions,
ref ReadOnly, ref AddToRecentFiles, ref PasswordDocument, ref PasswordTemplate,
ref Revert, ref WritePasswordDocument, ref WritePasswordTemplate, ref Format,
ref Encoding, ref Visible, ref OpenAndRepair, ref DocumentDirection,
ref NoEncodingDialog, ref XMLTransform);

thisDocument = wordDoc;
wDoc = wordDoc;
WApp = thisApplication;
formFields = wordDoc.FormFields;
return "true";
}
catch (Exception ex)
{
//MessageBox.Show(ex.Message);
return ex.ToString();
}

}
private void FillData(string[] BookMark, string[] Text, ref Microsoft.Office.Interop.Word.Document wDoct, ref Microsoft.Office.Interop.Word.Application wAppt)
{
for (int i = 0; i < BookMark.Length; i++)
{
if (wAppt.ActiveDocument.Bookmarks.Exists(BookMark[i]))
{
Object titleNo = BookMark[i];
wAppt.ActiveDocument.Bookmarks.get_Item(ref titleNo).Select();
wAppt.Selection.TypeText(Text[i]);
}
}
}

以上webMethod如果测试一下是没有问题的,能够正常运行.可是如果我在另网站项目中本地引用它.就会在"红色字休"处报错!!why???为什么不能webservices自身运行ok,而调用却会报错误呢??

[此贴子已经被作者于2006-7-10 17:18:23编辑过]

搜索更多相关主题的帖子: webMethod 火急 
2006-07-10 17:16
fququ
Rank: 1
等 级:新手上路
威 望:1
帖 子:181
专家分:0
注 册:2004-5-30
收藏
得分:0 
up

2006-07-11 08:43
快速回复:webMethod问题[再次求助!]火急
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011225 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved