如何在hta中使用vbscript 标识checkbox的状态(checked value)

这里是读取excel数据并将数据导入到hta表中的代码,并将编辑后的数据从hta写入excel ,在我的hta页面 Excel示例数据 看起来像这样,如果我select所需的checkbox并单击Click To Writebutton,数据按“是”或“否”存储在Excel表格中。

 <!DOCTYPE html> <head> <HTA:application Applicationname="MyApp" BORDER="thin" BORDERSTYLE="Normal" Caption="yes" ICON="D:\VBScriptTrainee\Ampeross-Qetto-Icon-developer.ico" MAXIMIZEBUTTON="yes" MINIMIZEBUTTON="yes" SINGLEINSTANCE="no" NAVIGABLE="yes" SYSMENU="yes" VERSION="2.0" WINDOWSTATE="maximize"/> <title>Read Excel</title> <link rel="stylesheet" href="D:\VBScriptTrainee\bootstrap-3.3.6-dist\css\bootstrap.min.css"> <style type="text/css"> body { background-color:#1abc9c; } P { font:bold 18px arial; } </style> <script language="vbscript"> Public mySpan,selectexcel,objExcel,objWorkbook,rowCount,colCount,rowData,textData,sp,b,tempcol,checkData,i,j On error resume next Sub ReadExcelData() Set fileexcel =document.getelementbyid("file_id") file2=fileexcel.value 'selectexcel = inputbox("Enter the path","path here","D:\VBScriptTrainee\Sample.xlsx") Set objExcel = CreateObject("Excel.Application") Set objWorkbook = objExcel.Workbooks.open(file2) objExcel.visible = True rowCount=objExcel.ActiveWorkbook.Sheets(1).UsedRange.Rows.Count colCount=objExcel.ActiveWorkbook.Sheets(1).UsedRange.Columns.Count Dim mySpan 'colCount=colCount+1 tempcol=colCount 'MsgBox(tempcol) 'MsgBox(colCount) rowData="<table border=2>" For intRow=1 to rowCount step 1 'rowData=null rowData = rowData & "<tr>" For intCol=1 to colCount step 1 'if ((intRow =1) and (intCol=tempcol)) then 'objExcel.Cells(intRow,tempcol).Value = "Flag" 'intRow =IntRow + 1 'End if If ((intRow <> 1) and (intCol = tempcol)) then 'objExcel.Cells(1,tempcol).Value = "Flag" rowData = rowData & "<td>" & "<input type='checkbox' id='flag_id' name='flag' />" & "</td>" 'checkData = cStr(rowData) End If If (intRow=1) Then rowData= rowData & "<td>" & "<b><font color=red>" & objExcel.Cells(intRow,intCol).Value & "</font></b>" & "</td>" Else rowData = rowData & "<td><div contentEditable='True'>" & objExcel.Cells(intRow,intCol).Value & "</div></td>" End If Next rowData = rowData & "</tr>" Next rowData =rowData & "</table>" Set mySpan=document.getelementbyid("Span_id_two") mySpan.innerHTML = rowData & "<br>" 'Set myExcel=document.getelementbyid("selectfile") 'myExcel.innerHTML = selectexcel MsgBox "Data readed successfully",vbInformation document.getElementById("file_id").accept = ".xlsx" End sub Sub WriteExcelData() mwresult = Msgbox ("Are you Sure to Write ?",vbOKCancel) If (mwresult=1) then Set mySpan=document.getelementbyid("Span_id_two") textData=mySpan.innerHTML Set tab=document.getElementsByTagName("table")(0) mytable = document.getElementsByTagName("table")(0).rows.length Msgbox("myTable (rows Length) " & mytable) mytable1= document.getElementsByTagName("table")(0).rows(0).cells.length Msgbox("myTable1 (rows Cells Length) " & mytable1) For n = 0 to (mytable-1) For j = 0 To (mytable1-1) objExcel.Cells (n + 1, j + 1).Value = tab.Rows(n).Cells(j).innerHTML tableValue = tab.Rows(n).Cells(j).innerHTML If(tableValue="<INPUT id=flag_id type=checkbox CHECKED name=flag>") then objExcel.Cells (n+1,mytable1).Value="Yes" End If If(tableValue="<INPUT id=flag_id type=checkbox name=flag>") then objExcel.Cells (n+1,mytable1).Value="No" End If Next Next find ="<*>" rplace =" " objExcel.Cells.Replace find,rplace MsgBox "Data Exported Successfully",vbInformation objExcel.ActiveWorkbook.Save Set objExcel=nothing End If If(mwresult=2) then MsgBox "You Selected Cancel",vbInformation End If End sub </script> </head> <body> <center> <img src="D:\VBScriptTrainee\Excel.png" height=200 width=300/> </center> <center> <h1 align="center" style="color:blue"><img src="D:\VBScriptTrainee\icon-developer-icon.png" height=100px width=100px/> Read Excel**</h1><br> <a style="a.link:red;a.hover:green;a.visited:blue;" href="D:\VBScriptTrainee\Hta_Rules.hta">Rules*</a><br><br> <input class="btn btn-primary text-primary" type="file" id="file_id" name="file_id" accept=".xlsx"> <br> <button class="btn btn-success" name="Read" value="Click To Read" onclick="ReadExcelData()">Click To Read</button> <button class="btn btn-danger" name="Write" value="Click To Write" onclick="WriteExcelData()">Click To Write</button> <br> <br> <p id="selectfile"></p> <span ID="Span_id_two" Style="Color:blue;" name="text_name"> </span> </div> </div> </div> </center> <marquee direction="Right" style="color:red;">***Note : Select only excel files***</marquee> </body> </html> 

但是,我已经通过给出html格式来识别select的检查值数据,就像这样

从上面的编码

 If(tableValue="<INPUT id=flag_id type=checkbox CHECKED name=flag>") then objExcel.Cells (n+1,mytable1).Value="Yes" End If If(tableValue="<INPUT id=flag_id type=checkbox name=flag>") then objExcel.Cells (n+1,mytable1).Value="No" End If 

是否有其他方法来确定checkbox的状态(checkbox是否被选中)。

这是我的Excel表格

ExcelSheet

toCelcius的函数定义有错误的语法

  function toCelsius(f) { //removed var return (5/9) * (f-32); } 

您的debugging器工具(如控制台)可与您的浏览器一起轻松find这些问题。

当你在JavaScript中定义一个函数时,你不必像在强types语言中那样包含某种“types”。 所以在toCelsius参数列表中添加var导致错误。 将其更改为:

function toCelsius(f)