/// <summary>
        /// Baut aus der Liste von ArcheoObjecten ein XmlDocument
        /// </summary>
        /// <param name="archObj"></param>
        /// <returns>gibt das XmlDocument zurück</returns>
        public XmlDocument GenerateXMLDocumentFromArcheoObjectList(Dictionary <string, ArcheoObject> archObjCol)
        {
            XmlDocument xmlDoc   = new XmlDocument();
            XmlNode     rootNode = xmlDoc.CreateElement("ArcheoObjectsList");

            foreach (KeyValuePair <string, ArcheoObject> archObject in archObjCol)
            {
                XmlNode      archeoNode    = xmlDoc.CreateElement("ArcheoObject");
                XmlAttribute codeAttribute = xmlDoc.CreateAttribute("code");
                codeAttribute.InnerText = archObject.Key;
                archeoNode.Attributes.Append(codeAttribute);
                ArcheoObject archeoObject = archObject.Value;
                Dictionary <string, string> PropertyList = archeoObject.GetArcheoObjectAsDictonary();

                foreach (KeyValuePair <string, string> item in PropertyList)
                {
                    XmlNode node = xmlDoc.CreateElement(item.Key);
                    node.InnerText = item.Value;
                    archeoNode.AppendChild(node);
                }

                rootNode.AppendChild(archeoNode);
            }
            xmlDoc.AppendChild(rootNode);
            return(xmlDoc);
        }
Ejemplo n.º 2
0
        public void ExportToWord(ArcheoObject archeoObject, string FullDirectory)
        {
            object      documentTyp      = 0;
            object      visible          = true;
            object      fileName         = FullDirectory + archeoObject.CodeOut + ".docx";
            string      fullTemplateName = new FilePaths().GetTemplatePath();
            object      templateName     = fullTemplateName;
            object      missing          = System.Reflection.Missing.Value;
            Application oWordApp         = new Application();

            oWordApp.Visible = true;
            Document oWordDoc = oWordApp.Documents.Add(ref templateName, missing, documentTyp, visible);

            oWordDoc.Activate();

            int  test  = oWordDoc.Bookmarks.Count;
            bool test1 = oWordDoc.Bookmarks.Exists("Code");

            string[] textmarkes           = archeoObject.GetObjectProperties();
            string[] archeoObjectAsString = archeoObject.GetArcheoObject(true);
            Dictionary <string, string> archeoObjectAsDict = archeoObject.GetArcheoObjectAsDictonary();
            object textmarke = new object();
            int    i         = 0;

            foreach (string property in textmarkes)
            {
                textmarke = property;
                bool archeoObjectParam = archeoObjectAsDict.TryGetValue(property, out string value);
                bool textMarkeExists   = oWordDoc.Bookmarks.Exists(property);
                if (archeoObjectParam && textMarkeExists)
                {
                    oWordDoc.Bookmarks.get_Item(ref textmarke).Range.Text = value;
                }
                i++;
            }

            //Einfügen Bild
            Range aRange = oWordDoc.Range(Start: oWordDoc.Paragraphs[12].Range.Start, oWordDoc.Paragraphs[12].Range.End);

            oWordDoc.InlineShapes.AddPicture(archeoObject.PictureLinkOut, false, true, aRange);

            oWordDoc.SaveAs2(fileName);
            oWordDoc.Close();
            oWordApp.Quit();
        }