示例#1
0
        private static void ComputeStatistics()
        {
            int pagecount = 0;
            int wordcount = 0;

            object fileName  = Filename;
            object readOnly  = false;
            object isVisible = false;
            object objDNS    = Word.WdSaveOptions.wdPromptToSaveChanges;
            object missing   = System.Reflection.Missing.Value;

            Word._Application WordApp = new Word.ApplicationClass();

            Word._Document aDoc = null;

            try
            {
                aDoc = WordApp.Documents.Open
                       (
                    ref fileName, ref missing, ref readOnly,
                    ref missing, ref missing, ref missing,
                    ref missing, ref missing, ref missing,
                    ref missing, ref missing, ref isVisible,
                    ref missing, ref missing, ref missing,
                    ref missing
                       );

                Word.WdStatistic pagestat = Word.WdStatistic.wdStatisticPages;
                Word.WdStatistic wordstat = Word.WdStatistic.wdStatisticWords;

                pagecount = aDoc.ComputeStatistics(pagestat, ref missing);
                wordcount = aDoc.ComputeStatistics(wordstat, ref missing);
            }
            catch (Exception ex)
            {
            }
            finally
            {
                if (aDoc != null)
                {
                    aDoc.Close(ref objDNS, ref missing, ref missing);
                    Marshal.ReleaseComObject(aDoc);
                    aDoc = null;
                }
                if (WordApp != null)
                {
                    WordApp.Quit(ref objDNS, ref missing, ref missing);
                    Marshal.ReleaseComObject(WordApp);
                    WordApp = null;
                }
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
            TotalPages = pagecount;
            NoOfWords  = wordcount;
        }
示例#2
0
        public KeyValuePair <int, int> AddBooksToTableTemplate(List <Book> l, string act, string dep)
        {
            l.Sort();
            Word.Table oTable          = this.CreateTemplateTable(act, dep);
            string     currentLanguage = l[0].Language;

            if (currentLanguage == null)
            {
                currentLanguage = "Не заполнено поле язык";
            }

            //oTable.Rows[3].Range.Font.Bold = 0;
            oTable.Cell(3, 1).Merge(oTable.Cell(3, 11));
            oTable.Cell(3, 1).Range.Text = currentLanguage.ToUpper();
            int ID            = 0;
            int CountWriteOff = 0;

            foreach (Book b in l)
            {
                if (currentLanguage != b.Language)
                {
                    oTable.Rows.Add(ref oMissing);
                    oTable.Cell(oTable.Rows.Count - 1, 1).Merge(oTable.Cell(oTable.Rows.Count - 1, 11));
                    currentLanguage = b.Language;
                    if (currentLanguage == null)
                    {
                        currentLanguage = "Не заполнено поле язык";
                    }
                    oTable.Cell(oTable.Rows.Count - 1, 1).Range.Text = currentLanguage.ToUpper();
                }
                ID++;
                CountWriteOff += b.accNums_.Count - b.InvsLeftInFund;
                this.AddBookToTable(oTable, b, ID);
                oTable.Rows.Add(ref oMissing);
            }
            oTable.Cell(oTable.Rows.Count, 1).Merge(oTable.Cell(oTable.Rows.Count, 10));
            oTable.Cell(oTable.Rows.Count, 1).Range.Paragraphs.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;
            oTable.Cell(oTable.Rows.Count, 1).Range.Text = "Итого списано по акту: " + CountWriteOff.ToString() + " инвентарных номера(ов)";
            return(new KeyValuePair <int, int>(CountWriteOff, oDoc.ComputeStatistics(WdStatistic.wdStatisticPages, ref oMissing)));
        }