刚学VB.NET,多多指教
Call killEXCEL()
Dim excelApp As New Microsoft.Office.Interop.Excel.Application
Dim excelBook As Microsoft.Office.Interop.Excel.Workbook
Dim excelWorksheet As Microsoft.Office.Interop.Excel.Worksheet
Try
excelBook = excelApp.Workbooks.Open(Application.StartupPath & "\1.xls")
excelWorksheet = excelBook.Sheets.Item(1)
excelApp.Visible = True
excelWorksheet.Activate()
With excelWorksheet
.Range(.Cells(1, 1), .Cells(1, 8)).Merge()
.Range(.Cells(2, 1), .Cells(2, 8)).Merge()
.Cells.HorizontalAlignment = Right
.Cells(1, 1).Value = classname & year & term & "课表"
.Cells(1, 1).Font.Size = 20
.Cells(1, 1).Font.bold = True
.Cells(2, 1).Value = Today.ToString
End With
With excelWorksheet
For i As Integer = 0 To 6
.Cells(3, i + 2).value = cmbdayofweek.Items.Item(i)
Next
For i As Integer = 0 To 7
.Cells(i + 4, 1).value = cmbtimeperiod.Items.Item(i)
Next
End With
Dim node As TreeNode
Dim node1 As TreeNode
Dim node2 As TreeNode
Dim node3 As TreeNode
Dim node4 As TreeNode
For Each node In TreeView1.Nodes()
For Each node1 In node.Nodes()
For Each node2 In node1.Nodes()
For Each node3 In node2.Nodes()
For i As Integer = 0 To 6
If node3.Text = excelWorksheet.Cells(3, i + 2).value Then
For Each node4 In node3.Nodes()
Dim IDItem(3) As String
IDItem = node4.Text.Split("|"c)
For j As Integer = 0 To 7
If IDItem(1) = excelWorksheet.Cells(j + 4, 1).value Then
excelWorksheet.Cells(j + 4, i + 2).value() = IDItem(2)
End If
Next
Next
End If
Next
Next
Next
Next
Next
'For i As Integer = 0 To 18
' excelBook.ActiveSheet.cells(4 + i, 4) = allNum(i)
' Next
Catch ex As Exception
WriteErr(ex)
Finally
excelBook = Nothing
excelWorksheet = Nothing
excelApp = Nothing
End Try
End Sub
这个程序是往EXCEL中写课程表的,我用的是vb.net2005版本的,可是运行出错,请指点,Dim excelBook As Microsoft.Office.Interop.Excel.Workbook
Dim excelWorksheet As Microsoft.Office.Interop.Excel.Worksheet
这两行不运行,运行到.Cells.HorizontalAlignment = Right就出错了,请高手指点,