Imports Microsoft.Office.Interop.Excel Imports System.Text Imports System.Reflection Imports System.Data Imports Excel = Microsoft.Office.Interop.Excel Public Class Form1 Private Const connstring As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=C:\Test.xls;Extended Properties=""Excel 8.0;HDR=YES;""" Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'Dim objexcel As Microsoft.Office.Interop.Excel.Application ' Dim wb As Microsoft.Office.Interop.Excel.Workbook ' Dim ws As Microsoft.Office.Interop.Excel.Worksheet ' Dim mMsgResponse As Integer Dim objExcel As New Excel.Application Dim objBook As Excel.Workbook = objExcel.Workbooks.Open("C:\Users\Server\Downloads\DONEsb.xls") Dim objSheet As Excel.Worksheet Dim bolFlag As Boolean = True Dim excelRow As Integer = 7 Dim excelCol As Integer = 1 Dim strCell1 As String Dim strCell2 As String Dim strCell3 As String Dim strCell4 As String Dim strCell5 As String Dim strCell6 As String Dim dialog As New OpenFileDialog() ' If DialogResult.OK = dialog.ShowDialog Then 'TextBox1.Text = dialog.FileName ' objExcel = New Microsoft.Office.Interop.Excel.Application ' objBook = objExcel.Workbooks.Open(TextBox1.Text) If Convert.ToString(objSheet.Cells(excelRow, 1).value) = "" Then bolFlag = False strCell1 = CType(objSheet.Cells(excelRow, 1).value, String) strCell2 = CType(objSheet.Cells(excelRow, 2).value, String) strCell3 = CType(objSheet.Cells(excelRow, 3).value, String) strCell4 = CType(objSheet.Cells(excelRow, 4).value, String) strCell5 = CType(objSheet.Cells(excelRow, 5).value, String) strCell6 = CType(objSheet.Cells(excelRow, 6).value, String) excelRow += 1 strCell1 = "" strCell2 = "" strCell3 = "" strCell4 = "" strCell5 = "" strCell6 = "" objExcel.Visible = True objBook.Activate() MsgBox("") End If ' End If ' Catch ex As COMException ' MessageBox.Show("Error accessing Excel: " + ex.ToString()) End Sub End Class
Dim objSheet = objBook.Worksheets[1] as Microsoft.Office.Interop.Excel.Worksheet;
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)