我使用的互操作庫Word和我得到一個COM異常:收到COMException發生:錯誤碼= -2146824070
消息: 「類型不匹配」 錯誤碼:-2146824070 來源: 「Microsoft Word中」
引發錯誤的方法是:
object docStart = doc.Content.End - 1;
object docEnd = doc.Content.End;
object start = subDoc.Content.Start;
object end = subDoc.Content.End;
Word.Range rng = doc.Range(ref docStart, ref docEnd);
rng.FormattedText = subDoc.Range(ref start, ref end);
(。當它試圖設置FormattedText屬性錯誤被拋出)
當地人調試時有:
docStart: 0
docEnd: 1
start: 0
end: 10
我不確定我的問題在這裏。有任何想法嗎?謝謝!
需要成爲'rng.FormattedText = subDoc.Range(ref start,ref end).FormattedText;'您不能將FormattedText設置爲範圍對象... – Ben 2012-01-30 17:58:14
來自同一個實例的'doc'和'subDoc'字?您不能將Word的一個實例的FormattedText分配給另一個實例,它們必須位於同一個實例中(即相同的「應用程序」)。 – Ben 2012-01-31 15:25:52
我打開他們都使用相同的應用程序。我發佈的方法是在爲每個文檔調用的類中。 – 2012-01-31 16:07:42