private static WListItemElement GetListItemElementFromXMLData(XmlNode ListItemNode)
        {
            if (ListItemNode != null)
            {
                WListItemElement wlie = new WListItemElement();

                if (ListItemNode.Name == WordXMLTags.WordTagName_Paragraph)
                {
                    WParagraph WPrg = WParagraphReader.GetParagraphFromParagraphXMLNode(ListItemNode);
                    wlie.ListItemElement = WPrg;
                    wlie.ListID          = WPrg.ListID;
                    wlie.ListItemLevel   = WPrg.ListItemLevel;
                }
                else if (ListItemNode.Name == WordXMLTags.WTN_Table)
                {
                    WTable LTable = WTableReader.GetTableFromTableXMLData(ListItemNode.OuterXml);
                    wlie.ListItemElement = LTable;
                    wlie.ListItemLevel   = -1;
                    wlie.ListID          = -1;
                }

                return(wlie);
            }
            return(null);
        }
        public static WList[] GetAllLists(Application MWordApp, Document MWordDocument)
        {
            Document DraftDoc = MWordApp.Documents.Add(Visible: false);

            //Document DraftDoc = MWordApp.Documents.Add(null, null, null, false);
            MWordDocument.Select();
            MWordApp.Selection.Copy();
            DraftDoc.Range().Paste();
            DraftDoc.Activate();

            List <WList> AllLists = new List <WList>();

            WCSelection[] ListSelection = GetAllContentSelections(MWordApp, MWordDocument);

            {
                WCSelection[] TableSelections = WTableReader.GetAllContentSelections(MWordApp, MWordDocument);

                ListSelection = WCSelectionOperations.RemoveChilds(ListSelection, TableSelections);
            }

            {
                int _csIndex = 0;
                int _lsCount = ListSelection.Length;

                while (_csIndex < _lsCount)
                {
                    string ListXML = null;
                    try
                    {
                        ListXML = MWordDocument.Range(ListSelection[_csIndex].ContentSelectionStart, ListSelection[_csIndex].ContentSelectionEnd).XML;

                        if (string.IsNullOrEmpty(ListXML) == true)
                        {
                            _csIndex++;
                            continue;
                        }
                    }
                    catch
                    {
                        _csIndex++;
                        continue;
                    }
                    XmlDocument DrftDocFullCntx = new XmlDocument();
                    DrftDocFullCntx.LoadXml(ListXML);

                    WList LContent = GetListFromListXMLData((DrftDocFullCntx.GetElementsByTagName(WordXMLTags.WTN_Body)[0]).ChildNodes[0]);
                    LContent.ContentSelection = ListSelection[_csIndex];
                    AllLists.Add(LContent);
                    _csIndex++;
                }
            }

            MWordDocument.Activate();
            DraftDoc.Close(WdSaveOptions.wdDoNotSaveChanges, WParameters.Missing, WParameters.Missing);

            return(AllLists.ToArray());
        }
Beispiel #3
0
        public static WParagraph[] GetAllParagraphs(Application MWordApp, Document MWordDocument, ILittleLyreLogger Logger)
        {
            List <WParagraph> ListParagraphs = new List <WParagraph>();

            Document DraftDoc = MWordApp.Documents.Add(Visible: false);

            MWordDocument.Select();
            MWordApp.Selection.Copy();
            DraftDoc.Range().Paste();
            DraftDoc.Activate();

            //// Log info
            //AddToLog("Trying to get all paragraphs...");
            //if (MyDraftDoc.Paragraphs.Count < 1)
            //{
            //    AddToLog("No paragraphs found. Going to next step...");
            //}
            //else
            //{
            //    AddToLog("Paragraph count: " + MyDraftDoc.Paragraphs.Count);
            //}
            // Log
            Logger.AddLog(new LogContent()
            {
                LogSubject = "Selection Array", LogMessage = "Getting first level Paragraph selections...", LogSeverity = LoggerParameters.LogSeverity.DEBUG
            });

            WCSelection[] AllPSelecs = GetAllContentSelections(MWordApp, MWordDocument, Logger);

            // Log
            Logger.AddLog(new LogContent()
            {
                LogSubject = "Selection Array", LogMessage = "Getting all first level table selections...", LogSeverity = LoggerParameters.LogSeverity.DEBUG
            });

            WCSelection[] TableWCS = WTableReader.GetAllContentSelections(MWordApp, MWordDocument, Logger);

            // Log
            Logger.AddLog(new LogContent()
            {
                LogSubject = "Selection Array", LogMessage = "Getting all first level list selections...", LogSeverity = LoggerParameters.LogSeverity.DEBUG
            });

            WCSelection[] ListWCS = WListReader.GetAllContentSelections(MWordApp, MWordDocument, Logger);

            // Log
            Logger.AddLog(new LogContent()
            {
                LogSubject = "Selection Array", LogMessage = "Getting all Table Of Content selections...", LogSeverity = LoggerParameters.LogSeverity.DEBUG
            });

            WCSelection[] TOCWCS = WAElement.GetAllContentSelections(MWordApp, MWordDocument, Logger);


            //// Log
            //Logger.AddLog(new LogContent() { LogSubject = "Selection Array", LogMessage = "Getting all Image selections...", LogSeverity = LoggerParameters.LogSeverity.DEBUG });

            //WCSelection[] ImageSelections = WImage.GetAllContentSelections(MWordApp, MWordDocument, Logger);

            // Log
            Logger.AddLog(new LogContent()
            {
                LogSubject = "Arranging Selection", LogMessage = "Comparing to a new arranged array by using table and list content selections...", LogSeverity = LoggerParameters.LogSeverity.DEBUG
            });

            WCSelection[] AllPrgCSelections = WCSelectionOperations.RemoveCompairingParts(AllPSelecs, WCSelectionOperations.CreateNewArrangedSelectionArray(TableWCS, ListWCS));

            // Log
            Logger.AddLog(new LogContent()
            {
                LogSubject = "Arranging Selection", LogMessage = "Comparing with image selection...", LogSeverity = LoggerParameters.LogSeverity.DEBUG
            });

            AllPrgCSelections = WCSelectionOperations.RemoveCompairingParts(AllPrgCSelections, TOCWCS);
            //AllPrgCSelections = WCSelectionOperations.RemoveAdditonalCompairingParts(AllPrgCSelections, TOCWCS, Logger);

            XmlDocument DraftXMLDoc = new XmlDocument();

            for (int psel = 0; psel < AllPrgCSelections.Length; psel++)
            {
                WParagraph wparag = new WParagraph();
                wparag.ContentSelection = AllPrgCSelections[psel];
                try
                {
                    //Range PRange = MWordDocument.Range(AllPrgCSelections[psel].ContentSelectionStart, AllPrgCSelections[psel].ContentSelectionEnd);
                    //string NLocal = PRange.get_Style().NameLocal;

                    string ParagXML = MWordDocument.Range(AllPrgCSelections[psel].ContentSelectionStart, AllPrgCSelections[psel].ContentSelectionEnd).XML;
                    DraftXMLDoc.LoadXml(ParagXML);
                    string tmpBody = DraftXMLDoc.GetElementsByTagName(WordXMLTags.WTN_Body)[0].OuterXml;
                    DraftXMLDoc.RemoveAll();
                    DraftXMLDoc.LoadXml(tmpBody);
                    XmlNode PrgNd = DraftXMLDoc.GetElementsByTagName(WordXMLTags.WordTagName_Paragraph)[0];
                    wparag = GetParagraphFromParagraphXMLNode(PrgNd);
                    wparag.ContentSelection = AllPrgCSelections[psel];
                    ListParagraphs.Add(wparag);
                    DraftXMLDoc.RemoveAll();
                    // Log
                    Logger.AddLog(new LogContent()
                    {
                        LogSubject = "Getting Paragraph", LogMessage = "Paragraph [" + (psel + 1) + "/" + AllPrgCSelections.Length + "] added. Content selection -> [" + AllPrgCSelections[psel].ContentSelectionStart + " : " + AllPrgCSelections[psel].ContentSelectionEnd + "]", LogSeverity = LoggerParameters.LogSeverity.DEBUG
                    });
                }
                catch (Exception Exp)
                {
                    // Log
                    Logger.AddLog(new LogContent()
                    {
                        LogSubject = "Getting Paragraph", LogMessage = "Error occured. Error message -> [" + Exp.Message + "]", LogSeverity = LoggerParameters.LogSeverity.DEBUG
                    });

                    //ListParagraphs.Add(wparag);

                    //// Log
                    //Logger.AddLog(new LogContent() { LogSubject = "Getting Paragraph", LogMessage = "Paragraph [" + (psel + 1) + "/" + "] added. Content selection -> [" + AllPrgCSelections[psel].ContentSelectionStart + " : " + AllPrgCSelections[psel].ContentSelectionEnd + "]", LogSeverity = LoggerParameters.LogSeverity.DEBUG });
                }
            }


            //for (int prg = 1; prg <= DraftDoc.Paragraphs.Count; prg++)
            //{
            //    //MyStringBuilder.Append(MyDraftDoc.Paragraphs[prg].Range.Text + Environment.NewLine);
            //    WCSelection wcs = new WCSelection();
            //    WParagraph wparag = new WParagraph();
            //    WParagraphProperties wparagp = new WParagraphProperties();

            //    //wparag.ParagraphProperties = wparagp;
            //    wcs.ContentID = "Paragraph_" + prg;
            //    wcs.ContentSelectionStart = DraftDoc.Paragraphs[prg].Range.Start;
            //    wcs.ContentSelectionEnd = DraftDoc.Paragraphs[prg].Range.End;

            //    XmlDocument DraftXMLDoc = new XmlDocument();

            //    try
            //    {
            //        {
            //            //if (DraftDoc.Paragraphs[prg].Range.get_Style().NameLocal == DraftDoc.Styles[WdBuiltinStyle.wdStyleHeading1].NameLocal)
            //            //{
            //            //    wparagp.ParagraphStyle = ParagraphStyle.WordHeading1;
            //            //}
            //            //else if (DraftDoc.Paragraphs[prg].Range.get_Style().NameLocal == DraftDoc.Styles[WdBuiltinStyle.wdStyleHeading2].NameLocal)
            //            //{
            //            //    wparagp.ParagraphStyle = ParagraphStyle.WordHeading2;
            //            //}
            //            //else if (DraftDoc.Paragraphs[prg].Range.get_Style().NameLocal == DraftDoc.Styles[WdBuiltinStyle.wdStyleHeading3].NameLocal)
            //            //{
            //            //    wparagp.ParagraphStyle = ParagraphStyle.WordHeading3;
            //            //}
            //            //else if (DraftDoc.Paragraphs[prg].Range.get_Style().NameLocal == DraftDoc.Styles[WdBuiltinStyle.wdStyleHeading4].NameLocal)
            //            //{
            //            //    wparagp.ParagraphStyle = ParagraphStyle.WordHeading4;
            //            //}
            //            //else if (DraftDoc.Paragraphs[prg].Range.get_Style().NameLocal == DraftDoc.Styles[WdBuiltinStyle.wdStyleHeading5].NameLocal)
            //            //{
            //            //    wparagp.ParagraphStyle = ParagraphStyle.WordHeading5;
            //            //}
            //            //else if (DraftDoc.Paragraphs[prg].Range.get_Style().NameLocal == DraftDoc.Styles[WdBuiltinStyle.wdStyleHeading6].NameLocal)
            //            //{
            //            //    wparagp.ParagraphStyle = ParagraphStyle.WordHeading6;
            //            //}
            //            //else if (DraftDoc.Paragraphs[prg].Range.get_Style().NameLocal == DraftDoc.Styles[WdBuiltinStyle.wdStyleHeading7].NameLocal)
            //            //{
            //            //    wparagp.ParagraphStyle = ParagraphStyle.WordHeading7;
            //            //}
            //            //else if (DraftDoc.Paragraphs[prg].Range.get_Style().NameLocal == DraftDoc.Styles[WdBuiltinStyle.wdStyleHeading8].NameLocal)
            //            //{
            //            //    wparagp.ParagraphStyle = ParagraphStyle.WordHeading8;
            //            //}
            //            //else if (DraftDoc.Paragraphs[prg].Range.get_Style().NameLocal == DraftDoc.Styles[WdBuiltinStyle.wdStyleHeading9].NameLocal)
            //            //{
            //            //    wparagp.ParagraphStyle = ParagraphStyle.WordHeading9;
            //            //}
            //            //else if (DraftDoc.Paragraphs[prg].Range.get_Style().NameLocal.ToString().ToLower.Contains("heading"))
            //            //{
            //            //    wparagp.ParagraphStyle = ParagraphStyle.WordHeading9;
            //            //}
            //            //else if (DraftDoc.Paragraphs[prg].Range.get_Style().NameLocal == DraftDoc.Styles[WdBuiltinStyle.wdStyleListParagraph].NameLocal)
            //            //{
            //            //    break;
            //            //}
            //            //else
            //            //{
            //            //    wparagp.ParagraphStyle = ParagraphStyle.WordSimpleParagraph;
            //            //}

            //            //if (DraftDoc.Paragraphs[prg].Alignment == WdParagraphAlignment.wdAlignParagraphCenter)
            //            //{
            //            //    wparagp.Alingment = Alignment.Center;
            //            //}
            //            //else if (DraftDoc.Paragraphs[prg].Alignment == WdParagraphAlignment.wdAlignParagraphLeft)
            //            //{
            //            //    wparagp.Alingment = Alignment.Left;
            //            //}
            //            //else if (DraftDoc.Paragraphs[prg].Alignment == WdParagraphAlignment.wdAlignParagraphRight)
            //            //{
            //            //    wparagp.Alingment = Alignment.Right;
            //            //}
            //            //else
            //            //{
            //            //    wparagp.Alingment = Alignment.Both;
            //            //}
            //        }

            //        string ParagXML = DraftDoc.Paragraphs[prg].Range.XML;
            //        DraftXMLDoc.LoadXml(ParagXML);

            //        XmlNode PrgNd = DraftXMLDoc.GetElementsByTagName(WordXMLTags.WordTagName_Paragraph)[0];
            //        wparag = GetParagraphFromParagraphXMLNode(PrgNd);

            //        wparag.ParagraphProperties.ContentSelection = wcs;

            //        ListParagraphs.Add(wparag);
            //        DraftXMLDoc.RemoveAll();
            //    }
            //    catch
            //    {
            //        wparagp.ContentSelection = wcs;
            //        wparag.ParagraphProperties = wparagp;
            //        ListParagraphs.Add(wparag);
            //        DraftXMLDoc.RemoveAll();
            //    }


            //    //// Log info
            //    //AddToLog("Paragraph [" + prg + "/" + MyDraftDoc.Paragraphs.Count + "] -> Selection[Start, End] = " + "[" + Selcs[0] + ", " + Selcs[1] + "]");
            //}

            MWordDocument.Activate();
            DraftDoc.Close(WdSaveOptions.wdDoNotSaveChanges, WParameters.Missing, WParameters.Missing);
            return(ListParagraphs.ToArray());
        }
        public static WList[] GetAllLists(Application MWordApp, Document MWordDocument, ILittleLyreLogger Logger)
        {
            // Log
            Logger.AddLog(new LogContent()
            {
                LogSubject = "Getting List", LogMessage = "Getting all first level list elements..."
            });

            Document DraftDoc = MWordApp.Documents.Add(Visible: false);

            //Document DraftDoc = MWordApp.Documents.Add(null, null, null, false);
            MWordDocument.Select();
            MWordApp.Selection.Copy();
            DraftDoc.Range().Paste();
            DraftDoc.Activate();

            List <WList> AllLists = new List <WList>();

            WCSelection[] ListSelection = GetAllContentSelections(MWordApp, MWordDocument, Logger);
            // Log
            Logger.AddLog(new LogContent()
            {
                LogSubject = "Getting List", LogMessage = "All list content selections collected.", LogSeverity = LoggerParameters.LogSeverity.DEBUG
            });

            {
                WCSelection[] TableSelections = WTableReader.GetAllContentSelections(MWordApp, MWordDocument, Logger);

                ListSelection = WCSelectionOperations.RemoveChilds(ListSelection, TableSelections, Logger);

                // Log
                Logger.AddLog(new LogContent()
                {
                    LogSubject = "Getting List", LogMessage = "Child elements removed against table selection.", LogSeverity = LoggerParameters.LogSeverity.DEBUG
                });
            }

            // Log
            Logger.AddLog(new LogContent()
            {
                LogSubject = "Getting List", LogMessage = "Getting and arranging all first level list contents ...", LogSeverity = LoggerParameters.LogSeverity.DEBUG
            });
            {
                int _csIndex = 0;
                int _lsCount = ListSelection.Length;

                while (_csIndex < _lsCount)
                {
                    string ListXML = null;
                    try
                    {
                        ListXML = MWordDocument.Range(ListSelection[_csIndex].ContentSelectionStart, ListSelection[_csIndex].ContentSelectionEnd).XML;

                        if (string.IsNullOrEmpty(ListXML) == true)
                        {
                            _csIndex++;
                            continue;
                        }
                    }
                    catch
                    {
                        _csIndex++;
                        continue;
                    }
                    XmlDocument DrftDocFullCntx = new XmlDocument();
                    DrftDocFullCntx.LoadXml(ListXML);

                    WList LContent = GetListFromListXMLData((DrftDocFullCntx.GetElementsByTagName(WordXMLTags.WTN_Body)[0]).ChildNodes[0]);
                    LContent.ContentSelection = ListSelection[_csIndex];
                    AllLists.Add(LContent);
                    _csIndex++;
                }
            }
            // Log
            Logger.AddLog(new LogContent()
            {
                LogSubject = "Getting List", LogMessage = "All list contents collected and arranged.", LogSeverity = LoggerParameters.LogSeverity.DEBUG
            });

            MWordDocument.Activate();
            DraftDoc.Close(WdSaveOptions.wdDoNotSaveChanges, WParameters.Missing, WParameters.Missing);

            return(AllLists.ToArray());
        }