Read a value from a .xls file using .bat files

て烟熏妆下的殇ゞ 提交于 2019-12-02 06:55:36

There is no facility to do this directly with traditional .bat files. However, you might investigate PowerShell, which is designed to be able to do this sort of thing. PowerShell integrates well with existing Windows applications (such as Excel) and may provide the tools you need to do this easily.

A quick search turned up this example of reading Excel files from PowerShell.

You can't do this directly from a batch file. Furthermore, to manipulate use Excel files in scripting you need Excel to be installed.

What you can do is wrap the Excel-specific stuff in a VBScript and call that from your batch.

This will be hard (very close to impossible) in BAT, especially when using the original XLS file, but even after an export to CSV it will be much easier to use a script/programming language (Perl, C, whatever) to do this.

You can do it with Alacon - command-line utility for Alasql database.

It works with Node.js, so you need to install Node.js and then Alasql package:

To take data from Excel file you can use the following command:

> node alacon "SELECT VALUE [mail ID] FROM XLS('mydata.xls', {headers:true}) 
                   WHERE EID = ?" "E2222"

Fist parameter is a SQL-expresion, which read data from XLSX file with header and search data for second parameter value: "E22222". The command returns mail ID value.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!