⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 program.cs

📁 [Visual C# 2005程序设计基础教程] 全部的源码!非常经典
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.Text;
using word = Microsoft.Office.Interop.Word;

namespace VSTOWord
{
    class Program
    {
        static void Main(string[] args)
        {
            //新建文档
            object oMissing = System.Reflection.Missing.Value;
            //实例化一个word应用程序Application对象oWord
            Microsoft.Office.Interop.Word.Application oWord = new Microsoft.Office.Interop.Word.Application();
            oWord.Visible = true;
            //定义一个文档对象oDoc
            Microsoft.Office.Interop.Word.Document oDoc;
            //使用word应用程序对象oWord对象Documents集合的Add方法实例化一个文档
            oDoc = oWord.Documents.Add(ref oMissing, ref oMissing,
            ref oMissing, ref oMissing);

            //向文档中添加文本
            object start = 0;
            object end = 0;
            word.Range rng = oDoc.Range(ref start, ref end);
            rng.Text = "Hello Word";

            //保存文档
            object fileName = @"C:\\NewDocument.doc";
            oWord.ActiveDocument.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);

        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -