...

View Full Version : Javascript function getting values from Excel 2003 sheet



kamila
02-01-2007, 03:54 PM
Hi,
I am new to use with Javascript. i make this script to get value from Excel sheet but it is not working plz check this and guide me that where is i am doing some thing wrong. In Excel sheet i have 3000 ID values to pass in this function to get all right or corrcet ID numbers. Excel file and html file is on the my local harddrive "C".

<html>
<head>
<title>checking ID number formula </title>
</head>
<body>

<form>
<INPUT TYPE="button" CLASS="button" NAME="bname" VALUE="ID Number" onClick="(ValidateID())"><br>
</form>

<script type="text/jscript">

function ValidateID()
{
var A1
var excel = new ActiveXObject("Excel.Application");
var excel_file = excel.Workbooks.Open("C:\\ids1.xls");
var excel_sheet = excel.Worksheets("Sheet1");
var ID = excel_sheet.Cells(A1,A1).Value;

var TmpStr
var Tmpr
var vekt1 = "376189452"
var vekt2 = "5432765432"
var tot = 0
var base = 11
var value
var vekt
var TmpStr2
var Tmpr2
var vekt2 = "5432765432"
var tot2= 0
var base = 11

// for first number
for (i=0;i<9 ;i++)
{
value = ID.substr(i,1)
vekt = vekt1.substr(i,1)
tot = tot + (parseInt(value) * parseInt(vekt))
}
i=tot/11
i=tot-(parseInt(i)*11)
i=11-i
TmpStr = ID
TmpStr = ID.substr(9,1)
Tmpr=(ID.length)

// for second number
for (y = 0; y < 10 ; y++)
{
value = ID.substr(y,1)
vekt = vekt2.substr(y,1)
tot2 = tot2 + (parseInt(value) * parseInt(vekt))
}
y=tot2/11
y=tot2-(parseInt(y)*11)
y=11-y
TmpStr2 = ID
TmpStr2 = ID.substr(10,1)
Tmpr2=(ID.length)

// integer check

if (base!=Tmpr)
{
document.write("You must enter 11 number for ID (0 - 9) ")
}
else if ( parseInt(i)==TmpStr && parseInt(y)==TmpStr2)
{
document.write(ID)
}
else
{
document.write("Obs!! You write wrong ID number!")
}

}

</script>
</body>
</html>


I am sending few number for checking working

06084718767
15056021762
12065032304
09177539088
41575227037

i am also sending attach zipfile with html file and excel file.

best regards,

Kamila



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum