Readdy Write  
0,00 €
Your View Money
Views: Count
Self 20% 0
Your Content 60% 0

Users by Links 0
u1*(Content+Views) 10% 0
Follow-Follower 0
s2*(Income) 5% 0

Count
Followers 0
Login Register as User

Code: Word Vorlage in VSTO Addin aus einem neuen Dokument ermitteln

13.11.2018 (👁9398)

Word Vorlage in VSTO Addin

Wie kann man die Vorlage eines Word-Dokuments ermitteln, wenn man in Visual Studio ein C# Code in debug startet

Lösung:

Man kann das zugeordnete Template nur durch .get_AttachedTemplate(); ermitteln.

Leider kann man bei gestartetem Debug nur von der Word-Anwendung heraus dokumente öffnen und Vorlagen aus dem Internet öffnen.

Ein neues Dokument1 aus einer eigenen Vorlage heraus konnte ich nicht öffnen.

Deshalb hier der Code, welcher dennoch funktionierte.

Lösung Code

Eigentliche Vorlage eines neuen Dokuments in Word ermitteln

C#, intercom addin

var varTemplate = Globals.ThisAddIn.Application.ActiveDocument.get_AttachedTemplate();

            if (varTemplate != null)

            {

                Word.Template template = (Word.Template)varTemplate;

                sWordPath =template.Path;

            }

string sFilename = Settings1.Default.Excel_Filename;

if (sFilename.IndexOf(":") < 0)

{

    string sWordPath = Globals.ThisAddIn.Application.ActiveDocument.Path;

    if(sWordPath=="")

    {

        try

        {

            var varTemplate = Globals.ThisAddIn.Application.ActiveDocument.get_AttachedTemplate();

            if (varTemplate != null)

            {

                Word.Template template = (Word.Template)varTemplate;

                sWordPath =template.Path;

            }

        }

        catch (Exception )

        {

 

            throw;

        }

        

    }

    sFilename = sWordPath + "\\" + sFilename;

}