using System; using System.Collections; using System.IO; using System.Reflection; using Microsoft.Office.Core; using Microsoft.Office.Interop.Word; using TechHeadBrothers.Configuration; namespace THBPublisher { /// <summary> /// Utilities class /// </summary> public class Utilities { private static object oMissing = Missing.Value; /// <summary> /// configure les namespace XML de Word /// </summary> /// <param name="ThisApplication">L'application</param> /// <param name="ThisDocument">Le document</param> public static void configureXMLNamespaces(ref Application ThisApplication, ref Document ThisDocument) { //Effacer tous les namespaces existants foreach (XMLNamespace ns in ThisApplication.XMLNamespaces) { ns.Delete(); } //Normalement on lit dans un fichier de configuration les namespaces //IDictionary settings = ((IDictionary) AssemblySettings.GetConfig("Document")); string alias = "THB Article 3.0"; //(string) settings["schemaalias"]; string asmpath = Assembly.GetCallingAssembly().CodeBase; string pathschema = Path.GetDirectoryName(asmpath) + "\\" + "WordFormat30.xsd"; //(string) settings["schema"]; object t = alias; XMLNamespace xmlnamespace = ThisApplication.XMLNamespaces.Add(pathschema, ref oMissing, ref t, false); object document = ThisDocument; xmlnamespace.AttachToDocument(ref document); } } }