我对整个批处理脚本的事情很陌生,但我真的很喜欢它。我一直在使用批处理 scrip 并将常量 ping 结果以及时间戳输出到.txt文件中,但我想输出到.xlsx。这是我一直在使用的脚本。
@echo off
title Google Ping
mode 12,1
:start
set DT=%date:/=-%
timeout /t 30
echo %time% %date% >> C:UsersBradleyDesktopLogsgoogle_log%DT%.txt
ping -n 1 8.8.8.8 >> C:UsersBradleyDesktopLogsgoogle_log%DT%.txt
goto start
任何帮助将不胜感激。
没有本机方法可以使用纯批处理文件读取和写入 Excel 文件。你可以用Vbscript和Powershell来做到这一点。 但我觉得最简单的选择就是把它写到 csv 文件中。通常CSV文件默认使用Excel打开。
@echo off
title Google Ping
echo date,time,ip,bytes,pingtime,ttl>pinglog.csv
:begin
FOR /F "tokens=3-6 delims=: " %%G IN ('ping -n 1 8.8.8.8^|find /i "reply from"') DO (
SET ip=%%G
SET %%H
SET ping%%I
SET %%J
)
>>pinglog.csv echo %date%,%time%,%ip%,%bytes%,%pingtime%,%TTL%
timeout /t 10 >nul
GOTO begin
我自己也做了一些非常相似的事情。 我用以下内容制作了一个.txt文件:
C:
cdUsersgarysDocumentsMy Spreadsheets
dir /s /b > %userprofile%DesktopdirectrySpreadsheetFiles.txt
然后通过以下方式将其放入 Excel:
Sub GetData()
Dim s As String, Textline As String, i As Long
Dim RC As Long
s = Application.GetOpenFilename()
RC = Rows.Count
Range("B2:F" & RC).Clear
Range("A2:A" & RC).ClearContents
Close #1
Open s For Input As #1
i = 2
Do While Not EOF(1)
Line Input #1, Textline
Cells(i, "C").Value = Textline
i = i + 1
Loop
Close #1
End Sub
材料进入 C 列,在顶部为标题留出空间。