我做的word词频统计
时间:2011-05-18
来源:互联网
今天用字典+excel排序做了个word词频统计程序,没想到速度这么快。
Sub word词频排序()
'首先请引用excel11,我的是office2003
Application.ScreenUpdating = False
Dim dic As Object
Dim i, s
Dim f()
Dim m()
Set dic = CreateObject("scripting.dictionary")
For Each i In ActiveDocument.Words
s = CStr(i)
If i <> Chr(13) Then
If dic.Exists(s) Then
dic.Item(s) = dic.Item(s) + 1
Else
dic.Add (s), 1
End If
End If
Next
f = dic.keys
m = dic.items
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
xlApp.Visible = True
With xlSheet
[a2].Resize(dic.Count, 1) = xlBook.Application.Transpose(f)
[b2].Resize(dic.Count, 1) = xlBook.Application.Transpose(m)
[a1].Resize(1, 2) = Array("词条名称 ", "找到个数")
Range("B2:B" & dic.Count).Select
Range("A2:B" & dic.Count).Sort Key1:=Range("B2"), Order1:=xlDescending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
SortMethod:=xlPinYin, DataOption1:=xlSortNormal
End With
Application.ScreenUpdating = True
End Sub
Sub word词频排序()
'首先请引用excel11,我的是office2003
Application.ScreenUpdating = False
Dim dic As Object
Dim i, s
Dim f()
Dim m()
Set dic = CreateObject("scripting.dictionary")
For Each i In ActiveDocument.Words
s = CStr(i)
If i <> Chr(13) Then
If dic.Exists(s) Then
dic.Item(s) = dic.Item(s) + 1
Else
dic.Add (s), 1
End If
End If
Next
f = dic.keys
m = dic.items
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
xlApp.Visible = True
With xlSheet
[a2].Resize(dic.Count, 1) = xlBook.Application.Transpose(f)
[b2].Resize(dic.Count, 1) = xlBook.Application.Transpose(m)
[a1].Resize(1, 2) = Array("词条名称 ", "找到个数")
Range("B2:B" & dic.Count).Select
Range("A2:B" & dic.Count).Sort Key1:=Range("B2"), Order1:=xlDescending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
SortMethod:=xlPinYin, DataOption1:=xlSortNormal
End With
Application.ScreenUpdating = True
End Sub
作者: sqhsqhli 发布时间: 2011-05-18
好玩。顶一下学习学习。
作者: 香川群子 发布时间: 2011-05-18
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28