Закрытие WORD приложения - C#
Формулировка задачи:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using Microsoft.Office.Interop.Word;
namespace kolontitul
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = folderBrowserDialog1.SelectedPath;
string selc_path;
selc_path = folderBrowserDialog1.SelectedPath;
string[] pathes = Name_Path_file(selc_path);
ParallelOptions ns = new ParallelOptions();
ns.MaxDegreeOfParallelism = 5;
Parallel.For(0, pathes.Length, ns,i =>
{
colontit(pathes[i]);
});
}
public string[] Name_Path_file(string path)
{
string [] file_name = System.IO.Directory.GetFiles(path, "*.doc", SearchOption.AllDirectories);
return file_name;
}
public void colontit(string path)
{
object file = @path;
object nullobj = System.Reflection.Missing.Value;
object missing = System.Reflection.Missing.Value;
object format = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatDocument;
ApplicationClass wordApp = new ApplicationClass();
Document doc = wordApp.Documents.Open(
ref file, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj);
wordApp.ActiveDocument.Sections[1].Footers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].
Range.Text = "cyberforum - место, где Вам всегда помогут.";
wordApp.Visible = false;
object save = Microsoft.Office.Interop.Word.WdSaveOptions.wdSaveChanges;
object orform = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatDocument;
doc.Close(ref save,ref orform, nullobj);
wordApp.Quit(save, orform, nullobj);
}
}
}Решение задачи: «Закрытие WORD приложения»
textual
Листинг программы
File.SetAttributes("filename", FileAttributes.Normal);