我有一個預先製作的具有表格的Word模板。我想打開它,然後在文檔的末尾添加(粘貼)另一個表格。問題是它不會到達文檔的末尾,而是將新表粘貼到原始表的第一個單元格中。任何幫助將不勝感激。如何將表格粘貼到使用C#的Ms-Word文檔的末尾
//previous code copied a table from another document
Object oTempPath = "C:\\Temp\\Logtemp.doc";
Object defaultTemplate = "C:\\Temp\\LogContemp.doc";
oDoc = oWord.Documents.Open(ref defaultTemplate,
ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing);
object start = oDoc.Content.Start;
object end = oDoc.Content.End;
oDoc.Range(ref start, ref end).Copy();
oDoc.Close(ref oMissed, ref oMissed, ref oMissed);
oDoc = oWord.Documents.Open(ref oTempPath,
ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing);
oDoc.Activate();
//**** This is where the issue starts ****
start = oWord.Selection.End;
end = oWord.Selection.End;
Word.Range rng = oDoc.Range(ref start, ref end);
rng.Select();
rng.Paste();
object fileN1 = "C:\\temp\\" + TextBox1.Text + " Log.doc";
oDoc.Fields.Update();
oDoc.SaveAs(ref fileN1,
ref oMissed, ref oMissed, ref oMissed, ref oMissed, ref oMissed,
ref oMissed, ref oMissed, ref oMissed, ref oMissed, ref oMissed,
ref oMissed, ref oMissed, ref oMissed, ref oMissed, ref oMissed);
oDoc.Close(ref oMissed, ref oMissed, ref oMissed);
oWord.Quit(ref oMissing, ref oMissing, ref oMissing);
你既嘗試開始和結束= oDoc.Content.End? – Fosco 2011-05-30 01:51:39
嘗試過,但獲得超出範圍的錯誤。 – user770344 2011-05-30 02:02:41