使用用户提示输入函数
input function using user prompt
这个问题我之前发过,没有成功。
我有一些行使一个用户菜单从 exceljs 获取数据。
1 - 如何将 while 条件放入此函数中,以获取所有行到菜单?看起来 switch(input) 不接受循环。
逻辑是:
* 阅读 costumers.xlsx 以获取所有客户。
*循环所有客户作为菜单选项。
* 选择后,它会打开另一个 xlsx 文件,其中包含所选客户的名称
IE:
1 - 顾客 1
2 - 顾客 2
如果我选择 1 我会打开 costumer1.xlsx
2 - 如何选择并作为字符串传递以打开 xlsx?
wb_costumers.xlsx.readFile('costumers.xlsx').then(function(){
sh_costumers = wb_costumers.getWorksheet("Sheet1");
var ic = 2;
while (ic <= sh_costumers.rowCount){
console.log("Row " + sh_costumers.getRow(ic).getCell(1) + " - " + sh_costumers.getRow(ic).getCell(2));
ic++;
}
});
function processChoice(input){
return new Promise(function(resolve, reject) {
var error = undefined;
var func;
switch(input){
case sh_costumers.getRow(2).getCell(1).text :
func = addPreset;
break;
经过一些研究,我发现了一些关于提示(npm install prompt)的东西。
现在我可以在 xlsx 文件中读取我的客户配置。
在工作簿上 costumers.xlsx 我有两列:
cell1 = id
cell2 = 客户姓名
在工作簿 check_(costumer's name).xlsx 上,我有我想放在某个地方的信息。
这是我的代码。
const prompt = require('prompt');
var Excel = require('exceljs');
var wb = new Excel.Workbook();
var wbc = new Excel.Workbook();
prompt.start();
var ic = 1;
wbc.xlsx.readFile('costumers.xlsx').then(function(){
shc = wbc.getWorksheet("Sheet1");
while (ic <= shc.rowCount){
console.log(shc.getRow(ic).getCell(1).value +" - "+ shc.getRow(ic).getCell(2).value);
ic++;
}
});
prompt.get(['costumer'], function (err, result) {
if (err) { return onErr(err); }
var costumer = shc.getRow(result.costumer).getCell(2).value;
wb.xlsx.readFile('check_'+costumer+'.xlsx').then(function(){
sh = wb.getWorksheet("Sheet1");
console.log(sh.getRow(2).getCell(3).value);
});
});
function onErr(err) {
console.log(err);
return 1;
}
这个问题我之前发过,没有成功。
我有一些行使一个用户菜单从 exceljs 获取数据。
1 - 如何将 while 条件放入此函数中,以获取所有行到菜单?看起来 switch(input) 不接受循环。
逻辑是: * 阅读 costumers.xlsx 以获取所有客户。 *循环所有客户作为菜单选项。 * 选择后,它会打开另一个 xlsx 文件,其中包含所选客户的名称 IE: 1 - 顾客 1 2 - 顾客 2 如果我选择 1 我会打开 costumer1.xlsx
2 - 如何选择并作为字符串传递以打开 xlsx?
wb_costumers.xlsx.readFile('costumers.xlsx').then(function(){
sh_costumers = wb_costumers.getWorksheet("Sheet1");
var ic = 2;
while (ic <= sh_costumers.rowCount){
console.log("Row " + sh_costumers.getRow(ic).getCell(1) + " - " + sh_costumers.getRow(ic).getCell(2));
ic++;
}
});
function processChoice(input){
return new Promise(function(resolve, reject) {
var error = undefined;
var func;
switch(input){
case sh_costumers.getRow(2).getCell(1).text :
func = addPreset;
break;
经过一些研究,我发现了一些关于提示(npm install prompt)的东西。
现在我可以在 xlsx 文件中读取我的客户配置。
在工作簿上 costumers.xlsx 我有两列:
cell1 = id cell2 = 客户姓名
在工作簿 check_(costumer's name).xlsx 上,我有我想放在某个地方的信息。
这是我的代码。
const prompt = require('prompt');
var Excel = require('exceljs');
var wb = new Excel.Workbook();
var wbc = new Excel.Workbook();
prompt.start();
var ic = 1;
wbc.xlsx.readFile('costumers.xlsx').then(function(){
shc = wbc.getWorksheet("Sheet1");
while (ic <= shc.rowCount){
console.log(shc.getRow(ic).getCell(1).value +" - "+ shc.getRow(ic).getCell(2).value);
ic++;
}
});
prompt.get(['costumer'], function (err, result) {
if (err) { return onErr(err); }
var costumer = shc.getRow(result.costumer).getCell(2).value;
wb.xlsx.readFile('check_'+costumer+'.xlsx').then(function(){
sh = wb.getWorksheet("Sheet1");
console.log(sh.getRow(2).getCell(3).value);
});
});
function onErr(err) {
console.log(err);
return 1;
}