好的,我是javascript
的新手(尽快学习)。我已经能够拼凑出一些代码来完成一些事情。
A1
(将永远是#
) - 变量repCount。 A2-A33
写入html中的表格(硬编码的开始和结束)现在我要做的是
到目前为止,这是我的代码:
<script language="javascript" >
// Open the spreadsheet and get the count of reps
function GetData(cell,row)
{
var excel = new ActiveXObject("Excel.Application");
var excel_file = excel.Workbooks.Open("SOMEFILE.xlsx");
var excel_sheet = excel.Worksheets("Sheet1");
var repCount = excel_sheet.Cells(cell,row).Value;
document.getElementById('div1').innerText = repCount;
}
// open spreadsheet and populate table with representatives
var excelApp=null, excelFile=null, excelSheet=null;
var filename = "SOMEFILE.xlsx";
function initExcel(filename)
{
excelApp = new ActiveXObject("Excel.Application");
excelFile = excelApp.Workbooks.Open(filename);
excelSheet = excelApp.Worksheets('Sheet1');
}
function myShutdownExcel()
{
excelApp.Quit();
excelApp=null;
excelFile=null;
excelSheet=null;
}
function myGetData(column, row)
{
return excelSheet.Cells(column, row).Value;
}
function byId(e) {return document.getElementById(e);}
function myOnLoad2()
{
var numRows = 33, numCols = 1;
var tBody = byId('dataTableBody');
var rowIndex, colIndex, curVal;
var curRow, curCell, curCellText;
initExcel(filename);
for (rowIndex=2; rowIndex<=numRows; rowIndex++)
{
curRow = document.createElement('tr');
for (colIndex=1; colIndex<=numCols; colIndex++)
{
curVal = myGetData(rowIndex, colIndex);
curCell = document.createElement('td');
curCell.setAttribute('title', 'The value of cell [' + rowIndex + ',' + colIndex +']\nis: ' + curVal);
curCellText = document.createTextNode(curVal);
curCell.appendChild(curCellText);
curRow.appendChild(curCell);
}
tBody.appendChild(curRow);
}
myShutdownExcel();
}
</script>
</head>
<body>
<p> </p>
<div style="background: #009955; width:'100%';" align="center">
<font color="#000080" size="12pt">
<b>Get data from excel sheets</b>
</font>
</div>
<center>
<p> </p>
<div id="div1" style="background: #DFDFFF; width:'100%';" align="center">
To start the statistics page - Click the button below
</div>
<input type="button" value="Start" onClick="GetData(1,1);" />
<input type="button" value="Next" onClick="myOnLoad2()" />
</center>
<b>Get data from excel sheets</b>
<table id='dataTable'>
<tbody id='dataTableBody'>
</tbody>
</table>
</body>
</html>
我是否在正确的轨道上?我只能使用javascript,所以不要试着指向我jQuery或PHP。任何人都可以帮助或指向一个好的资源,我想学习这个但语法和我...不是这么好的朋友。一旦我看到一个例子,我很擅长弄清楚如何调整它,但是把它变成阵列让我在上周感到震惊。提前谢谢。