1

わかりました、私は初めてですjavascript(ただし、すぐに学習します)。いくつかのことを行うコードをまとめることができました。

  1. Excel ファイルを開いたり読み込んだりします (現在はローカルですが、サーバー上にあります)。セルを取得A1します (常に になります#) - 変数 repCount。
  2. html のテーブルにセルA2-A33を書き込みます (ハードコードされた開始と停止)

今、私がやりたいことは

  1. 書き込み部分の最後の行として repCount 変数を取ります - 動的停止ポイント
  2. 私が操作できる配列にそれを書き込みます(グローバルに利用できるはずです)。

これまでの私のコードは次のとおりです。

 <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>&nbsp;</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>&nbsp;</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 を教えてはいけません。誰か助けてくれたり、良いリソースを教えてくれたりできますか?私はこれを学びたいのですが、構文と私は...あまり良い友達ではありません. 例を見ると、それを適応させる方法を理解するのはかなり上手ですが、それを配列に入れることは先週私を悩ませました。前もって感謝します。

4

0 に答える 0