Thursday, July 2, 2015

Xsheet name obtaining

Xsheet name obtaining

Imports System.IO
Imports Microsoft.VisualBasic
Imports System.Net.Mime.MediaTypeNames
Imports Microsoft.Office.Interop.Excel
Imports Office = Microsoft.Office.Core
Imports System.Windows.Forms


Public Class coe
    Public Sub closeall()
        End
    End Sub
    Public Sub source_file()
        Dim dialog As New OpenFileDialog()
        If DialogResult.OK = dialog.ShowDialog Then
            Form1.Label3.Text = dialog.FileName
        End If
        Dim xlapp As New Microsoft.Office.Interop.Excel.Application
        Dim xlsht As Microsoft.Office.Interop.Excel.Worksheet
        Dim xlwb As Microsoft.Office.Interop.Excel.Workbook

        xlwb = xlapp.Workbooks.Open(dialog.FileName)
        For Each xlsht In xlwb.Worksheets
            Form1.ComboBox1.Items.Add(xlsht.Name)
        Next
        xlapp.Quit()
    End Sub
    Public Sub target_file()
        Dim dialog As New OpenFileDialog()
        If DialogResult.OK = dialog.ShowDialog Then
            Form1.Label4.Text = dialog.FileName
        End If
        Dim xlapp As New Microsoft.Office.Interop.Excel.Application
        Dim xlsht As Microsoft.Office.Interop.Excel.Worksheet
        Dim xlwb As Microsoft.Office.Interop.Excel.Workbook
        xlwb = xlapp.Workbooks.Open(dialog.FileName)
        For Each xlsht In xlwb.Worksheets
            Form1.ComboBox2.Items.Add(xlsht.Name)
        Next
        xlapp.Quit()
    End Sub
End Class


No comments:

Post a Comment

Followers