[英]How do I code a drop down box to report to an excel file?
I have a simple question. 我有一个简单的问题。 I'm sure its easy to everyone... but me.
我敢肯定所有人都容易...但是我。 I can't get my drop down box to report the option that was chosen.
我无法在下拉框中报告所选的选项。 Can anyone help?
有人可以帮忙吗? This code is generic, but the one that is actually being used is similar to this one.
该代码是通用的,但实际使用的代码与此代码相似。 For some reason its not reporting the chosen option from the drop down box to the excel wb.
由于某种原因,它没有将下拉框中的所选选项报告给excel wb。 Can anyone let me know what I'm missing?
谁能让我知道我在想什么? Thanking you in advance!
预先感谢您!
<SCRIPT LANGUAGE=JAVASCRIPT>
var currentDate = new Date();
var date1 = currentDate.getDate();
var mon = currentDate.getMonth()+1;
var year = currentDate.getYear();
var today = mon+"/"+date1+"/"+year;
var filePath = "Somefile.xlsx";
function setDate() {
f1.tDate.value=today;
}
function saveToExcel() {
var myApp = new ActiveXObject("Excel.Application");
myApp.visible = false;
var xlCellTypeLastCell = 11;
var myWorkbook = myApp.Workbooks.Open(filePath);
var myWorksheet = myWorkbook.Worksheets(1);
myWorksheet.Activate;
objRange = myWorksheet.UsedRange;
objRange.SpecialCells(xlCellTypeLastCell).Activate;
newRow = myApp.ActiveCell.Row + 1;
strNewCell = "A" + newRow;
myApp.Range(strNewCell).Activate;
myWorksheet.Cells(newRow,1).value = f1.tDate.value;
myWorksheet.Cells(newRow,2).value = f1.tAgent.value;
myWorksheet.Cells(newRow,3).value = f1.tIssid.value;
myWorksheet.Cells(newRow,4).value = f1.tLOB.value;
myWorksheet.Cells(newRow,5).value = f1.tResp.value;
myWorksheet.Cells(newRow,6).value = f1.tResp.value;
myWorksheet.Cells(newRow,7).value = f1.tTaken.value;
myWorksheet.Cells(newRow,8).value = f1.tAlred.value;
myWorksheet.Cells(newRow,9).value = f1.tAlred.value;
myWorksheet.Cells(newRow,10).value = f1.tUnab.value;
myWorksheet.Cells(newRow,11).value = f1.tNotes.value;
myWorkbook.Close(true);
myApp.Workbooks.Close;
myApp.Close;
alert('Data successfully saved');
}
</SCRIPT>
<BODY onLoad="setDate()">
<form name="f1" method="post">
<h1>Some title</h1><br />
<h3>Payment Entry Log</h3>
<hr>
<table cellpadding="5" width="475">
<tr>
<td class="tb_bor"align="left" ><b>Date of Call</b><br />
<input type=text name=tDate ></td>
<td class="tb_bor" ><b>Entered By:<br /></b>
<select name="tAgent" id="tAgent" style="80% !important;">
<option value="Agent 1" >Agent 1</option>
<option value="Agent 2" >Agent 2</option>
<option value="Agent 3" >Agent 3</option>
<option value="Agent 4" >Agent 4</option>
<option value="Agent 5" >Agent 5</option>
<option value="Agent 6" >Agent 6</option>
<option value="Agent 7" >Agent 7</option>
<option value="Agent 8" >Agent 8</option>
<option value="Agent 9" >Agent 9</option>
<option value="Agent 10" >Agent 10</option>
</select>
</td>
</tr>
<tr>
<td class="tb_bor" ><b>Subscriber ID:</b></td>
<td align="left" ><input type=text name="tIssid" ></td>
</tr>
<tr>
<td class="tb_bor" ><b>L.O.B:<br /><br /></b>
<td align="left" >
<input id="az" type="radio" value="1" name="tLOB" >AZ<br />
<input id="ca" type="radio" value="2" name="tLOB" >CA<br />
<input id="or" type="radio" value="3" name="tLOB" >OR<br /><hr></td>
</tr>
<tr>
<td width="" class="tb_bor" ><b>Positive Response:<br /><br /></b>
<td align="left" width="235" >
<input id="yes" type="radio" value="4" name="tResp" >Yes<br />
<input id="no" type="radio" value="5" name="tResp" >No <b><font color="red" size="2">(Indicate only if negative response)</font></b><br /><hr></td>
</tr>
<tr>
<td width="" class="tb_bor" ><b>Was a payment taken? <br /><br /></b>
<td align="left" >
<input id="yes" type="radio" value="6" name="tTaken" >Yes<br />
<input id="no" type="radio" value="7" name="tTaken" >No <br /><hr></td>
</tr>
<tr>
<td width="225" class="tb_bor" ><b>Was a payment already made?<br /> <font color="red" size="2">(Must be located in systems, i.e. ABS, CHKSEA, LEDINQ, etc...)</font></b><br /><br /> </b>
<td align="left" >
<input id="yes" type="radio" value="8" name="tAlred" >Yes<br />
<input id="no" type="radio" value="9" name="tAlred" >No <br /><hr></td>
</tr>
<tr>
<td width="225" class="tb_bor" align="right"><b>Could the member be reached?<br /> <font color="red" size="2">(Busy, no awnser , wrong number etc please indicate)</font></b><br /><br /> </b>
<td align="left" >
<input id="yes" type="radio" value="10" name="tUnab" >Yes<br />
<input id="no" type="radio" value="11" name="tUnab" >No <br /><hr></td>
</tr>
<tr>
<td class="tb_bor" colspan="3" align="left"><b>Notes:</b><br />
<textarea rows="6" cols="55" name="tNotes" ></textarea><br />
<font color="red" size="2">(If a payment was taken, please add notes that were entered in the account)</font></td>
</tr>
</table>
<hr>
<table>
<tr>
<td align="center" colspan="2">
<input type="reset" name="Reset" value="Clear" >
<input type="button" name=save value="Submit" onClick='saveToExcel();'>
</td>
</tr>
</table>
</form>
</BODY>
The code actually worked for me. 该代码实际上为我工作。 I'm not sure what error you are receiving.
我不确定您收到什么错误。
What I did: 我做了什么:
The Excel file was updated appropriately upon inspection. 检查时已适当更新了Excel文件。
Also, you should be able to see any error messages from the running of your javascript code in Internet Explorer's "Developer Tools" using the "Console". 另外,您应该能够在Internet Explorer的“开发人员工具”中使用“控制台”查看运行JavaScript代码所产生的任何错误消息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.