在Excel和JSON文件之间比较数据失败

时间:2019-04-02 02:38:57

标签: javascript jasmine protractor

我有两个文件,一个是JSON文件,另一个是MS-Excel文件。两个文件应该具有相同的数据,我正在尝试比较文件。我已经开发了下面应该可以解决问题的辅助函数。但是脚本失败,找不到单个匹配项。一个示例:在一种情况下,它无法通过以下日志来匹配名称:

  

学生姓名不匹配:993793117,Json:Eugene,Tobias中的姓名:&Excel:Eugene,Tobias:

名称是相同的,并且如果我从上述错误中复制名称并进行手动比较,它们将完全匹配。该如何解决?

this.fileComparisonXlJson = async function (Jsonfile, Excel){


    let Datafile = Jsonfile;
    await browser.wait(async function(){
        return await fs.existsSync(Datafile);

    }, 30*1000, "File has not downloaded in 30 seconds");

    let rawdata = fs.readFileSync(await Datafile);
    let data = await JSON.parse(rawdata);


    let excelFile = await Excel;

    await browser.wait(async function(){
        return await fs.existsSync(excelFile);

    }, 30*1000, "File has not downloaded in 30 seconds");

    let WB = await Workbook.xlsx.readFile(await excelFile);
    let WS = await WB.getWorksheet(1);
    let RC = await WS.actualRowCount;

    let a = 0;
    for (j=0;j<(RC-1); j++){
        jsonRecord = await data[j];
        for (i=2; i<RC+1; i++){

            const StudentID = 'A'+i;

            if (await Number(WS.getCell(StudentID))===await Number(jsonRecord['StudentID'])){
                 const StudentName = 'B'+i;
                 const Grade = 'C'+i;
                 const BaseSchool = 'D'+i;
                 const RegTeacher = 'E'+i;
                 const EsyStatus = 'F'+i;
                 const EsySite = 'G'+i;

                 if (await WS.getCell(StudentName) === await jsonRecord['Student Name'].trim()) {
                     a = a;
                 }else{
                     a = a+ '\n Student Name did not match for :'+ jsonRecord['StudentID'] + 'Name in Json:'+ await jsonRecord['Student Name'].trim() + ': & Name in Excel:'+await WS.getCell(StudentName)+':' ;
                 }
                 if (await WS.getCell(Grade) === await jsonRecord['Grade']) {
                     a = a;
                 }else{
                     a = a+ '\n Grade did not match for :'+ jsonRecord['StudentID'];
                 }
                 if (await WS.getCell(BaseSchool) === await jsonRecord['Base School']) {
                     a = a;
                 }else{
                     a = a+ '\n Base School did not match for :'+ jsonRecord['StudentID'];
                 }
                 if (await WS.getCell(RegTeacher) === await jsonRecord['Registering Teacher']) {
                     a = a;
                 }else{
                     a = a+ '\n Reg Teacher did not match for :'+ jsonRecord['StudentID'];
                 }
                 if (await WS.getCell(EsyStatus) === await jsonRecord['Esy Status']) {
                     a = a;
                 }else{
                     a = a+ '\n ESY Status did not match for :'+ jsonRecord['StudentID'];
                 }
                 if (await WS.getCell(EsySite) === jsonRecord['Esy Site Assigned']) {
                     a = a;
                 }else{
                     a = a+ '\n ESY Site did not match for :'+ jsonRecord['StudentID'];
                 }
             }else{

                 a = a+ '\n No Record found for the student  :'+ jsonRecord['StudentID'] + ' in the Excel file';
             }

        }

    }
return await a;
}

0 个答案:

没有答案