标题:[求助]怎样实现在VS.2005中导入EXCEL表,代码怎么样实现,
只看楼主
heyuqing0502
Rank: 1
等 级:新手上路
帖 子:24
专家分:0
注 册:2007-3-21
 问题点数:0 回复次数:4 
[求助]怎样实现在VS.2005中导入EXCEL表,代码怎么样实现,

刚学VB.NET,多多指教

搜索更多相关主题的帖子: EXCEL 代码 
2007-04-18 22:17
bygg
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:乖乖的心中
等 级:版主
威 望:241
帖 子:13555
专家分:3076
注 册:2006-10-23
得分:0 
你是想把数据导入到EXCEL中,还是想把数据从EXCEL中导出到其它的地方?

飘过~~
2007-04-19 09:48
liuminghui
Rank: 6Rank: 6
等 级:贵宾
威 望:20
帖 子:2882
专家分:0
注 册:2007-1-26
得分:0 
我感觉是把 Excel表中的内容导入到数据库中去

海鸽 is My Lover!!
2007-04-19 10:23
heyuqing0502
Rank: 1
等 级:新手上路
帖 子:24
专家分:0
注 册:2007-3-21
得分:0 
回复:(bygg)你是想把数据导入到EXCEL中,还是想把数...

把数据导入到EXCEL中去,

2007-04-21 22:22
hpu02zdh
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2007-5-12
得分:0 

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就出错了,请高手指点,

2007-06-08 21:38



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-132997-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.086087 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved