Пример #1
0
        /// <summary>
        /// EXTENSION METHOD
        /// Checks - recursively - if the given table is empty
        /// </summary>
        /// <param name="PobjTable"></param>
        /// <returns></returns>
        public static void DeleteEmpty(this Word.Table PobjTable)
        {
            try
            {
                foreach (Word.Table PobjItem in PobjTable.Tables)
                {
                    PobjItem.DeleteEmpty();
                }
                // figure to toal number of characters in this table if it were empty
                // each blank cell has two (2) characters
                int LintTotal = PobjTable.Range.Cells.Count * 2;
                int LintCount = 0;
                foreach (Word.Cell LobjCell in PobjTable.Range.Cells)
                {
                    LintCount += LobjCell.Range.Text.Length;
                }

                // now we see if it is empty and if it is then we delete it
                if (LintTotal >= LintCount)
                {
                    PobjTable.Delete();
                }
                else
                {
                    PobjTable.DeleteRows();
                }
            }
            catch { }
        }