Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

xls2js

Status
Not open for further replies.

gapla

Programmer
Dec 15, 2003
37
ES
I need convert an excel sheet into javascript
is there any way to achieve it?
 
Code:
<html>
<head>
  <title>sample of using Excel</title>
  <script language=&quot;JScript&quot;>
    var xls;
    var wb;
    var xlSaveChanges = 1;
    var xlDoNotSaveChanges = 2;
    function read_excel()
    {
      var rertval;
      var hrng, irng;
      var cols;
      var rows;
      var i, j;
      xls = new ActiveXObject(&quot;Excel.Application&quot;);
      xls.DisplayAlerts = false;
      wb = xls.Workbooks.open(&quot;C:\\path to excel\\excel-test.xls&quot;);
      retval = &quot;reading data from excel:<br/>\n&quot;;
      retval += &quot;<table  style=\&quot;font:10pt MS Sans Serif\&quot; border=\&quot;1\&quot; CELLSPACING=\&quot;0\&quot; CELLPADDING=\&quot;1\&quot; BGCOLOR=\&quot;#FFFFFF\&quot;>\n&quot;;
      wb.Sheets.item(&quot;Sheet1&quot;).Range(&quot;B1&quot;).value = 100;
      hrng = wb.Sheets.item(&quot;Sheet1&quot;).Range(&quot;B2:F2&quot;);
      cols = hrng.Columns.count;
      retval += &quot;<thead style=\&quot;font:bold; background-color:#C0C0C0\&quot;>\n<tr>\n&quot;;
      for(i = 1; i <= cols; i++)
      {
        retval += (&quot;<td>&quot; + hrng.Cells(1, i).Value + &quot;</td>&quot;);
      }
      retval += &quot;</tr></thead>&quot;;
      irng = wb.Sheets.item(&quot;Sheet1&quot;).Range(&quot;B3:F22&quot;);
      rows = irng.Rows.count;
      for(j = 1; j <= rows; j++)
      {
        retval += &quot;<tr>&quot;;
        for(i = 1; i <= cols; i++)
        {
          retval += (&quot;<td>&quot; + irng.Cells(j, i).Value + &quot;</td>&quot;);
        }
        retval += &quot;</tr>\n&quot;;
      }
      retval += &quot;</table>\n&quot;;
      return retval;
    }
    function doQuit()
    {
      var toSave = confirm(&quot;would you like to save?&quot;);
      if(toSave)
      {
        wb.close(xlSaveChanges);
      }else
      {
        wb.close(xlDoNotSaveChanges);
      }
      xls.quit();
    }
    document.write(read_excel());
  </script>
</head>
<body onUnload=&quot;javaScript:doQuit()&quot;>
</body>
</html>

Ion Filipski
1c.bmp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top