Advertisement
Advertisement
| 01.15.2008 at 08:30AM PST, ID: 23084409 |
|
[x]
Attachment Details
|
||
|
[x]
The Solution Rating System
|
||
With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.
Your Input Matters If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support. Thank you! |
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: |
option strict off
imports System
imports System.Reflection ' For Missing.Value and BindingFlags
imports System.Runtime.InteropServices ' For COMException
Imports Microsoft.Office.Interop.Excel
class AutoExcel
public shared sub Main()
Console.WriteLine ("Creating new Excel Application")
Dim app As Application
app = New Application()
if app is nothing then
Console.WriteLine("ERROR: EXCEL couldn't be started!")
environment.exitcode = 0
exit sub
end if
Console.WriteLine ("Making application visible")
app.Visible = true
Console.WriteLine ("Getting the workbooks collection")
Dim workbooks As Workbooks
workbooks = app.Workbooks
Console.WriteLine ("Adding a new workbook")
Dim workbook As _Workbook
workbook = workbooks.Add(XlWBATemplate.xlWBATWorksheet)
Console.WriteLine ("Getting the worksheets collection")
Dim sheets As Sheets
sheets = workbook.Worksheets
Dim worksheet As _Worksheet
worksheet = sheets.Item(1)
if worksheet is nothing then
Console.WriteLine ("ERROR: worksheet == null")
end if
Console.WriteLine ("Setting the value for cell")
dim range as Object 'Range
range = worksheet.Range("A10", Missing.Value)
if range is nothing then
Console.WriteLine ("ERROR: range == null")
end if
range.Value2 = 5
' This paragraph sends single dimension array to Excel
Dim range2 as Object
range2 = worksheet.Range("A1", "E1")
Dim array2(5) as Integer
Dim i As Integer
For i = 0 To 4
array2(i) = i+1
Next i
range2.Value2 = array2
' This paragraph sends two dimension array to Excel
Dim range3 as Object
range3 = worksheet.Range("A2", "E3")
Dim array3(2, 5) as Integer
Dim j As Integer
For i = 0 To 1
For j = 0 To 4
array3(i, j) = i*10+j
Next j
Next i
range3.Value2 = array3
' This paragraph reads two dimension array from Excel
Dim range4 as Object
range4 = worksheet.Range("A2", "E3")
Dim array4(,) as Object
array4 = range4.Value2
For i = array4.GetLowerBound(0) To array4.GetUpperBound(0)
For j = array4.GetLowerBound(1) To array4.GetUpperBound(1)
if CDbl(array4(i, j)) <> array3(i-1, j-1) then
environment.exitcode = 0
Console.WriteLine ("ERROR: Comparison FAILED!")
exit sub
end if
Next j
Next i
' This paragraph sends two dimension array to Excel
Dim range5 as Object
range5 = worksheet.Range("A5", "J6")
Dim array5(2, 10) as Double
For j = 0 To array5.GetUpperBound(1)
Dim arg as Double
arg = Math.PI/array5.GetLength(1) * j
array5(0, j) = Math.Sin(arg)
array5(1, j) = Math.Cos(arg)
Next j
range5.Value2 = array5
' The following code draws the chart
range5.Select
Dim chartobjects as Object
chartobjects = worksheet.ChartObjects(Missing.Value)
Dim chartobject as Object
chartobject = chartobjects.Add(10, 100, 450, 250)
Dim chart as Object
chart = chartobject.Chart
chart.ChartWizard(range5, XlChartType.xl3DColumn, Missing.Value, XlRowCol.xlRows, 0, 0, True, "Sample Chart", _
"Sample Category Type", "Sample Value Type")
Console.WriteLine ("Press ENTER to finish the sample:")
Console.ReadLine()
Try
' If user interacted with Excel it will not close when the app object is destroyed, so we close it explicitely
workbook.Saved = true
app.UserControl = false
app.Quit()
Catch Outer As COMException
Console.WriteLine ("User closed Excel manually, so we don't have to do that")
End Try
environment.exitcode = 100
Console.WriteLine ("Sample successfully finished!")
end sub
end class
|