Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 835 Vote(s) - 3.49 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Show the output on the speedometer

#1
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" />

<!-- language: lang-js -->

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!!!!!!
Reply

#2
A call to [`.Cells()`](

[To see links please register here]

) expects `RowIndex` followed by `ColumnIndex`. Common naming practices suggest `x` refers to the column, and `y` refers to the row. If that's right, then you are passing in your arguments in the wrong order. It should be:

var data = excel_sheet.Cells(y, x).Value;

---

I can't help but notice some other issues:

* You are using backslashes instead of slashes for one of your comments. That will result in a syntax error.
* You never use the file input - the path to the excel file is hard coded.
* You are passing a value to `drawWithexcelValue()`, but then you try to access a `value` property. Maybe you think you are passing a reference to the cell?
* You are passing a string to `setTimeout()` instead of a function reference. Technically, that's legal, but it's old school.
* Your `drawWithXValue()` functions are nearly identical. You should create one function that shares common functionality:

<!-- -->

function drawWithValue(val) {
iTargetSpeed = val || 0;
if (iTargetSpeed < 0) {
iTargetSpeed = 0;
} else if (iTargetSpeed > 80) {
iTargetSpeed = 80;
}
job = setTimeout(draw, 5);
}
function drawWithInputValue() {
drawWithValue(document.getElementById('txtSpeed').value);
}

Or, even a little more concise:

function drawWithValue(val) {
iTargetSpeed = Math.max(0, Math.min(80, val || 0));
job = setTimeout(draw, 5);
}
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through