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)
------解决方案--------------------------------------------------------