public class Test
public Shared Sub Main
Dim objExcel As Excel.Application
objExcel = New Excel.Application
Dim objSheet As New Excel.Worksheet
Dim objData As Excel.Range
Dim intCol, intRow As Integer
Call OpenExcel()
objExcel.Visible = True
objSheet = objExcel.Workbooks.Open("C:\Temp\Test.xls").Worksheets.Item(1)
objExcel.Range("A2:E3").Select()
objData = objExcel.Selection
objData.Sort(Key1:=objData.Range("A2"), Order1:=Excel.XlSortOrder.xlAscending)
For intCol = 1 To 5
For intRow = 1 To 2
Console.WriteLine(objData(intRow, intCol).value)
Next
Next
objExcel.Workbooks.Close()
objExcel.Quit()
objExcel = Nothing
End Sub
End class
|