windows 通过批处理脚本读取XLS文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1781467/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 13:28:51  来源:igfitidea点击:

read XLS file through batch script

windowsexcelbatch-file

提问by kv.

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?

XLS = Excel file

XLS = Excel 文件

回答by ghostdog74

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.

如果您想使用批处理来执行此操作,无论出于何种原因,您都可以将您的 xls 文件导出并保存为逗号分隔 (csv),然后在您的批处理中使用 delim=, 进行循环。

回答by brianegge

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.

如果您安装了 Excel,则可以轻松地为该任务创建 vbscript 或 PowerShell 脚本。Windows 命令外壳解释器确实无法完成解析 Excel 文件的任务。

VBScript:

脚本:

Set objExcel = CreateObject("Excel.Application")

PowerShell:

电源

a = New-Object -comobject Excel.Application

回答by Jon Skeet

Whether you're talking about the binary .xls format orXML, 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.

无论您谈论的是二进制 .xls 格式还是XML,在 Windows 批处理文件中进行解析基本上是不切实际的。您应该使用更合适的工具。最接近 Windows 批处理文件的可能是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.)

批处理文件适用于非常简单的任务,但是当您需要做一些更复杂的事情时,您应该考虑使用更强大的东西。(与 bash 脚本相比,我一开始并不是特别喜欢 Windows 批处理文件 - 但有时它们是完成任务的最简单方法。)