Открытие документа Word с помощью кода в Visual Studio C#C#

Место общения программистов C#
Ответить
Anonymous
 Открытие документа Word с помощью кода в Visual Studio C#

Сообщение Anonymous »

Я занимаюсь разработкой Office с помощью Visual Studio. И получите сообщение об ошибке ниже

Код: Выделить всё

Error:
**
Unable to cast COM object of type 'Microsoft.Office.Interop.Word.ApplicationClass' to interface type 'Microsoft.Office.Interop.Word._Application'.
This operation failed because the QueryInterface call on the COM component for the interface with IID '{00020970-0000-0000-C000-000000000046}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
**
Код: (также на https://gist.github.com/1056809)

Код: Выделить всё

if (File.Exists((string)strDocPath))
{
Word.Application wdApp = new Word.Application();
wdApp.Visible = true; //Error thrown here

object readOnly = false;
object isVisible = true;
object oMissing = System.Reflection.Missing.Value;

//Open the word document
//Error thrown on line below.
Word.Document aDoc = wdApp.Documents.Open(ref strDocPath, ref oMissing, ref readOnly, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref isVisible,
ref oMissing, ref oMissing, ref oMissing, ref oMissing);

// Activate the document
aDoc.Activate();
}
Что это за ошибка? Как мне этого избежать?

Подробнее здесь: https://stackoverflow.com/questions/653 ... io-c-sharp
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»