I have to read an Excel file and show the output on a speedometer. I have taken the input, and here is my HTML and scripting code, the Excel file contains name and value:
<input type="text" id="txtSpeed" name="txtSpeed" value="20" maxlength="2" />
<input type="button" value="Draw" onclick="drawWithInputValue();">
<input type="file" id="file" onchange="checkfile(this);" />
<input type="button" id="btnSubmit" onclick="readdata(1, 2)" value="Submit" />
function checkfile(sender) {
var validExts = new Array(".xlsx", ".xls", ".csv");
var fileExt = sender.value;
fileExt = fileExt.substring(fileExt.lastIndexOf('.'));
if (validExts.indexOf(fileExt) < 0) {
alert("Invalid file selected, valid files are of " +
validExts.toString() + " types.");
return false;
}
else return true;
}
function readdata(x,y) {
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");
var data = excel_sheet.Cells(x, y).Value;
//alert(data);
drawWithexcelValue(data);
}
catch (ex) {
alert(ex);
}
// return data;
}
and for the speedometer here is the code
function drawWithInputValue() {
var txtSpeed = document.getElementById('txtSpeed');
alert(txtSpeed.value);
if (txtSpeed !== null) {
iTargetSpeed = txtSpeed.value;
// Sanity checks
if (isNaN(iTargetSpeed)) {
iTargetSpeed = 0;
} else if (iTargetSpeed < 0) {
iTargetSpeed = 0;
} else if (iTargetSpeed > 80) {
iTargetSpeed = 80;
}
job = setTimeout("draw()", 5);
}
}
function drawWithexcelValue(val) {
var txtSpeed = val;
if (txtSpeed !== null) {
iTargetSpeed = txtSpeed.value;
// Sanity checks
if (isNaN(iTargetSpeed)) {
iTargetSpeed = 0;
} else if (iTargetSpeed < 0) {
iTargetSpeed = 0;
} else if (iTargetSpeed > 80) {
iTargetSpeed = 80;
}
job = setTimeout("draw()", 5);
}
}
So i am getting the file excel file ,and through this excel file the values should be shown on speedometer .But while clicking on submit button the niddle of speedometer goes down to 0..it is not showing the values of excel file on speedometer..
function checkfile(sender) is for the validation function readdata(x,y) is for the reading of excel file function drawWithInputValue() is for the output manually..like ,suppose you have enter 40 value in text name"txtspeed" then on clicking on Draw button it will show the value in speedometer by rotating the niddle
function drawWithexcelValue(val) is for the reading excel file and show its value in the output..
here is the problem .. suppose we have some name and values in the excel file which is as follows name values India 35 china 46 U.S.A 73 so now by clicking on the submit button it has to show 35 first and the 46 and the 73 with the names ..but what is happening according to my code is while clicking the submit button it doesn't show the value from the excel file it just show zero...HELP!!!!!!