开发者

read XLS file through batch script

开发者 https://www.devze.com 2022-12-12 00:34 出处:网络
This works:- for /F\"开发者_如何学运维tokens=4 delims=skip=1\" %%x in (myfile.txt) DO echo %%x

This works:-

for /F  "开发者_如何学运维tokens=4 delims=    skip=1" %%x in (myfile.txt) DO echo %%x

But not this:-

for /F  "tokens=4 delims=    skip=1" %%x in (myfile.xls) DO echo %%x

How can i read xls without converting to tab saperated?

XLS = Excel file


if you want to do it with batch, for whatever reasons, you can export and save your xls file to comma separated (csv), then use delim=, in your batch for loop.


Whether you're talking about the binary .xls format or XML, parsing in a Windows batch file is basically going to be impractical. You should use a more appropriate tool. The closest thing to a Windows batch file which will be able to cope with this is probably PowerShell.

Batch files are okay for pretty simple tasks, but when you need to do anything with a bit more complexity, you should look to use something more powerful. (I'm not particularly fond of Windows batch files in the first place compared with, say, bash scripts - but sometimes they're the easiest way to get things done.)


If you have Excel installed, you can easily create a vbscript or PowerShell script for the task. The Windows command shell interpreter really isn't up to the task of parsing Excel files.

VBScript:

Set objExcel = CreateObject("Excel.Application")

PowerShell:

a = New-Object -comobject Excel.Application
0

精彩评论

暂无评论...
验证码 换一张
取 消