加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

VB,以及VB.NET自动化EXCEL

发布时间:2020-12-16 23:01:12 所属栏目:大数据 来源:网络整理
导读:最近由于工作关系,要从网站下载数据,填一个EXCEL,我一下子头大了。数据量太大。 最后写了个程序,发现EXCEL调用起来,挺方便,感觉很爽,thrilling! vb6.0代码: Dim xls As Excel.Application Set xls = CreateObject("excel.application") Dim xlbook A

最近由于工作关系,要从网站下载数据,填一个EXCEL,我一下子头大了。数据量太大。

最后写了个程序,发现EXCEL调用起来,挺方便,感觉很爽,thrilling!

vb6.0代码:

Dim xls As Excel.Application
Set xls = CreateObject("excel.application")
Dim xlbook As Excel.Workbook
Dim xlbooksource As Excel.Workbook
Dim xlsheet As Excel.Worksheet
Set xlbook = xls.Workbooks.Open("C:/end.xls")
Set xlbooksource = xls.Workbooks.Open("C:/book1.xls")
Dim sheet2 As Excel.Worksheet
Dim Num As Integer
'Set xlsheet = xlbook.Worksheets("户县")
Set xlsheet = xlbook.Worksheets("市区")
xlsheet.Activate
Dim column As Integer
For column = 0 To 4
Set sheet2 = xlbooksource.Worksheets(1 + column)
Dim i As Byte
Dim j As Byte
Dim station As String
Dim count As Integer
Dim sum As Double
sum = 0
count = 0
For i = 3 To xlsheet.UsedRange.Rows.count
station = CStr(xlsheet.Cells(i,1))
station = Trim(station)
Debug.Print (station)
For j = 1 To sheet2.UsedRange.Rows.count
If Trim(CStr(sheet2.Cells(j,4))) = station Then
xlsheet.Cells(i,3 + column) = sheet2.Cells(j,8)
sum = sum + xlsheet.Cells(i,3 + column)
count = count + 1
Exit For
End If
Next
If station = "平均" Then
xlsheet.Cells(i,3 + column) = sum / count
Exit For
End If
Next
Next
xlbook.SaveAs ("C:/test.xls")
xls.Quit

VB.NET 下面代码:

.NET下面没有的CELL不能直接赋值,应该

把:cell(i,j)=xxx

改成:cell(i,j).Value= xxx

才成!

其它再无什么大的变化。

直接移值即可。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读