2017-10-21 313 views
1

我是這批整批腳本編程的新手,但我真的很喜歡它。我一直在使用批處理腳本,並將恆定的ping結果以及時間戳輸出到.txt文件,但希望輸出到.xlsx。這是我一直在使用的腳本。將批處理結果輸出爲excel

@echo off 

title Google Ping 

mode 12,1 

:start 

set DT=%date:/=-% 

timeout /t 30 

echo %time% %date% >> C:\Users\Bradley\Desktop\Logs\google_log%DT%.txt 

ping -n 1 8.8.8.8 >> C:\Users\Bradley\Desktop\Logs\google_log%DT%.txt 

goto start 

任何幫助將不勝感激。

回答

0

我自己做的事情非常相似。我做一個的.txt文件有:

C: 
cd\Users\garys\Documents\My Spreadsheets 
dir /s /b > %userprofile%\Desktop\directry\SpreadsheetFiles.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列,在頂部的頭留出空間。

1

沒有本地的方式來讀取和寫入純批處理文件的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 
相關問題