コード例 #1
0
        public static WList GetListFromWordElements(IWBaseElement[] ListElements)
        {
            if (ListElements == null)
            {
                return(null);
            }

            WListItemElement[] WLIElems = new WListItemElement[ListElements.Length];

            for (int pi = 0; pi < ListElements.Length; pi++)
            {
                WLIElems[pi] = new WListItemElement();
                if (ListElements[pi].GetType() == typeof(WParagraph))
                {
                    WLIElems[pi].ListItemElement = ListElements[pi] as WParagraph;
                    WLIElems[pi].ListID          = (ListElements[pi] as WParagraph).ListID;
                    WLIElems[pi].ListItemLevel   = (ListElements[pi] as WParagraph).ListItemLevel;
                }
                else if (ListElements[pi].GetType() == typeof(WTable))
                {
                    WLIElems[pi].ListItemElement = ListElements[pi] as WTable;
                    WLIElems[pi].ListID          = -1;
                    WLIElems[pi].ListItemLevel   = -1;
                }
            }

            WList out_Rslt = new WList();

            PrepareListRecursively(out_Rslt, WLIElems);
            return(out_Rslt);
        }
コード例 #2
0
        protected static int PrepareListRecursively(WList out_WList, WListItemElement[] ListItemElements)
        {
            if (ListItemElements == null)
            {
                return(0);
            }


            if (ListItemElements.Length < 1)
            {
                return(0);
            }

            //WList out_WList = new WList();
            int Level   = ListItemElements[0].ListItemLevel;
            int LIIndex = 0;

            while (LIIndex < ListItemElements.Length)
            {
                WListItem wli = new WListItem();

                if (ListItemElements[LIIndex].ListItemLevel > Level)
                {
                    WListItemElement[] nplist = new WListItemElement[ListItemElements.Length - LIIndex];

                    Array.Copy(ListItemElements, LIIndex, nplist, 0, nplist.Length);
                    WList tmpCWList = new WList();
                    LIIndex += PrepareListRecursively(tmpCWList, nplist);

                    out_WList.ListItems[out_WList.ListItems.Count - 1].ChildList = tmpCWList;

                    continue;
                }
                else if (ListItemElements[LIIndex].ListItemLevel < Level)
                {
                    if (ListItemElements[LIIndex].ListItemLevel < 0)
                    {
                        out_WList.ListItems[out_WList.ListItems.Count - 1].ItemElements.Add(ListItemElements[LIIndex]);
                        LIIndex++;
                        continue;
                    }
                    else
                    {
                        return(LIIndex);
                    }
                }
                else
                {
                    wli.ListID        = ListItemElements[LIIndex].ListID;
                    wli.ListItemLevel = ListItemElements[LIIndex].ListItemLevel;
                    wli.ItemElements.Add(ListItemElements[LIIndex]);
                }

                out_WList.ListItems.Add(wli);
                LIIndex++;
            }

            return(LIIndex);
        }
コード例 #3
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());
        }
コード例 #4
0
        public static WList GetListFromListXMLData(XmlNode in_XMLNode)
        {
            //XmlNodeList Prgs = GetAllNodes(XMLContent);
            List <WListItemElement> PListItems = new List <WListItemElement>();

            foreach (XmlNode P in in_XMLNode.ChildNodes)
            {
                WListItemElement tmpWLIElem = GetListItemElementFromXMLData(P);
                if (tmpWLIElem.ListItemElement != null)
                {
                    PListItems.Add(tmpWLIElem);
                }
            }
            WList out_Rslt = new WList();

            PrepareListRecursively(out_Rslt, PListItems.ToArray());
            return(out_Rslt);
        }
コード例 #5
0
        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());
        }