Microsoft Office VB.NET编程,获得当前编辑文档的对象,并打印到控制台 OfficeVBVB.NETMicrosoft编程
程序员文章站
2022-07-05 21:36:51
...
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
下一篇: 吐槽各大题库的优劣