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#程序设计有所帮助。
0
投稿
猜你喜欢
- 一、概念从本质上来说,它就是一个匿名函数,可以用来直接实现接口中的方法,从而简化代码。但是Lambda有一个限制,不能实现接口中的所有方法,
- 这周末体验了一下挺火的Docker技术,记录学习笔记。>Docker是干什么的Docker 是一个基于Linux容器(LXC-linu
- 前言本文主要给大家介绍了关于Spring Boot应用极速部署脚本的相关内容,分享出来供大家参考学习,下面话不多说了,来一起看看详细的介绍吧
- C# Linq获取两个List或数组的差集交集List<int> list1 = newList<int>();li
- 本文实例讲述了Android编程获取GPS数据的方法。分享给大家供大家参考,具体如下:GPS是Android系统中重要的组成部分,通过它可以
- 假如使用绝对路径,没有任何问题,就是移植性不太好。假如使用相对路径,则要注意当前路径“.”是在哪儿?一般我们都会在配置文件中加入log文件的
- 一、前置说明本节大纲使用lombok插件的好处如何安装lombok插件使用lombok提高开发效率二、使用lombok插件的好处我们在jav
- 今天给大家提供一个由今天给大家提供一个由Java swing实现的酒店管理系统,数据库采用sqlserver,我会贴上部分代码,完整的代码请
- 本文实例讲述了C#验证给定字符串是否为数字的方法。分享给大家供大家参考。具体分析如下:这段C#代码用于验证给定的字符串是否为数字,不能用于验
- Spring提供的工具类,主要用于框架内部使用,这个类提供了一些简单的方法,并且提供了易于使用的方法在分割字符串,如CSV字符串,以及集合和
- 类必须先定义才能使用。类是创建对象的模板,创建对象也叫类的实例化。下面通过一个简单的例子来理解Java中类的定义:public class
- 通过代码操作防火墙的方式有两种:一是代码操作修改注册表启用或关闭防火墙;二是直接操作防火墙对象来启用或关闭防火墙。不论哪一种方式,都需要使用
- 一. 可变字符串1. 简介在Java中,我们除了可以通过String类创建和处理字符串之外,还可以使用StringBuffer和String
- 本文实例讲述了Java二维数组。分享给大家供大家参考,具体如下:一 点睛1 每行的元素个数不同的二维数组Java定义二维数组更加灵活,允许二
- MyBatis 配置之集合的嵌套前言介绍在一些查询结果包装类中,包含一些 List 集合属性,使用 collection 标签可以声明该 L
- 最近在做上传文件的服务,简单看了网上的教程。结合实践共享出代码。由于网上的大多数没有服务端的代码,这可不行呀,没服务端怎么调试呢。Ok,先上
- 1、背景说明公司收费系统需要与银行做实时代收对接,业务协议使用我们收费系统的标准。但是银行要求在业务协议的基础上,使用银行的加密规则。采用M
- spring.thymeleaf.cache=false不起作用配置是清除缓存,实现热部署。也就是修改了html后不用重启,刷新页面就能看到
- 本文实例讲述了C#写入对象或集合类型数据到xml文件的方法。分享给大家供大家参考。具体实现方法如下:public static string
- disruptor不过多介绍了,描述下当前的业务场景,两个应用A,B,应用 A 向应用 B 传递数据 . 数据传送比较快,如果用http直接