简体   繁体   English

如何在javascript中设置时间间隔

[英]how to set the time interval in javascript

I am using html5 and javascript..i have some code in which i am reading some value from excel file ..here is the code 我正在使用html5和javascript..i,其中一些代码是我从excel文件中读取一些值的。

 var xVal = 1;
 var yVal = 2

 function readdata(x,y) {
    x = xVal;
    y = yVal;
    try {
       var excel = new ActiveXObject("Excel.Application");
       excel.Visible = false;
       var excel_file = excel.Workbooks.Open("D:\\Test.xls");
       //alert(excel_file.worksheets.count);
       var excel_sheet = excel_file.Worksheets("Sheet1");

   for(i=0;i<5;i++)
   {
        var data = excel_sheet.Cells(i,2).Value;
        drawWithexcelValue(data);
       }        
}
catch (ex) {
    alert(ex);
}         

this is my code to read excel file ...while i am running it gives an error Expected";"..i dont know where do i keep the ; 这是我的代码,用于读取excel文件...在运行时,它会给出预期的错误“;” ..我不知道该在哪里保存;

We have for loop to evaluate next value ...i want to know that how to give time interval between every execution , say it will stop for particular time before taking next value..and secondly i am hardcoding the value i<5; 我们有for循环来评估下一个值...我想知道如何在每次执行之间给定时间间隔,说它将在获取下一个值之前的特定时间停止。.其次,我对值i <5进行硬编码; ..i want to know that is there any function through which i can read full excel file ... ..我想知道我有什么功能可以读取完整的Excel文件...

How are you defining "full file"? 您如何定义“完整文件”? Excel has very large number of possible rows, I think what you want is a loop that ends when you hit an empty row. Excel具有大量可能的行,我认为您想要的是一个循环,当您击中空行时该循环结束。

while(1) {
   var data = excel_sheet.Cells(i,2).Value;
   if(data === ''){ // or undefined?
        break;
    } else {
       drawWithexcelValue(data);
    }
}

You have not said what line creates the error, but the specific error message you receive suggests this line: 您没有说出哪一行会导致错误,但是您收到的特定错误消息提示了这一行:

var yVal = 2

which is missing a semi-colon at the end. 最后缺少分号。 JavaScript statements are semi-colon terminated. JavaScript语句以分号结尾。 This would not usually create an error though, unless you are using use strict . 除非您使用use strict ,但这通常不会产生错误。

You can investigate JavaScript's setInterval to create the delay(s).. once you've got the current code working. 一旦您使当前代码正常工作,就可以研究JavaScript的setInterval来创建延迟。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM