excel - Vbscript 将文本文件中的数据提取到 Excel 中
问题描述
我是 VBScript 的新手。我需要将文本文件转换为 Excel 文件。试了几天还是失败。
我在文本文件中有数千行,但是在“====Succeeded MML Command====”行之后,我只需要将某些数据,例如 NE 放在第一列,Time 在第二列,MML SN 在第三列是 MML 命令、Retcode、Explain_info、机柜号、子架号、插槽号、TX 通道号、VSWR(0.01) 在接下来的列中。也一直在读取从文本文件中提取数据到 Excel中的代码看起来不错,但我更喜欢使用 vbscript。
这是我所拥有的:
Dim objFSO
Dim TextFile
Dim TextRead
Dim Line, Line1, Line2, Line3
Dim Count
ExcelFilePath = "D:\Test\output.xlsx"
Set objExcel = CreateObject("Excel.Application")
objExcel.visible = true
Set objWB = objExcel.Workbooks.Open(ExcelFilePath)
Set SheetObject = objWB.Worksheets("Sheet1")
Const ForReading = 1
TextFile = "D:\Test\*.txt"
set objFSO = CreateObject("Scripting.FileSystemObject")
set TextRead = objFSO.OpenTextFile(TextFile,ForReading)
row = 2
With SheetObject
.Range(.Columns(1),.Columns(11)).NumberFormat = "@"
.Cells(1, 1).Value = "eNodeBName"
.Cells(1, 2).Value = "Time"
.Cells(1, 3).Value = "MML SN"
.Cells(1, 4).Value = "MML Command"
.Cells(1, 5).Value = "Retcode"
.Cells(1, 6).Value = "Explain_info"
.Cells(1, 7).Value = "Cabinet No."
.Cells(1, 8).Value = "Subrack No."
.Cells(1, 9).Value = "Slot No."
.Cells(1, 10).Value = "TX Channel No."
.Cells(1, 11).Value = "VSWR(0.01)"
End With
if instr(strText, "Succeeded") > 0 then
msgbox("Found it!")
end if
msgbox("DONE")
objWB.Save
objWB.Close
objExcel.Quit
解决方案
推荐阅读
- python - 如何让屏幕忽略某些图像的背景颜色?
- python - 无法对提供给加载的朴素贝叶斯模型的用户输入值进行编码?
- c++ - 尝试使用 OpenGL 制作 Endless Runner C++
- c# - Razor Tag Helper - 绑定到集合
- c++11 - 朋友别名模板不能用 clang 编译
- lua - 如何使用 lua 设置 cmusphinx?
- angular - 将应用程序发布到 IIS 后访问服务时出现 400 错误请求
- javascript - 使用 react-router 自定义动态路由
- excel - 使用带有 BeforeClose 的 msgbox 将数据导出到另一个工作簿
- search - Google Places API 可以进行模糊搜索吗