Load Excel to edit xlsx file : Excel « Windows System « VB.Net






Load Excel to edit xlsx file

   


Module Module1

    Sub Main()

    Dim file As String = "Data.xlsx"
        Try
            Dim row, col, finalRow, finalCol As Integer
            Dim xl = CreateObject("Excel.application")
            xl.Workbooks.Open(file)
            xl.Worksheets("Sheet1").activate()

            finalRow = xl.ActiveSheet.UsedRange.Rows.Count
            finalCol = xl.ActiveSheet.UsedRange.Columns.Count

            Dim vals(finalRow, finalCol) As String
            For row = 1 To finalRow
                For col = 1 To finalCol
                    vals(row, col) = _
                    Str(xl.ActiveSheet.Cells(row, col).Value)
                    Console.WriteLine(row)
                    Console.WriteLine(col)
                    Console.WriteLine(vals(row, col))
                Next col
            Next row
            xl.Workbooks.Close()
            xl = Nothing
        Catch ex As Exception
            MsgBox("Unable to read spreadsheet")
        End Try

    End Sub
End Module

   
    
    
  








Related examples in the same category

1.Create workbook and read from it