예제 #1
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();
        }
        /// <summary>
        /// Gibt ein Liste von ArcheoObjects zurück
        /// </summary>
        /// <returns>Dictionary "string, ArcheoObject"</string></returns>
        public Dictionary <string, ArcheoObject> GetArcheoObjColFromXMLDoc()
        {
            Dictionary <string, ArcheoObject> archeoObjects = new Dictionary <string, ArcheoObject>();

            XmlDocument xmlDoc   = this.ReadXMLDocumentFromFile(new FilePaths().GetXmlDataFilePath());
            XmlNodeList elemList = xmlDoc.DocumentElement.SelectNodes("/ArcheoObjectsList/ArcheoObject");

            foreach (XmlNode node in elemList)
            {
                ArcheoObject archeoObject = new ArcheoObject();
                string[]     PropertyList = archeoObject.GetObjectProperties();
                Dictionary <string, string> keyValuePairs = new Dictionary <string, string>();
                string id = node.SelectSingleNode("Id").InnerText;
                foreach (string property in PropertyList)
                {
                    keyValuePairs.Add(property, node.SelectSingleNode(property).InnerText);
                }
                archeoObject.SetArcheoObject(keyValuePairs);
                archeoObjects.Add(id, archeoObject);
            }
            return(archeoObjects);
        }