I just want to know if there could be any way by which we can read a value from an .xls file using a .bat file. For eg:If i have an .xls named test.xls which is having two columns namely 'EID' and then 'mail ID'.Now when we give the input to the .xls the EID name.it should extract the mail id which corresponds to the EID and echo the result out.
我只想知道是否有任何方法可以使用.bat文件从.xls文件中读取值。例如:如果我有一个名为test.xls的.xls,它有两列,即“EID”,然后是“邮件ID”。现在我们将.xls的输入提供给EID名称。它应该提取邮件ID对应于EID并回显结果。
**EID** **MailID**
E22222 MynameisA@company.com
E33333 MynameisB@company.com
...
...
So by the above table,when i give the input to the xls file using my .bat file as E22222,it should read the corresponding mail ID as MynameisA@company.com and it should echo the value.
因此,通过上表,当我使用我的.bat文件作为E22222将输入提供给xls文件时,它应该读取相应的邮件ID为MynameisA@company.com,它应该回显该值。
So i hope i am able to present my doubt.Please get back to me for more clarifications.
所以我希望我能够表达我的疑问。请回复我,以获得更多的澄清。
Thanks and regards Maddy
谢谢并问候Maddy
4 个解决方案
#1
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.
直接使用传统的.bat文件无法做到这一点。但是,您可能会调查PowerShell,它旨在能够执行此类操作。 PowerShell与现有的Windows应用程序(如Excel)完美集成,可以提供轻松完成此操作所需的工具。
A quick search turned up this example of reading Excel files from PowerShell.
快速搜索出现了从PowerShell中读取Excel文件的示例。
#2
You can't do this directly from a batch file. Furthermore, to manipulate use Excel files in scripting you need Excel to be installed.
您无法直接从批处理文件执行此操作。此外,要在脚本中操作使用Excel文件,您需要安装Excel。
What you can do is wrap the Excel-specific stuff in a VBScript and call that from your batch.
您可以做的是将特定于Excel的内容包装在VBScript中并从批处理中调用它。
#3
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.
这在BAT中很难(非常接近不可能),特别是在使用原始XLS文件时,但即使在导出到CSV之后,使用脚本/编程语言(Perl,C,无论如何)也会更容易。
#4
You can do it with Alacon - command-line utility for Alasql database.
您可以使用Alacon - Alasql数据库的命令行实用程序来完成此操作。
It works with Node.js, so you need to install Node.js and then Alasql package:
它适用于Node.js,因此您需要安装Node.js然后安装Alasql包:
To take data from Excel file you can use the following command:
要从Excel文件中获取数据,可以使用以下命令:
> 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.
Fist参数是一个SQL-expresion,它从XLSX文件读取数据,标题和搜索数据为第二个参数值:“E22222”。该命令返回邮件ID值。
#1
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.
直接使用传统的.bat文件无法做到这一点。但是,您可能会调查PowerShell,它旨在能够执行此类操作。 PowerShell与现有的Windows应用程序(如Excel)完美集成,可以提供轻松完成此操作所需的工具。
A quick search turned up this example of reading Excel files from PowerShell.
快速搜索出现了从PowerShell中读取Excel文件的示例。
#2
You can't do this directly from a batch file. Furthermore, to manipulate use Excel files in scripting you need Excel to be installed.
您无法直接从批处理文件执行此操作。此外,要在脚本中操作使用Excel文件,您需要安装Excel。
What you can do is wrap the Excel-specific stuff in a VBScript and call that from your batch.
您可以做的是将特定于Excel的内容包装在VBScript中并从批处理中调用它。
#3
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.
这在BAT中很难(非常接近不可能),特别是在使用原始XLS文件时,但即使在导出到CSV之后,使用脚本/编程语言(Perl,C,无论如何)也会更容易。
#4
You can do it with Alacon - command-line utility for Alasql database.
您可以使用Alacon - Alasql数据库的命令行实用程序来完成此操作。
It works with Node.js, so you need to install Node.js and then Alasql package:
它适用于Node.js,因此您需要安装Node.js然后安装Alasql包:
To take data from Excel file you can use the following command:
要从Excel文件中获取数据,可以使用以下命令:
> 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.
Fist参数是一个SQL-expresion,它从XLSX文件读取数据,标题和搜索数据为第二个参数值:“E22222”。该命令返回邮件ID值。