简体   繁体   English

如何编写一个下拉框报告到Excel文件?

[英]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: 我做了什么:

  1. Opened the html file on a PC (Windows 8) from Internet Explorer, being sure to enable ActiveX when presented with the option. 从Internet Explorer在PC(Windows 8)上打开html文件,请确保在显示该选项时启用ActiveX。
  2. Created the Excel file, put it in the same location as the html file and closed it. 创建Excel文件,将其放置在与html文件相同的位置,然后将其关闭。
  3. Updated the path to the Excel file in the javascript. 在javascript中将Excel文件的路径更新为。 I used an absolute path (beginning at "C:/") and used forward slashes only. 我使用了绝对路径(从“ C:/”开始),并且仅使用正斜杠。
  4. Changed the selection in the drop down box in Internet Explorer and then clicked "Post" with different selections. 在Internet Explorer的下拉框中更改了选择,然后单击具有不同选择的“发布”。

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.

相关问题 如何根据另一个下拉框在下拉框中创建列表? - How do I make a list in a drop down box depending on another drop down box? 如何仅使用 Javascript 创建动态下拉框? - How do I create a dynamic drop down box with just Javascript? 如何根据前一个下拉列表和最终选择显示文本框创建下拉列表 - How do I create a drop down list dependant on previous drop down and final choice displays text box 我需要将多语言链接更改为一个下拉框吗? 我怎样才能做到这一点 - I need to change the multi lingual links to a drop-down box? How can I do this 单击具有指定功能的按钮时,如何在输出框中的下拉列表中显示选项的值? - How do I display the value of an option on a drop down in an output box when a button with an assigned function is clicked on? 如何在单个下拉框中将多个单独的查询结果显示在选项中? - How do i display multiple separate query results into options in a single drop down box? 如何从传递到其同级组件的下拉框中获取ref值? - How do I get the ref value from a drop down box passed to its sibling component? 从SuiteScript的下拉菜单中选择选项后,如何显示文本框? - How do I make a text box appear after selecting an option from a drop-down menu in SuiteScript? 如何从下拉列表和显示的输入框中获取增加的价值? - How do I get the added value from a drop down list and an input box to show? 在网页上如何显示悬停时变为下拉框的标签 - On a web page how do I display a label that changes to a drop down box on hover
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM