如题

解决方案 »

  1.   

    肯定要用到 ActiveXObject,
    早先用 js + access 做过些小东东,excel 应该差不多,
    楼主自己动手搜搜吧!
      

  2.   

    这个是一个简单的示例,就是你给他一个表格名字就可以了,然后生成一个表格,就是这样:MakeExcel("TABLE1",true,"1.xls"),其他参数可以不要。function MakeExcel(Obj,ProceVisible,SaveAsFilename,SortType,SortField){
    var MyData= new GetTableData(Obj,0,0);
    var myrows=MyData.rows;
    var i,j;  try {
        var xls   = new ActiveXObject ( "Excel.Application" );
      }
      catch(e) {
          alert( "要打印该表,您必须安装Excel电子表格软件,同时浏览器须使用“ActiveX 控件”,您的浏览器须允许执行控件。 请点击【帮助】了解浏览器设置方法!");
            return "";
      }
        if (typeof(ProceVisible)=="undefined"){
      xls.visible = true;
      }
        else{
          if (ProceVisible=="true"){
          xls.visible = true;
          }
          else
            {
            xls.visible = false;
          }
        }
      var xlBook = xls.Workbooks.Add;
      var xlsheet = xlBook.Worksheets(1);
      xls.Cells.Select;
      xls.Selection.NumberFormatLocal = "@";
      for (i=0;i<MyData.rows ;i++){
      for (j=0;j<MyData.cols ;j++){
        if (typeof(MyData.GetFieldData(j)) == "number"){
        xlsheet.Cells(i+1,j+1).NumberFormatLocal = "0.00_ ";
        }
        xlsheet.Cells(i+1,j+1).Value= MyData.GetFieldData(j);
      }
      
      MyData.MoveNext(); 
      }
      
      if (SaveAsFilename=="" || typeof(SaveAsFilename)=="undefined"){
        var fname = xls.Application.GetSaveAsFilename("*.xls", "Excel Spreadsheets (*.xls), *.xls");
        if (fname!=""){
        xlBook.SaveAs(fname);
        }
      }
      else{
      xlBook.SaveAs(SaveAsFilename);
      }
      xlBook.Close (savechanges=false);
      //xls.visible = false;
      xls.Quit();
      xls=null;
      //结束excel进程,退出完成
      window.setInterval("Cleanup();",1);
      
    }
      

  3.   

    <html>
    <script>
    function mytest1() {
    var Excel, Book; // Declare the variables
    Excel = new ActiveXObject("Excel.Application"); // Create the Excel application object.
    Excel.Visible = false; // Make Excel invisible.
    Book = Excel.Workbooks.Add() // Create a new work book.
    Book.ActiveSheet.Cells(1,1).Value = document.all.my_textarea1.value;
    Book.SaveAs("C:/Documents and Settings/ProGamer/Desktop/word to text/TEST.xls");
    Excel.Quit(); // Close Excel with the Quit method on the Application object.
    }function mytest2() {
    var Excel;
    Excel = new ActiveXObject("Excel.Application");
    Excel.Visible = false;
    form1.my_textarea2.value = Excel.Workbooks.Open("C:/Documents and Settings/ProGamer/Desktop/word to text/TEST.xls").ActiveSheet.Cells(1,1).Value;
    Excel.Quit();
    }</script><body>
    <form name="form1">
    <input type=button onClick="mytest1();" value="Send Excel Data"><input type=text name="my_textarea1" size=70 value="enter ur data here">
    <br><br>
    <input type=button onClick="mytest2();" value="Get Excel Data"><input type=text name="my_textarea2" size=70  value="no data collected yet"></form>
    </body>
    </html>
      

  4.   

    function openExcel(file)
    {
      var Excel = new ActiveXObject("Excel.Application");
      Excel.Visible = false;
      document.all.editdiv.innerHTML = Excel.Workbooks.Open(file).ActiveSheet.Cells(1,1).Value;
      //Excel.Visible = true;
      Excel.Quit();
    }