使用VBScript读取Excel文件并写入
上一篇 /
下一篇 2011-06-23 18:41:27 / 天气: 舒适
/ 心情: 平静
/ 精华(1)
打开记事本,输入以下文字
dim xlApp,xlWorkBook,xlSheet
dim iRowCount,iLoop,numAdd
Set xlApp=CreateObject("Excel.Application")
xlApp.Visible=true
Set xlWorkBook=xlApp.Workbooks.Open("C:\data.xls")
Set xlSheet= xlWorkBook.Sheets("Sheet1")
iRowCount = xlSheet.usedRange.Rows.Count
for iLoop=10 to iRowCount
numAdd = numAdd&xlSheet.Cells(iLoop,3)
Next
xlSheet.Cells(2,2)=RegExpTest("a", numAdd)
xlSheet.Cells(3,2)=RegExpTest("b", numAdd)
xlSheet.Cells(4,2)=RegExpTest("c", numAdd)
xlSheet.Cells(5,2)=RegExpTest("d", numAdd)
xlSheet.Cells(6,2)=RegExpTest("e", numAdd)
xlWorkBook.Save
xlWorkBook.Close
xlApp.Quit
Set xlSheet= Nothing
set xlWorkBook= Nothing
Set xlApp= Nothing
'以下是根据正则表达式来得到一个字符串在另一个字符串中出现几次的
Function RegExpTest(patrn, strng)
Dim regEx, Matches
Set regEx = New RegExp
regEx.Pattern = patrn
regEx.IgnoreCase = true '为真则忽略大小写,否则严格匹配大小写
regEx.Global = true
Set Matches = regEx.Execute(strng)
RegExpTest = Matches.count
End Function
收藏
举报
TAG: