<script>
function gbid(s) {
return document.getElementById(s);
}
function GetData(cell,row){
var excel = new ActiveXObject("Excel.Application");
var excel_file = excel.Workbooks.Open("Someexcelfile.xlsx");
var excel_sheet = excel.Worksheets("Sheet1");
gbid('span1').innerText = excel_sheet.Cells(3,3).Value;
gbid('span2').innerText = excel_sheet.Cells(4,3).Value;
gbid('span3').innerText = excel_sheet.Cells(5,3).Value;
gbid('span4').innerText = excel_sheet.Cells(8,3).Value;
gbid('span6').innerText = excel_sheet.Cells(10,3).Value;
gbid('span7').innerText = excel_sheet.Cells(11,3).Value;
gbid('span8').innerText = excel_sheet.Cells(12,3).Value;
gbid('span11').innerText = excel_sheet.Cells(14,3).Value;
gbid('span12').innerText = excel_sheet.Cells(15,3).Value;
gbid('span13').innerText = excel_sheet.Cells(16,3).Value;
gbid('span14').innerText = excel_sheet.Cells(17,3).Value;
}
function RetrieveMember(cell,row){
var excel = new ActiveXObject("Excel.Application");
var excel_file = excel.Workbooks.Open("Someexcelfile.xlsx");
var excel_sheet = excel.Worksheets("Sheet1");
var searchMember = document.getElementById('searchMember').value;
var Name = document.getElementById('searchMember').value;
gbid('span9').innerText = excel_sheet.Cells(11,7).Value;
gbid('span10').innerText = excel_sheet.Cells(12,7).Value;
gbid('span15').innerText = excel_sheet.Cells(15,7).Value;
gbid('span16').innerText = excel_sheet.Cells(16,7).Value;
gbid('span17').innerText = excel_sheet.Cells(17,7).Value;
gbid('span18').innerText = excel_sheet.Cells(7,3).Value;
excel_file.Close()
excel.Application.Quit()
}
</script>
<body onload="GetData()" />
<body bgcolor="#000000">
<table width="450">
<tr>
<td colspan="2" bgcolor="#fafafa"><center>
<span id="span1" width:'100%'; ></span><br />
<span id="span2" width:'100%'; ></span><br />
<span id="span3" width:'100%'; ></span></center>
</tr>
<tr>
<td colspan="2" bgcolor="#B6D7E6" >
<b> <span id="span4" width:'100%'; ></span> : </b>
<input type="text" name="searchMember" id="searchMember" /> <a href="javascript: RetrieveMember();">Search</a>
<br />
<br />
<span id="span6" width:"100%; ></span> <b><u><span id="span18" width:"100%; ></span></b></u>
</td>
</tr>
<tr>
<td bgcolor="#fafafa" >
<span id="span7" width:"100%; ></span> <br />
<span id="span8" width:"100%; ></span> <br /> <br />
<span id="span11" width:"100%; ></span> <br />
</td>
<td bgcolor="#B6D7E6" >
<span id="span9" width:"100%; ></span> <br />
<span id="span10" width:"100%; ></span> <br /><br /><br />
</td>
</tr>
<tr>
<td bgcolor="#B6D7E6" > <span id="span12" width:"100%; ></span><br />
<span id="span13" width:"100%; ></span><br />
<span id="span14" width:"100%; ></span><br /><br />
</td>
<td bgcolor="#fafafa" >
<span id="span15" width:"100%; ></span><br />
<span id="span16" width:"100%; ></span><br />
<span id="span17" width:"100%; ></span><br /><br />
</td>
</tr>
好的,到目前为止,这段代码几乎可以完成我想要它做的所有事情。它从同一个excel文件中提取现有信息即可使用。我想让它做的是将信息从输入框/文本框发送到excel中的特定单元格(然后让它自动命中输入)。而已。我是javascript的新手,想知道我是否可以得到一些帮助。 Muchas Gracias!
答案 0 :(得分:0)
要将页面中的值发送到Excel单元格,只需反转此表达式:
gbid('span18').innerText = excel_sheet.Cells(7,3).Value;
到此:
excel_sheet.Cells(7,3).Value = gbid('span18').innerText;
虽然按Enter键我不知道你想要什么。如果我假设您正在尝试响应保存文件确认,那么为什么不明确保存文件:
excel_file.SaveAs("some location\somename.xlsx");
(假设您可以使用ActiveXObject保存。)
BTW您不应该在下面需要Application
,因为excel已经是应用程序:
excel.Quit();
和JavaScript语句以分号终止。即使它没有它们也可以使用,你应该总是使用它们。