private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
this.Application.DocumentOpen +=
new Word.ApplicationEvents4_DocumentOpenEventHandler(WorkWithDocument);
((Word.ApplicationEvents4_Event)this.Application).NewDocument +=
new > Word.ApplicationEvents4_NewDocumentEventHandler(WorkWithDocument);
}
private void WorkWithDocument(Microsoft.Office.Interop.Word.Document Doc)
{
try
{
Word.Range rng = Doc.Range(0, 0);
rng.Text = "New Text";
rng.Select();
}
catch (Exception ex)
{
// Handle exception if for some reason the document is not available.
}
}
Dies ist der vollständige Code. Von dem, was ich verstehe, soll es das Add-In initiieren, überprüfen Sie, ob das Dokument verfügbar ist. Der Teil I Schwierigkeiten Verständnis haben, ist dies:Versuchen, einen bestimmten Teil des Codes von Microsoft-Tutorials in Bezug auf Word-Add-Ins zu verstehen
((Word.ApplicationEvents4_Event)this.Application).NewDocument ...
Was ich nicht verstehe, die (Word.ApplicationEvents4_Event)
ist direkt vor this.Application
. Ist das eine Art von Event-Typus? Ich habe keine Ahnung.
Vielen Dank. – Qya