Example #1
0
        public void CreateNewDoc(String path, AppVisibility visibility)
        {
            //создаем обьект приложения word
            _application = new Word.Application();
            // создаем путь к файлу
            Object templatePathObj = path;

            // если вылетим на этом этапе, приложение останется открытым
            try
            {
                _document = _application.Documents.Add(ref templatePathObj, ref _missingObj, ref _missingObj, ref _missingObj);
            }
            catch (Exception error)
            {
                _document.Close(ref _falseObj, ref _missingObj, ref _missingObj);
                _application.Quit(ref _missingObj, ref _missingObj, ref _missingObj);
                _document    = null;
                _application = null;
                throw error;
            }
            if (visibility == AppVisibility.Visible)
            {
                // делаем word видимым
                _application.Visible = true;
            }
            else
            {
                _application.Visible = false;
            }
        }
Example #2
0
        /// <summary>
        /// Create a new document with or without the template.
        /// </summary>
        /// <param name="templateLocation">The document template location.</param>
        protected void CreateDocument(string templateLocation = "")
        {
            _templateLocation = templateLocation;

            // Create the new word instance.
            _application         = new Word.Application();
            _application.Visible = _isVisible;

            // Create a new document with or without the template
            if (String.IsNullOrEmpty(templateLocation))
            {
                _document = _application.Documents.Add(
                    ref _refMissing,
                    ref _refMissing,
                    ref _refMissing,
                    ref _refMissing);
            }
            else
            {
                _document = _application.Documents.Add(
                    ref _templateLocation,
                    ref _refMissing,
                    ref _refMissing,
                    ref _refMissing);
            }
        }
Example #3
0
 public void Dispose()
 {
     _document.Close(ref _falseObj, ref _missingObj, ref _missingObj);
     _application.Quit(ref _missingObj, ref _missingObj, ref _missingObj);
     _document    = null;
     _application = null;
 }
        /// <summary>
        /// 预览Word
        /// </summary>
        public string PreviewWord(string physicalPath, string url, string findIndex)
        {
            Microsoft.Office.Interop.Word._Application application = null;
            Microsoft.Office.Interop.Word._Document    doc         = null;
            application = new Microsoft.Office.Interop.Word.Application();
            object missing    = Type.Missing;
            object trueObject = true;

            application.Visible       = false;
            application.DisplayAlerts = WdAlertLevel.wdAlertsNone;
            doc = application.Documents.Open(physicalPath, missing, trueObject, missing, missing, missing,
                                             missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
            //Save Excelto Html
            object format     = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatHTML;
            string htmlName   = Path.GetFileNameWithoutExtension(physicalPath) + ".html";
            String outputFile = Path.GetDirectoryName(physicalPath) + "\\" + htmlName;
            string temp       = outputFile.Substring(0, outputFile.IndexOf(findIndex));

            temp       = temp + findIndex + "\\DKLManager\\ReadFiles" + outputFile.Substring(outputFile.LastIndexOf("\\"), outputFile.Length - outputFile.LastIndexOf("\\"));
            outputFile = temp;
            string strPath = Path.GetDirectoryName(outputFile);         //如果文件夹路径不存在就创建

            if (!Directory.Exists(strPath))
            {
                Directory.CreateDirectory(strPath);
            }
            doc.SaveAs(outputFile, format, missing, missing, missing,
                       missing, XlSaveAsAccessMode.xlNoChange, missing,
                       missing, missing, missing, missing);
            doc.Close();
            application.Quit();
            return(Path.GetDirectoryName(Server.UrlDecode(url)) + "\\" + htmlName);
        }
Example #5
0
        /// <summary>
        /// 读取Word表格中某个单元格的数据。其中的参数分别为文件名(包括路径),行号,列号。
        /// </summary>
        /// <param name="fileName">word文档</param>
        /// <param name="rowIndex">行</param>
        /// <param name="colIndex">列</param>
        /// <returns>返回数据</returns>
        public static string ReadWord_tableContentByCell(string fileName, int rowIndex, int colIndex)
        {
            Microsoft.Office.Interop.Word._Application cls   = null;
            Microsoft.Office.Interop.Word._Document    doc   = null;
            Microsoft.Office.Interop.Word.Table        table = null;
            object missing = System.Reflection.Missing.Value;
            object path    = fileName;

            cls = new Application();
            try
            {
                doc = cls.Documents.Open
                          (ref path, ref missing, ref missing, ref missing,
                          ref missing, ref missing, ref missing, ref missing,
                          ref missing, ref missing, ref missing, ref missing,
                          ref missing, ref missing, ref missing, ref missing);
                table = doc.Tables[1];
                string text = table.Cell(rowIndex, colIndex).Range.Text.ToString();
                text = text.Substring(0, text.Length - 2);   //去除尾部的mark
                return(text);
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
            finally
            {
                if (doc != null)
                {
                    doc.Close(ref missing, ref missing, ref missing);
                }
                cls.Quit(ref missing, ref missing, ref missing);
            }
        }
Example #6
0
        /// <summary>
        /// 修改word表格中指定单元格的数据
        /// </summary>
        /// <param name="fileName">word文档包括路径</param>
        /// <param name="rowIndex">行</param>
        /// <param name="colIndex">列</param>
        /// <param name="content"></param>
        /// <returns></returns>
        public static bool UpdateWordTableByCell(string fileName, int rowIndex, int colIndex, string content)
        {
            Microsoft.Office.Interop.Word._Application cls   = null;
            Microsoft.Office.Interop.Word._Document    doc   = null;
            Microsoft.Office.Interop.Word.Table        table = null;
            object missing = System.Reflection.Missing.Value;
            object path    = fileName;

            cls = new Application();
            try
            {
                doc = cls.Documents.Open
                          (ref path, ref missing, ref missing, ref missing,
                          ref missing, ref missing, ref missing, ref missing,
                          ref missing, ref missing, ref missing, ref missing,
                          ref missing, ref missing, ref missing, ref missing);

                table = doc.Tables[1];
                //doc.Range( ref 0, ref 0 ).InsertParagraphAfter();//插入回车
                table.Cell(rowIndex, colIndex).Range.InsertParagraphAfter();//.Text = content;
                return(true);
            }
            catch
            {
                return(false);
            }
            finally
            {
                if (doc != null)
                {
                    doc.Close(ref missing, ref missing, ref missing);
                    cls.Quit(ref missing, ref missing, ref missing);
                }
            }
        }
Example #7
0
        // TODO:
        private void ButtonParse_Click(object sender, EventArgs e)
        {
            object oMissing = System.Reflection.Missing.Value;

            fileNamePath = WordFunc.GetFilePath(openFileDialog1);


            oWord = new Word.Application {
                Visible = false
            };

            // TODO: Take into account of other cases such as when the user close the dialog instead of choosing a file
            try {
                oDoc = oWord.Documents.Open(fileNamePath, false, false, false);
            }
            catch {
                return;
            }

            WordFunc.ParseDocument(this, oDoc);
            bodyText = oDoc.Content.Text;

            //oDoc.SaveAs2(GetFilePath(saveFileDialog1));
            WordFunc.CloseWordFile(oWord, oDoc);
        }
Example #8
0
        public void openDocument(string doc)
        {
            closeWordProcess();

            Object Template     = doc;                                       // Optional Object. The name of the template to be used for the new document. If this argument is omitted, the Normal template is used.
            Object NewTemplate  = false;                                     // Optional Object. True to open the document as a template. The default value is False.
            Object DocumentType = Word.WdNewDocumentType.wdNewBlankDocument; // Optional Object. Can be one of the following WdNewDocumentType constants: wdNewBlankDocument, wdNewEmailMessage, wdNewFrameset, or wdNewWebPage. The default constant is wdNewBlankDocument.
            Object Visible      = true;

            // Optional Object. True to open the document in a visible window.
            // If this value is False, Microsoft Word opens the document but sets
            // the Visible property of the document window to False.
            // The default value is True.

            try
            {
                wApp = new Word.Application();
                //wApp.Visible = true;
                wDoc = wApp.Documents.Add(ref Template, ref NewTemplate,
                                          ref DocumentType, ref Visible);
            }
            catch (Exception ex)
            {
                this.close();
                throw ex;
            }
        }
Example #9
0
        private void insertTOC(Word._Application oWord, Word._Document oDoc)
        {
            log("Inserting TOC...");

            Object oClassType = "Word.Document.8";
            Object oTrue      = true;
            Object oFalse     = false;
            Object oMissing   = System.Reflection.Missing.Value;

            object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined bookmark */

            Word.Range rngTOC = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;

            //Add the TOC to the document

            //Object oBookmarkTOC = "TOC";
            // SETTING THE RANGE AT THE BOOKMARK
            //Word.Range rngTOC = oDoc.Bookmarks.get_Item(ref oBookmarkTOC).Range;
            // SELECTING THE SET RANGE
            rngTOC.Select();
            // INCLUDING THE TABLE OF CONTENTS
            Object oUpperHeadingLevel = "1";
            Object oLowerHeadingLevel = "3";
            Object oTOCTableID        = "TableOfContents";

            oDoc.TablesOfContents.Add(rngTOC, ref oTrue, ref oUpperHeadingLevel,
                                      ref oLowerHeadingLevel, ref oMissing, ref oTOCTableID, ref oTrue,
                                      ref oTrue, ref oMissing, ref oTrue, ref oTrue, ref oTrue);

            //UPDATING THE TABLE OF CONTENTS
            oDoc.TablesOfContents[1].Update();
            //UPDATING THE TABLE OF CONTENTS
            oDoc.TablesOfContents[1].UpdatePageNumbers();
        }
        /// <summary>
        /// 打开Word文档
        /// </summary>
        public bool OpenWord(bool isVisible)
        {
            bool isOpen = false;

            if (_wordApp == null)
            {
                _wordApp = new Word.ApplicationClass();
            }
            if (string.IsNullOrEmpty(_strFromFilePath))
            {
                return(isOpen);
            }
            object filepath       = _strFromFilePath as object;
            object confirmVersion = false;

            _curDoc = _wordApp.Documents.Open(ref filepath, ref confirmVersion, ref oMissing, ref oMissing, ref oMissing,
                                              ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                                              ref oMissing);
            _wordApp.Visible     = isVisible;
            _wordApp.WindowState = WdWindowState.wdWindowStateMaximize;
            if (_curDoc != null)
            {
                isOpen = true;
            }
            return(isOpen);
        }
Example #11
0
        private void AllInformingInterface()
        {
            DataTable debting_flats = SQL.FillTable("select distinct ID_квартиры from Долг order by ID_квартиры");
            foreach (DataRow row in debting_flats.Rows)
            {
                oWord = new Word.Application();
                DataTable flat_info = SQL.FillTable("select * from Квартира where ID_квартиры = " + row[0].ToString());
                DataTable tenant_info = SQL.FillTable("select * from Квартиросъёмщик where ID_квартиросъёмщика = " + flat_info.Rows[0][9].ToString());
                DataTable debt_info = SQL.FillTable("select Месяц, Год, Сумма from Долг where ID_квартиры = " + row[0].ToString() + " order by Год, Месяц");

                Word._Document oDoc = oWord.Documents.Add(TemplatePath + "Задолженность_по_квартплате.dotx");
                oDoc.Bookmarks["ФИО"].Range.Text = tenant_info.Rows[0][3].ToString() + " " + tenant_info.Rows[0][4].ToString() + " "
                    + tenant_info.Rows[0][5].ToString();
                oDoc.Bookmarks["Город"].Range.Text = flat_info.Rows[0][1].ToString();
                oDoc.Bookmarks["Улица"].Range.Text = flat_info.Rows[0][2].ToString();
                oDoc.Bookmarks["Дом"].Range.Text = flat_info.Rows[0][3].ToString();
                oDoc.Bookmarks["Квартира"].Range.Text = flat_info.Rows[0][4].ToString();
                int i = 2;
                foreach(DataRow row_debt in debt_info.Rows)
                {
                    oDoc.Tables[1].Rows.Add();
                    oDoc.Tables[1].Cell(i, 1).Range.Text = row_debt[1].ToString();
                    oDoc.Tables[1].Cell(i, 2).Range.Text = row_debt[0].ToString();
                    oDoc.Tables[1].Cell(i, 3).Range.Text = row_debt[2].ToString();
                    i++;
                }
                DateTime dt = DateTime.Now;
                oDoc.SaveAs(SavedDocumentsPath + "ИОЗ-" + flat_info.Rows[0][1].ToString() + "-" + flat_info.Rows[0][2].ToString() + "-" +
                flat_info.Rows[0][3].ToString()+ "-" + flat_info.Rows[0][4].ToString() + "-" +dt.Day + dt.Month+ dt.Year + dt.Hour + dt.Minute +
                dt.Second + ".docx");
                oDoc.Close();
            }
        }
Example #12
0
        public static void ShowDocument(string path)
        {
            Word._Application wordApplication = null;
            Word._Document    wordDocument    = null;
            try
            {
                wordApplication         = new Word.Application();
                wordDocument            = wordApplication.Documents.Open(path);
                wordApplication.Visible = true;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);

                if (wordDocument != null)
                {
                    wordDocument.Close();
                }
                if (wordApplication != null)
                {
                    wordApplication.Quit();
                }
            }
            finally
            {
                if (wordDocument != null)
                {
                    wordDocument = null;
                }
                if (wordApplication != null)
                {
                    wordApplication = null;
                }
            }
        }
 public PsychoReportGenerator(string rutaArch, AccesoDatos.AccesoDatos pAd)
 {
     this.rutaArchivo = rutaArch;
     this.ad          = pAd;
     this.oWord       = new Word.Application();
     oWord.Visible    = true;
     this.oDoc        = oWord.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);
 }
Example #14
0
        public groupDoc(string templatePath, bool startVisible)
        {
            //создаем обьект приложения word
            _application = new Word.Application();

            // создаем путь к файлу используя имя файла
            Object templatePathObj = "C:\\Documents and Settings\\iruchi\\Application Data\\Microsoft\\Шаблоны\\Normal.dotm";
        }
        public FontAnalyzerWindow()
        {
            // start a version of Word to use for this app
            oWord         = new Word.Application();
            oWord.Visible = false;

            InitializeComponent();
        }
Example #16
0
 private void updateTOC(Word._Application oWord, Word._Document oDoc)
 {
     log("Updating TOC...");
     //UPDATING THE TABLE OF CONTENTS
     oDoc.TablesOfContents[1].Update();
     //UPDATING THE TABLE OF CONTENTS
     oDoc.TablesOfContents[1].UpdatePageNumbers();
 }
Example #17
0
        public Window1()
        {
            // start a version of Word to use for this app
            oWord = new Word.Application();
            oWord.Visible = false;

            InitializeComponent();
        }
Example #18
0
        public FontSelection(Word._Application WordApp, string fname)
        {
            object oMissing = System.Reflection.Missing.Value;

            oWord = WordApp;
            object fileName = fname;
            object oReadOnly = (Boolean)true;
            object oVisible = (Boolean)true;

            oDoc = oWord.Documents.Open(ref fileName,
                ref oMissing, ref oReadOnly, ref oMissing, ref oMissing, ref oMissing,
                ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                ref oVisible, ref oMissing, ref oMissing, ref oMissing, ref oMissing);

            make_font_table(fname);
            InitializeComponent();
        }
Example #19
0
        // конструктор, создаем по шаблону, потом возможно расширение другими вариантами
        public word()
        {
            wordApplication = new Word.Application();

            //создаем ноый документ методом приложения Word по поути к шаблону документа
            try
            {
                  wordDocument = wordApplication.Documents.Add(ref wordMissing, ref wordMissing, ref wordMissing, ref wordMissing);

            }
            // если произошла ошибка, то приложение Word надо закрыть
            catch (Exception error)
            {
                wordApplication.Quit(ref wordMissing, ref  wordMissing, ref wordMissing);
                wordApplication = null;
                throw new Exception("Ошибка. Не удалось открыть шаблон документа MS Word. " + error.Message);
            }
            // завершение createFromTemplate(string templatePath)
        }
Example #20
0
        private void button2_Click(object sender, EventArgs e)
        {
            DataTable t;
            int month = 0; int year = 0;
            if (Int32.TryParse(textBox1.Text, out month) == true && Int32.TryParse(textBox2.Text, out year) == true)
            {
                if (month >= 1 && month <= 12)
                {
                    t = SQL.FillTable("select * from Оплата where Месяц = " + month + " and Год = " + year);
                    if (t.Rows.Count == 0) { MessageBox.Show("За данный месяц расчёт не проводился!", "Информация", MessageBoxButtons.OK, MessageBoxIcon.Error); }
                    else
                    {
                        oWord = new Word.Application();
                        Word._Document oDoc = oWord.Documents.Add(TemplatePath + "Отчет_по_управляющим_компаниям.dotx");
                        oDoc.Bookmarks["Месяц"].Range.Text = month.ToString();
                        oDoc.Bookmarks["Год"].Range.Text = year.ToString();
                        t = SQL.FillTable("select * from Управляющая_компания");
                        int i = 2;
                        foreach (DataRow row in t.Rows)
                        {

                            int sum = 0;
                            int negative_sum = 0;
                            DataTable flats_id = SQL.FillTable("select ID_квартиры from Квартира where ID_УК = " + row[0].ToString());
                            foreach (DataRow flat in flats_id.Rows)
                            {
                                DataTable payments = SQL.FillTable("select Сумма from Оплата where ID_квартиры = " + flat[0].ToString() + " and Месяц=" +
                                    month + " and Год = " + year);
                                foreach (DataRow dr in payments.Rows)
                                {

                                    sum += Convert.ToInt32(dr[0]);
                                }

                                DataTable debts = SQL.FillTable("select Сумма from Долг where ID_квартиры = " + flat[0].ToString() + " and Месяц=" +
                                    month + " and Год = " + year);
                                foreach (DataRow dr in debts.Rows)
                                {

                                    negative_sum += Convert.ToInt32(dr[0]);
                                }
                            }
                            oDoc.Tables[1].Rows.Add();
                            oDoc.Tables[1].Cell(i, 1).Range.Text = row[1].ToString();
                            oDoc.Tables[1].Cell(i, 2).Range.Text = sum.ToString();
                            oDoc.Tables[1].Cell(i, 3).Range.Text = negative_sum.ToString();
                            i++;

                        }
                        DateTime dt = DateTime.Now;
                        oDoc.SaveAs(SavedDocumentsPath + "МОУК-" + month.ToString() + "-" + year.ToString() + "-" + dt.Day + dt.Month + dt.Year + dt.Hour + dt.Minute +
                        dt.Second + ".docx");
                        oDoc.Close();
                        MessageBox.Show("Отчёты успешно составлены!", "Информация", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                else
                {
                    MessageBox.Show("Значение месяца должно быть от 1 от 12", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("Проверьте правильность ввода полей!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #21
0
        // закрытие открытого документа и приложения
        public void Close()
        {
            if (documentClosed()) { throw new Exception("Ошибка при попытке закрыть Microsoft Word. Программа или документ уже закрыты."); }

            wordDocument.Close(ref wordFalse, ref  wordMissing, ref wordMissing);
            wordApplication.Quit(ref wordMissing, ref  wordMissing, ref wordMissing);
            wordDocument = null;
            wordApplication = null;
        }
 public void Setup()
 {
     //_outlookApp = new Outlook.ApplicationClass();
     _wordApp = new Word.Application();
     _wordApp.Visible = false;
 }
Example #23
0
        // создаем приложение Word и открывает новый документ по заданному файлу шаблона
        public void CreateFromTemplate(string templatePath)
        {
            //создаем обьект приложения word

                wordApplication = new Word.Application();
                wordApplication.Visible = false;

            // создаем путь к файлу используя имя файла
            templatePathObj = templatePath;

            //создаем ноый документ методом приложения Word по поути к шаблону документа
            try
            {
                wordDocument = wordApplication.Documents.Open(templatePath);
                //wordDocument = wordApplication.Documents.Add(ref templatePathObj,ref wordMissing, ref wordMissing, true);
            }
            // если произошла ошибка, то приложение Word надо закрыть
            catch (Exception error)
            {
                wordApplication.Quit(ref wordMissing, ref  wordMissing, ref wordMissing);
                wordApplication = null;
                throw new Exception("Ошибка. Не удалось открыть шаблон документа MS Word. " + error.Message);
            }
            // завершение createFromTemplate(string templatePath)
        }
Example #24
0
        private void CreateWordDocument()
        {
            //создаем обьект приложения word
            m_app = new Microsoft.Office.Interop.Word.Application();
            // создаем путь к файлу
            Object templatePathObj = System.IO.Path.GetTempFileName();

            // если вылетим не этом этапе, приложение останется открытым
            try
            {
                m_doc = m_app.Documents.Add(ref templatePathObj, ref missingObj, ref missingObj, ref missingObj);
            }
            catch (Exception error)
            {
                m_doc.Close(ref falseObj, ref missingObj, ref missingObj);
                m_app.Quit(ref missingObj, ref missingObj, ref missingObj);
                m_doc = null;
                m_app = null;
                throw error;
            }
            //m_app.Visible = true;
        }
Example #25
0
        private void button2_Click(object sender, EventArgs e)
        {
            DataTable t;
            int year = 0;
            if (Int32.TryParse(textBox1.Text, out year) == true)
            {

                    t = SQL.FillTable("select * from Оплата where Год = " + year);
                    if (t.Rows.Count == 0) { MessageBox.Show("За данный год расчёт ни разу не проводился!", "Информация", MessageBoxButtons.OK, MessageBoxIcon.Error); }
                    else
                    {
                        t = SQL.FillTable("select * from Управляющая_компания");
                        foreach (DataRow row in t.Rows)
                        {
                            oWord = new Word.Application();
                            int flats_total = 0;
                            int payments_total = 0;
                            int debts_total = 0;
                            int sum = 0;
                            int negative_sum = 0;
                            Word._Document oDoc = oWord.Documents.Add(TemplatePath + "Годовой_отчёт_new.dotx");
                            DataTable flats_id = SQL.FillTable("select ID_квартиры from Квартира where ID_УК = " + row[0].ToString());
                            flats_total = flats_id.Rows.Count;
                            for (int month = 1; month <= 12; month++)
                            {
                                int payments_total_month = 0;
                                int debts_total_month = 0;
                                int sum_month = 0;
                                int negative_sum_month = 0;
                                foreach (DataRow flat in flats_id.Rows)
                                {
                                    DataTable payments = SQL.FillTable("select Сумма from Оплата where ID_квартиры = " + flat[0].ToString() + " and Месяц=" +
                                        month + " and Год = " + year);
                                    foreach (DataRow dr in payments.Rows)
                                    {
                                        if (Convert.ToInt32(dr[0]) > 0) payments_total_month++;
                                        sum_month += Convert.ToInt32(dr[0]);
                                    }

                                    DataTable debts = SQL.FillTable("select Сумма from Долг where ID_квартиры = " + flat[0].ToString() + " and Месяц=" +
                                        month + " and Год = " + year);
                                    foreach (DataRow dr in debts.Rows)
                                    {
                                        if (Convert.ToInt32(dr[0]) > 0) debts_total_month++;
                                        negative_sum_month += Convert.ToInt32(dr[0]);
                                    }
                                }
                                payments_total += payments_total_month;
                                debts_total += debts_total_month;
                                sum += sum_month;
                                negative_sum += negative_sum_month;
                                oDoc.Tables[2].Cell(month + 1, 2).Range.Text = negative_sum_month.ToString();
                            }

                            oDoc.Bookmarks["Год"].Range.Text = year.ToString();
                            oDoc.Bookmarks["УК"].Range.Text = row[1].ToString();
                            oDoc.Bookmarks["Квартир"].Range.Text = flats_total.ToString();
                            oDoc.Bookmarks["Оплат"].Range.Text = payments_total.ToString();
                            oDoc.Bookmarks["Число"].Range.Text = debts_total.ToString();
                            oDoc.Bookmarks["Сумма"].Range.Text = sum.ToString();
                            oDoc.Bookmarks["Недостача"].Range.Text = negative_sum.ToString();

                            DateTime dt = DateTime.Now;
                            oDoc.SaveAs(SavedDocumentsPath + "ГО-" + row[1].ToString() + "-" + year.ToString() + "-" + dt.Day + dt.Month + dt.Year + dt.Hour + dt.Minute +
                            dt.Second + ".docx");
                            oDoc.Close();
                            MessageBox.Show("Отчёты успешно составлены!", "Информация", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }

            }
            else
            {
                MessageBox.Show("Проверьте правильность ввода полей!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #26
0
 public CCWordApp(Word._Application oWordApplic, Word.Document oDoc)
 {
     this.oWordApplic = oWordApplic;
     this.oDoc = oDoc;
 }
Example #27
0
 /// <summary>
 /// 创建word文档
 /// </summary>
 public void CreateWord()
 {
     _WordApplicMain = new Microsoft.Office.Interop.Word.Application();
     _MainDoc = _WordApplicMain.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);
     SetPageDefaultStyle(new MyWordPageStyle());
 }
Example #28
0
        public Word._Application oWordApplic; // a reference to Word application

        #endregion Fields

        #region Constructors

        public CCWordApp()
        {
            // activate the interface with the COM object of Microsoft Word
            oWordApplic = new Word.ApplicationClass();
        }
 public Word07()
 {
     KillWordProcess(new TimeSpan(0, _INVALID_WORDPROC_TIMEOUT_, 0));
     m_WordApp = new Application();
     m_DocFormat = new DocFormat();
 }
 public override void Close()
 {
     if (m_WordApp != null)
     {
         if(m_doc != null)
             m_doc.Close(ref oMissing, ref oMissing, ref oMissing);
         m_WordApp.Quit(ref oMissing, ref oMissing, ref oMissing);
         m_doc = null;
         m_WordApp = null;
     }
     KillWordProcess(new TimeSpan(0, _INVALID_WORDPROC_TIMEOUT_, 0));
 }
Example #31
0
 /// <summary>
 /// Open the PowerPoint application
 /// </summary>
 private void OpenOfficeApplication()
 {
     if (wordApplication == null)
     {
         wordApplication = new Microsoft.Office.Interop.Word.Application();
     }
     if (powerPointApplication == null)
     {
         powerPointApplication = new Microsoft.Office.Interop.PowerPoint.Application();
     }
 }
Example #32
0
 /// <summary>
 /// Close the Powerpoint Application
 /// </summary>
 private void CloseOfficeApplication()
 {
     if (wordApplication != null)
     {
         wordApplication.Quit(false, System.Reflection.Missing.Value, System.Reflection.Missing.Value);
         wordApplication = null;
     }
     if (powerPointApplication != null)
     {
         powerPointApplication.Quit();
         powerPointApplication = null;
     }
 }