none
vb2008窗体如何嵌入excel2007? RRS feed

答案

  • Hi ,

    你可以试试这个代码:

        <DllImport("user32.dll")> _
        Private Shared Function SetParent(ByVal hWndChild As Integer, ByVal hWndNewParent As Integer) As Integer
        End Function
    
    
        Public Excel As Excel.Application = Nothing
        Public Workbook As Microsoft.Office.Interop.Excel.Workbook
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Excel = New Excel.Application
            Dim ExcelWnd As Integer = Excel.Hwnd
    
            Workbook = Excel.Workbooks.Add(XlWBATemplate.xlWBATWorksheet)
            Workbook.Activate()
    
            SetParent(ExcelWnd, Me.Handle.ToInt32())
            Excel.Visible = True
        End Sub

    希望有用。


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    2013年4月3日 8:26
    版主

全部回复

  • vb2008嵌窗体嵌入excel2007如何实现?

    恐怕你需要使用OleDbDataAdapter读取特定的Excel2007文件,然后绑定到dataGridView上方可显示。

    关于Excel数据库连接字符串:

    http://www.connectionstrings.com/excel-2007


    If you think one reply solves your problem, please mark it as An Answer, if you think someone's reply helps you, please mark it as a Proposed Answer

    Help by clicking:
    Click here to donate your rice to the poor
    Click to Donate
    Click to feed Dogs & Cats

    2013年4月2日 3:09
    版主
  • Hi ,

    你可以试试这个代码:

        <DllImport("user32.dll")> _
        Private Shared Function SetParent(ByVal hWndChild As Integer, ByVal hWndNewParent As Integer) As Integer
        End Function
    
    
        Public Excel As Excel.Application = Nothing
        Public Workbook As Microsoft.Office.Interop.Excel.Workbook
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Excel = New Excel.Application
            Dim ExcelWnd As Integer = Excel.Hwnd
    
            Workbook = Excel.Workbooks.Add(XlWBATemplate.xlWBATWorksheet)
            Workbook.Activate()
    
            SetParent(ExcelWnd, Me.Handle.ToInt32())
            Excel.Visible = True
        End Sub

    希望有用。


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    2013年4月3日 8:26
    版主