C#创建一个Word并打开的方法
作者:Regina 发布时间:2022-08-04 23:33:13
标签:C#,Word
本文实例讲述了C#创建一个Word并打开的方法。分享给大家供大家参考。具体实现方法如下:
private static string _createNewWord(string allTnC)
{
Microsoft.Office.Interop.Word.Document wordDocument = null;
Microsoft.Office.Interop.Word.Application wordApplication = null;
string dateTimeNow = DateTime.Now.ToString();
string wordPath = Path.GetTempFileName();
wordApplication = new Word.ApplicationClass();
object nothing = Missing.Value;
wordDocument = wordApplication.Documents.Add(ref nothing, ref nothing, ref nothing, ref nothing);
wordDocument.Paragraphs.Last.Range.Text = allTnC;
object format = Word.WdSaveFormat.wdFormatDocumentDefault;
wordDocument.SaveAs(wordPath, ref format, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing,
ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing);
wordDocument.Application.Documents.Close(ref nothing, ref nothing, ref nothing);
((Word.ApplicationClass)wordApplication).Quit(ref nothing, ref nothing, ref nothing);
return wordPath;
}
private static void _importTnCToActiveDocument(string wordPath)
{
Word.Application wordApplication = new Word.Application();
Word.Document wordDocument = new Word.Document();
Object nothing = System.Reflection.Missing.Value;
Object filePath = wordPath;
wordApplication.Documents.Open(ref filePath, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing);
wordDocument = wordApplication.ActiveDocument;
wordApplication.Visible = true;
}
vs10-office项目中创建ThisAddIn按钮实现某些功能当打开多个word时便获取不到当前word文档对象(如需要获取打开的第一个文档中的bookmark)
可以在 Startup 中加入:
ViteRibbon viteRibbon = new ViteRibbon(this.Application);
构造函数传递该参数并赋值:
currentDoucment = wordApp.ActiveDocument;
希望本文所述对大家的C#程序设计有所帮助。


猜你喜欢
- 我正在开发一个软键盘,做得很好,但是我不知道如何自定义一个长按键的弹出窗口.我的键盘视图:<?xml version="1.
- 具体详细介绍请看下文:在使用文件进行交互数据的应用来说,使用FTP服务器是一个很好的选择。本文使用Apache Jakarta Common
- 目录一、Java 类加载过程1、字节码编译2、加载3、连接4、初始化总结一、Java 类加载过程1、字节码编译编写好 Java 源码 Stu
- 目前系统集成短信似乎是必不可少的部分,由于各种云平台都提供了不同的短信通道,这里我们增加多租户多通道的短信验证码,并增加配置项,使系统可以支
- 协程属于Kotlin中非常有特色的一项技术,因为大部分编程语言中是没有协程这个概念的。那么什么是协程呢?它其实和线程有点相似,可以简单地将它
- 本文讲述了Java递归运行的机制:递归的微观解。分享给大家供大家参考,具体如下:前言:在java递归基础与递归的宏观语意和java链表的天然
- hello,今天给大家带来一道算法题。这道算法题,是我目前为止,见过最难的一道题。那么到底是怎样的一道算法题呢?如下:题目:给定一个数组,
- 一、举个栗子public class BeanServiceImpl implements BeanService {}@Configura
- 单例模式是最常用到的设计模式之一,熟悉设计模式的朋友对单例模式都不会陌生。一般介绍单例模式的书籍都会提到 饿汉式 和 懒汉式 这两种实现方式
- 主要介绍使用MediaPlayer播放音频的方式。关于MediaPlayer的基础知识,比如状态,可以参考Android MediaPlay
- 本文实例讲述了java swing实现的扫雷游戏及改进版。分享给大家供大家参考,具体如下:版本1:package awtDemo;impor
- 本文是vhr系列的第十二篇,项目地址 https://github.com/lenve/vhr邮件发送也是一个老生常谈的问题了,代码虽然简单
- 本文介绍spring中自定义缓存resolver,通过自定义resolver,可以在spring的cache注解中增加附加处理。一、概述ca
- 方法1:C#Label1.Text = Request.Form["txtName"].ToString();vb.ne
- 给大家看个计算题,看看大家的算术能力。0.1 +0.1 +0.1 - 0.3 等于几?大家可能会说这么简单的问题,是不是看不起我?肯定等于0
- 1.安装插件首先需要安装所用到的插件,分别用来支持Java、热部署和Tomcat服务器的插件在插件市场中搜索Java,第一个就是Extens
- 本文实例为大家分享了C语言实现中国象棋的具体代码,供大家参考,具体内容如下运行截图实现思路老套路,二维数组存储棋盘,宏定义各种棋子,每次棋子
- 本文实例讲述了基于私钥加密公钥解密的RSA算法C#实现方法,是一种应用十分广泛的算法。分享给大家供大家参考之用。具体方法如下:一、概述RSA
- 一.前言现在的app基本上都需要用到短信功能,注册时或者有消息通知时需要给用户发送一条短信,但是对于个人开发者来说,去买第三方的短信服务实在
- 1 导入需要渐变的图片如果需要实现图片之间的渐变效果,我们需要两张照片,这样才能实现照片1到照片2的渐变。在路径 /res/values/