Microsoft Office VB.NET编程,获得当前编辑文档的对象,并打印到控制台
PIA COM组件安装参见微软MSDN。
Imports Microsoft.Office.Interop.Word
Imports System.Runtime.InteropServices
Module Module1
Sub Main()
Dim wdGlobal As GlobalClass
Dim docs As Documents
Dim FileName As String
Dim doc As Document
Try
'获得当前Word application对象
wdGlobal = New GlobalClass
docs = wdGlobal.Documents
'获得当前编辑文档对象
If docs.Count() <> 0 Then
doc = docs(1)
End If
If Not doc Is Nothing Then
Console.WriteLine(doc.Path + "\\" + doc.Name)
'在控制台打印文档内容
Console.Write(doc.Content.Text)
Console.WriteLine()
End If
Catch ex As COMException
Console.WriteLine(ex.Message)
End Try
Console.WriteLine("input return key to end")
Console.ReadLine()
End Sub
End Module
该博客介绍了使用Microsoft Office VB.NET编程,获取当前编辑文档的对象并打印到控制台的方法。还提到PIA COM组件安装可参见微软MSDN,同时给出了具体的代码实现,包括获取Word application对象、当前编辑文档对象等操作。
2118

被折叠的 条评论
为什么被折叠?



