Tìm kiếm 
Tag +
Tag -
Invoke COM Components from VB.NET (demo included)
Giới thiệu:

Ngày gửi: Thứ Sáu, 02/05/2008 Ngôn ngữ: Visual Basic
Nguồn: NA Syntax: Visual Basic
Lượt xem: 629    


‘
‘
‘Import Reflection Namspace which supports COM interoperability
Imports System.Reflection
Imports System.Threading
‘
‘We will try to call Excel application from .NET environment
‘This is a latebinding application
‘for early binding u have to use RCW of COM Object
‘to do so use command line tool tblimp
‘ex.     c:\> tblimp  /out:
Module Module1
    Sub Main()
        ‘Define a variable to hold the Excel application
        Dim excel As Type
        Dim excelobject As Object
        Try
            ‘Get the excel object
            excel = Type.GetTypeFromProgID(“Excel.Application”)
            ‘Create instance of excel
            excelobject = Activator.CreateInstance(excel)
            ‘Set the parameter whic u want to set
            Dim parameter(1) As Object
            parameter(0) = True
            ‘Set the Visible property
            excel.InvokeMember(“Visible”, _
            BindingFlags.SetProperty, Nothing, _
             excelobject, parameter)
        Catch e As Exception
            Console.WriteLine(“Error Stack {0} ”, e.Message)
        Finally
            ‘When this object is destroyed the Excel
            ‘application will be closed
            ‘So Sleep for sometime and see the excel application
            Thread.Sleep(5000)
            ‘Relaese the object
            ‘GC.RunFinalizers()
        End Try
    End Sub
End Module

Các bài phản hồi, bình luận
Tất cả có 0 phản hồi cho bài này.