ASP.NET----新規作成、ワードコンテンツ編集機能を実現

2852 ワード

using System;

using System.Collections.Generic;

using System.Linq;

using System.IO;

using Microsoft.Office.Core;

using Microsoft.Office.Interop.Word;



namespace contractTest

{

    class Program

    {

        static void Main(string[] args)

        {

            Console.WriteLine("Word 2010");

            Microsoft.Office.Interop.Word.Application oWord = new Microsoft.Office.Interop.Word.Application();

            oWord.Visible = true;

            Microsoft.Office.Interop.Word.Document oDoc;

            object oMissing = System.Reflection.Missing.Value;

            object strFileName = "F:\\test.doc";

            //if (File.Exists((string)strFileName))

            //    File.Delete((string)strFileName);



            ////Ceate An New Word      word  

            //oDoc = oWord.Documents.Add(ref oMissing,ref oMissing,ref oMissing,ref oMissing);

            //oDoc.Paragraphs.Last.Range.Text = "Create An New Word!
\r"; //oDoc.SaveAs(ref strFileName,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); //oDoc.Close(ref oMissing,ref oMissing,ref oMissing); //oWord.Quit(ref oMissing,ref oMissing,ref oMissing ); //Console.WriteLine("Create An New Word"); //Open The Word word oDoc = null; oWord = null; oWord = new Microsoft.Office.Interop.Word.Application(); oDoc = oWord.Documents.Open(ref strFileName, 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); oDoc.Paragraphs.Last.Range.Text = "Open The Word!
\r"; Console.WriteLine("Open The New Word"); //Insert a paragraph Microsoft.Office.Interop.Word.Paragraph oPara1; oPara1 = oDoc.Content.Paragraphs.Add(ref oMissing); oPara1.Range.Text = "Heading 1"; oPara1.Range.Font.Bold = 1; oPara1.Format.SpaceAfter = 24;//24pt spacing after paragraph oPara1.Range.InsertParagraphAfter(); Console.WriteLine("Insert a paragraph"); //close , oDoc.Save(); oDoc.Close(ref oMissing,ref oMissing ,ref oMissing ); oWord.Quit(ref oMissing,ref oMissing,ref oMissing); Console.WriteLine("Close Over"); } } }