Javascript没有从excel中显示正确的单元格

Javascript is not displaying correct cells from excel

本文关键字:单元格 显示 excel Javascript      更新时间:2023-09-26
<script language="javascript" >
function GetData(cell,row){
var excel = new ActiveXObject("Excel.Application");
var excel_file = excel.Workbooks.Open("http://kb.healthnet.com/al/12/2/72550.xls");
var excel_sheet = excel.Worksheets("CA 2012-2013 HMO Plans");
var data = excel_sheet.Cells(cell,row).Value;
var data2 = excel_sheet.Cells(cell,row).Value;
document.getElementById('div1').innerText = data;
document.getElementById('div2').innerText = data2;
}
</script>
<table>
<tr>
<td>
<input type="button" value="Hearing Services" onClick="GetData(45,2);(46,2);" />
</td>
<td>
<div id="div1" style="background: #e2e2e2; width:'100%';" align="center">45,2 will display here</div>
</td>
</tr>
<tr>
<td></td>
<td>
<div id="div2" style="background: #e2e2e2; width:'100%';" align="center">46,2 will display here</div>
</td>
</tr>
<table>

看,在45,2和46,2 td中只有45,2在两个td上显示。我试过改变一切,所以我认为我缺乏结构的功能逻辑。我一直在试着略读一些书,因为这个项目对时间很敏感,所以很难集中注意力。

什么是GetData(45,2)&(46,2)

如果你试图做两个单独的函数调用,它应该是GetData(45,2)和再次GetData(46,2)。但是您使用了一个奇怪的操作符&——您的意思是将这些值连接起来吗?如果是这样,你是在Javascript中使用VB操作符。

要解决您的显示问题,您希望完成什么?提供单元格中的数据示例,以及在单元格的内容更新后希望单元格包含的内容。那么我们可能会更能帮助你。

此外,将函数作为文本放在onclick属性内并不是最佳实践。一般来说,最好创建一个实际的函数,并在页面加载时附加它:

function hearingServicesClick() {
   GetData(45, 2);
   GetData(46, 2);
}
document.getElementById('hearingservices').onclick = hearingServicesClick;