예제 #1
0
        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());
        }
예제 #2
0
        public static WCSelection[] GetAllContentSelections(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 <WCSelection> ListSelection = new List <WCSelection>();

            for (int wlist = 1; wlist <= DraftDoc.Lists.Count; wlist++)
            {
                List dlist = DraftDoc.Lists[wlist];
                dlist.Range.Select();
                WCSelection wcs = new WCSelection()
                {
                    ContentSelectionStart = MWordApp.Selection.Start,
                    ContentSelectionEnd   = MWordApp.Selection.End
                };
                ListSelection.Add(wcs);
            }


            ListSelection = new List <WCSelection>(WCSelectionOperations.RemoveChilds(ListSelection.ToArray()));

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

            //    ListSelection = new List<WCSelection>(WCSelectionOperations.RemoveChilds(ListSelection.ToArray(), TableSelections, Logger));

            //}

            {
                for (int ls = 0; ls < ListSelection.Count; ls++)
                {
                    ListSelection[ls].ContentID = "WList_" + (ls + 1);
                }
            }

            MWordDocument.Activate();
            DraftDoc.Close(WdSaveOptions.wdDoNotSaveChanges, WParameters.Missing, WParameters.Missing);
            return(ListSelection.ToArray());
        }
        public static WCSelection[] GetAllContentSelections(Application MWordApp, Document MWordDocument)
        {
            try
            {
                Document DraftDoc = MWordApp.Documents.Add(Visible: false);
                MWordDocument.Select();
                MWordApp.Selection.Copy();
                DraftDoc.Range().Paste();
                DraftDoc.Activate();

                List <WCSelection> ParagWCS = new List <WCSelection>();


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

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

                    ParagWCS.Add(wcs);
                }


                WCSelection[] NParagWCS = WCSelectionOperations.RemoveChilds(ParagWCS.ToArray());

                for (int pindx = 0; pindx < NParagWCS.Length; pindx++)
                {
                    NParagWCS[pindx].ContentID = "WParagraph_" + (pindx + 1);
                }

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

                return(NParagWCS);
            }
            catch (Exception Exp)
            {
                return(null);
            }
        }
        public static WCSelection[] GetAllContentSelections(Application MWordApp, Document MWordDocument, ILittleLyreLogger Logger)
        {
            Document DraftDoc = MWordApp.Documents.Add(Visible: false);

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

            List <WCSelection> TableSelections = new List <WCSelection>();

            for (int tbli = 1; tbli <= DraftDoc.Tables.Count; tbli++)
            {
                //// Log info
                //AddToLog("Working on table: " + tbli);
                Table CurTable = DraftDoc.Tables[tbli];

                //string TableXML = CurTable.Range.XML;

                //// Log info
                //AddToLog("Getting table content. Row count: " + CurTable.Rows.Count + "; Column count: " + CurTable.Columns.Count);

                //WTable wtbl = GetTableFromTableXMLData(TableXML);

                //for (int trow = 1; trow <= CurTable.Rows.Count; trow++)
                //{

                //    string[] TRow = new string[CurTable.Columns.Count];
                //    for(int tcol = 1; tcol <= CurTable.Columns.Count; tcol++)
                //    {

                //        try
                //        {

                //            TRow[tcol - 1] = CurTable.Cell(trow, tcol).Range.Text;
                //        }
                //        catch
                //        {
                //            TRow[tcol - 1] = string.Empty;
                //        }
                //    }
                //    TList_Tables.Add(TRow);
                //}

                //// Log info
                //AddToLog("All content collected...");

                CurTable.Select();

                WCSelection wcs = new WCSelection()
                {
                    ContentSelectionStart = MWordApp.Selection.Start,
                    ContentSelectionEnd   = MWordApp.Selection.End
                };

                TableSelections.Add(wcs);

                //// Log info
                //AddToLog("Table was added as selection. Selection[Start, End] = [" + cs.RStart + ", " + cs.REnd + "]");
            }

            TableSelections = new List <WCSelection>(WCSelectionOperations.RemoveChilds(TableSelections.ToArray()));

            //{
            //    WCSelection[] ListSelections = WListReader.GetAllContentSelections(MWordApp, MWordDocument, Logger);

            //    TableSelections = new List<WCSelection>(WCSelectionOperations.RemoveChilds(TableSelections.ToArray(), ListSelections, Logger));

            //}

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

            {
                for (int ls = 0; ls < TableSelections.Count; ls++)
                {
                    TableSelections[ls].ContentID = "WTable_" + (ls + 1);
                }
            }

            return(TableSelections.ToArray());
        }
        public static WTable[] GetAllTables(Application MWordApp, Document MWordDocument, ILittleLyreLogger Logger)
        {
            Document DraftDoc = MWordApp.Documents.Add();

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

            List <WTable> TList = new List <WTable>();

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

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

                TSelection = WCSelectionOperations.RemoveChilds(TSelection, ListSelections, Logger);
            }


            for (int tbls = 0; tbls < TSelection.Length; tbls++)
            {
                //// Log info
                //AddToLog("Working on table: " + tbli);

                //// Log info
                //AddToLog("Getting table content. Row count: " + CurTable.Rows.Count + "; Column count: " + CurTable.Columns.Count);

                string TableXML = MWordDocument.Range(TSelection[tbls].ContentSelectionStart, TSelection[tbls].ContentSelectionEnd).XML;

                WTable wtbl = GetTableFromTableXMLData(TableXML);

                //for (int trow = 1; trow <= CurTable.Rows.Count; trow++)
                //{

                //    string[] TRow = new string[CurTable.Columns.Count];
                //    for(int tcol = 1; tcol <= CurTable.Columns.Count; tcol++)
                //    {

                //        try
                //        {

                //            TRow[tcol - 1] = CurTable.Cell(trow, tcol).Range.Text;
                //        }
                //        catch
                //        {
                //            TRow[tcol - 1] = string.Empty;
                //        }
                //    }
                //    TList_Tables.Add(TRow);
                //}

                //// Log info

                wtbl.ContentSelection = TSelection[tbls];

                TList.Add(wtbl);

                //// Log info
                //AddToLog("Table was added as selection. Selection[Start, End] = [" + cs.RStart + ", " + cs.REnd + "]");
            }

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

            return(TList.ToArray());
        }
예제 #6
0
        public static WCSelection[] GetAllContentSelections(Application MWordApp, Document MWordDocument, ILittleLyreLogger Logger)
        {
            try
            {
                // Log
                Logger.AddLog(new LogContent()
                {
                    LogSubject = "Getting Elements", LogMessage = "Trying to get all paragraphs."
                });

                // Log
                Logger.AddLog(new LogContent()
                {
                    LogSubject = "Creating Document", LogMessage = "Trying to create draft document...", LogSeverity = LoggerParameters.LogSeverity.DEBUG
                });

                Document DraftDoc = MWordApp.Documents.Add(Visible: false);
                MWordDocument.Select();
                MWordApp.Selection.Copy();
                DraftDoc.Range().Paste();
                DraftDoc.Activate();

                // Log
                Logger.AddLog(new LogContent()
                {
                    LogSubject = "Creating Document", LogMessage = "Draft document created.", LogSeverity = LoggerParameters.LogSeverity.DEBUG
                });

                List <WCSelection> ParagWCS = new List <WCSelection>();

                // Log
                Logger.AddLog(new LogContent()
                {
                    LogSubject = "Getting Selection", LogMessage = "Trying to get all first level paragraph content selections"
                });

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

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

                    // Log
                    Logger.AddLog(new LogContent()
                    {
                        LogSubject = "Getting Selection", LogMessage = "Paragraph [" + prg + "/" + DraftDoc.Paragraphs.Count + "] added. Content selection -> [" + wcs.ContentSelectionStart + " : " + wcs.ContentSelectionEnd + "]", LogSeverity = LoggerParameters.LogSeverity.DEBUG
                    });

                    ParagWCS.Add(wcs);
                }

                // Log
                Logger.AddLog(new LogContent()
                {
                    LogSubject = "Getting Selection", LogMessage = "All paragraph content selection collected."
                });
                //Thread.Sleep(500);

                WCSelection[] NParagWCS = WCSelectionOperations.RemoveChilds(ParagWCS.ToArray());

                for (int pindx = 0; pindx < NParagWCS.Length; pindx++)
                {
                    NParagWCS[pindx].ContentID = "WParagraph_" + (pindx + 1);
                }

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

                return(NParagWCS);
            }
            catch (Exception Exp)
            {
                // Log
                Logger.AddLog(new LogContent()
                {
                    LogSubject = "Getting Selection", LogMessage = "Error occured. Message -> " + Exp.Message
                });
                return(null);
            }
        }
예제 #7
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());
        }
        public static WCSelection[] GetAllContentSelections(Application MWordApp, Document MWordDocument, ILittleLyreLogger Logger)
        {
            // Log
            Logger.AddLog(new LogContent()
            {
                LogSubject = "Getting Selection", LogMessage = "Trying to get all list content selections..."
            });
            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 <WCSelection> ListSelection = new List <WCSelection>();

            for (int wlist = 1; wlist <= DraftDoc.Lists.Count; wlist++)
            {
                List dlist = DraftDoc.Lists[wlist];
                dlist.Range.Select();
                WCSelection wcs = new WCSelection()
                {
                    ContentSelectionStart = MWordApp.Selection.Start,
                    ContentSelectionEnd   = MWordApp.Selection.End
                };
                ListSelection.Add(wcs);

                // Log
                Logger.AddLog(new LogContent()
                {
                    LogSubject = "Getting Selection", LogMessage = "List [" + wlist + "/" + DraftDoc.Lists.Count + "] added. Content selection [start : end] = [" + wcs.ContentSelectionStart + " : " + wcs.ContentSelectionEnd + "]", LogSeverity = LoggerParameters.LogSeverity.DEBUG
                });

                //// Log info
                //AddToLog("List [" + wlist + "/" + MyDraftDoc.Lists.Count + "] has been added as selection. Selection[Start, End] = [" + cs.RStart + ", " + cs.REnd + "]");
            }


            ListSelection = new List <WCSelection>(WCSelectionOperations.RemoveChilds(ListSelection.ToArray()));
            // Log
            Logger.AddLog(new LogContent()
            {
                LogSubject = "Getting Selection", LogMessage = "Child content selections removed.", LogSeverity = LoggerParameters.LogSeverity.DEBUG
            });

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

            //    ListSelection = new List<WCSelection>(WCSelectionOperations.RemoveChilds(ListSelection.ToArray(), TableSelections, Logger));

            //}

            {
                for (int ls = 0; ls < ListSelection.Count; ls++)
                {
                    ListSelection[ls].ContentID = "WList_" + (ls + 1);
                }
            }

            MWordDocument.Activate();
            DraftDoc.Close(WdSaveOptions.wdDoNotSaveChanges, WParameters.Missing, WParameters.Missing);
            return(ListSelection.ToArray());
        }