public class Test
public Shared Sub Main
Dim objExcel As Excel.Application
objExcel = New Excel.Application
Dim objSheet As New Excel.Worksheet
Dim objRange As Excel.Range
Dim intRow, intCol As Integer
objExcel.Visible = True
'Add a worksheet and then add some content to it.
objSheet = objExcel.Workbooks.Add.Worksheets.Add
With objSheet
.Cells(2, 1).Value = "1st Quarter"
.Cells(2, 2).Value = "2nd Quarter"
.Cells(2, 3).Value = "3rd Quarter"
.Cells(2, 4).Value = "4th Quarter"
.Cells(2, 5).Value = "Year Total"
.Cells(3, 1).Value = 123.45
.Cells(3, 2).Value = 435.56
.Cells(3, 3).Value = 376.25
.Cells(3, 4).Value = 425.75
.Range("A2:E2").Select()
With objExcel.Selection.Font
.Name = "Verdana"
.FontStyle = "Bold"
.Size = 12
End With
End With
'Set the alignment.
objSheet.Range("A2:E2").Select()
objExcel.Selection.Columns.AutoFit()
objSheet.Range("A2:E2").Select()
With objExcel.Selection
.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter
End With
'Format some numbers.
objSheet.Range("A3:E3").Select()
With objExcel.Selection.Font
.Name = "Verdana"
.FontStyle = "Regular"
.Size = 11
End With
'Display summary information.
objSheet.Cells(3, 5).Value = "=Sum(A3:D3)"
objRange = objSheet.UsedRange
For intCol = 1 To objRange.Columns.Count
For intRow = 1 To objRange.Rows.Count
Console.WriteLine(objRange.Cells(intRow, intCol).value)
Next
Next
objExcel.Workbooks.Close()
objExcel.Quit()
objExcel = Nothing
End Sub
End class
|