[visual C#]помогите найти ошибку

Discussion in 'С/С++, C#, Rust, Swift, Go, Java, Perl, Ruby' started by fox_malder, 5 Jun 2011.

  1. fox_malder

    fox_malder Active Member

    Joined:
    28 Nov 2008
    Messages:
    162
    Likes Received:
    131
    Reputations:
    73
    Добрые люди помогите найти ошибку , у меня есть программа которая вставляет текст в шаблон по средствам закладок все хорошо, она это делает, но когда я его открываю чтобы проверить все ли хорошо и потом закрываю и пытаюсь ввести информацию другую программа сбивается и не хочет дальше работать :confused: :rolleyes: :rolleyes: помогите пожалуйста
    вот код

    Code:
    
    
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Windows.Forms;
    using System.Linq;
    using System.Text;
    using Microsoft.Office;
    using Microsoft.Office.Interop;
    using Word = Microsoft.Office.Interop.Word;
    
    
    namespace word
    {
        public partial class Form1 : Form
        {
            Word._Application oWord = new Word.Application();
            object oMissing = System.Reflection.Missing.Value;
    
            public Form1()
            {
                InitializeComponent();
            }
    
    
            private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
            {
                oWord.Quit(ref oMissing, ref oMissing, ref oMissing);
            }
    
        
    
            private void saveBtn_Click(object sender, EventArgs e)
            {
                Word._Document oDoc = LoadTemplate(Environment.CurrentDirectory + "\\Dot6.dot");
                SetTemplate(oDoc);
                SaveToDisk(oDoc, Environment.CurrentDirectory + "\\Dot6.dot");
                oDoc.Close(ref oMissing, ref oMissing, ref oMissing);
                
            }
            private Word._Document LoadTemplate(string filePath)
            {
                object oTemplate = filePath;
                Word._Document oDoc = oWord.Documents.Add(ref oTemplate, ref oMissing, ref oMissing, ref oMissing);
                return oDoc;
            }
    
            private void SetTemplate(Word._Document oDoc)
            {
                object oBookMark = "MERGEFIELD";
                oDoc.Bookmarks.get_Item(ref oBookMark).Range.Text = autorTxtb.Text;
            }
    
            private void SaveToDisk(Word._Document oDoc, string filePath)
            {
                object fileName = filePath;
                oDoc.SaveAs(ref fileName, 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, ref oMissing);
            }
    
           
            
           
    
           
        }
    }
    
    
     
  2. fox_malder

    fox_malder Active Member

    Joined:
    28 Nov 2008
    Messages:
    162
    Likes Received:
    131
    Reputations:
    73
    народ подскажите как сделать чтобы при нажатии кнопки и выполнения операций с вордом , чтобы потом WINWORD процесс закрывался
     
  3. cheater_man

    cheater_man Member

    Joined:
    13 Nov 2009
    Messages:
    651
    Likes Received:
    44
    Reputations:
    7
    скорее всего ты его не корректно закрываешь
     
  4. BrainDeaD

    BrainDeaD Elder - Старейшина

    Joined:
    9 Jun 2005
    Messages:
    774
    Likes Received:
    292
    Reputations:
    214
    хз, никогда не раболтал с ворд-темплейтами.
    хардкор вариант - тупо убивать процесс.
     
    #4 BrainDeaD, 6 Jun 2011
    Last edited: 6 Jun 2011
    1 person likes this.
  5. fox_malder

    fox_malder Active Member

    Joined:
    28 Nov 2008
    Messages:
    162
    Likes Received:
    131
    Reputations:
    73
    Добрые люди спасибо за подсказки проблема решена