当前位置: 代码迷 >> ASP.NET >> 急ASP.NET循环调用word的替换功能,为什么只有第一次成功?该怎么解决
  详细解决方案

急ASP.NET循环调用word的替换功能,为什么只有第一次成功?该怎么解决

热度:4238   发布时间:2013-02-25 00:00:00.0
急!!!!!ASP.NET循环调用word的替换功能,为什么只有第一次成功??
string temps =@"names,admissDate,thesisType,searchField,supervisor,subDate ,titleThesis,titleEng ,objStudy,absStudy,litReview ,method,analysis,useStudy ,serGrade,applyReason,studentSig,sigDate ,supComm ,supSignature,supSigDate";
  string[] tempValue = temps.Split(',');

  AppSettings math = new AppSettings();
  object missing = System.Reflection.Missing.Value;
  Guid names = Guid.NewGuid();
  Microsoft.Office.Interop.Word.Application WordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
  WordApp.Visible = true;
  object openTemp = @"C:\\TEMP\\OpeningReport.docx"; //本地模板
  object wordName = (math.TempPath + names.ToString());
  Microsoft.Office.Interop.Word.Document WordDoc = WordApp.Documents.Open(ref openTemp, 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); //打开本地模板
  Microsoft.Office.Interop.Word.Window mywindow = WordDoc.ActiveWindow;  
  Microsoft.Office.Interop.Word.Selection mySelection = mywindow.Selection;
  Microsoft.Office.Interop.Word.Find myFind = mySelection.Find;

  Microsoft.Office.Interop.Word.Table tempTable = WordDoc.Tables[1];
  object shuju = "数据";
  if (tempTable.Rows.Count != 0)
  {
//替换内容
  for (int i = 0; i < tempTable.Rows.Count; i++)
  {
  object tempss = "$(" + tempValue[i] + ")";
  myFind.Execute(ref tempss, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref shuju, ref missing, ref missing, ref missing, ref missing, ref missing);
  }

  }
  WordDoc.SaveAs(ref wordName, 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);
  WordDoc.Close(ref missing, ref missing, ref missing);
  WordApp.Quit(ref missing, ref missing, ref missing);

------解决方案--------------------------------------------------------
if (tempTable.Rows.Count != 0)
如果tempTable有数据,条件不是就一直为false呢?

说说什么条件下替换?
if (tempTable.Rows.Count > 0)
------解决方案--------------------------------------------------------
探讨

引用:

if (tempTable.Rows.Count != 0)
如果tempTable有数据,条件不是就一直为false呢?

说说什么条件下替换?
if (tempTable.Rows.Count > 0)

不好意思,我看成==了。
  相关解决方案