new ActiveXObject("Excel.Application");

解决方案 »

  1.   

    做个查询页替换HTMLURL的值
    <object classid="clsid:0002E510-0000-0000-C000-000000000046" id="Spreadsheet1" codebase="file:D:\SoftWare_Bak\Office2000\office2000\msowc.cab" width="576" height="288">
      <param name="HTMLURL" value="http://www.csdn.net/">
      <param name="DataType" value="HTMLURL">
      <param name="AutoFit" value="0">
      <param name="DisplayColHeaders" value="-1">
      <param name="DisplayGridlines" value="-1">
      <param name="DisplayHorizontalScrollBar" value="-1">
      <param name="DisplayRowHeaders" value="-1">
      <param name="DisplayTitleBar" value="-1">
      <param name="DisplayToolbar" value="-1">
      <param name="DisplayVerticalScrollBar" value="-1">
      <param name="EnableAutoCalculate" value="-1">
      <param name="EnableEvents" value="-1">
      <param name="MoveAfterReturn" value="-1">
      <param name="MoveAfterReturnDirection" value="0">
      <param name="RightToLeft" value="0">
      <param name="ViewableRange" value="1:65536">
    </object>
      

  2.   

    假如以上代码在表单Form中选择了HTML文本.
    你将HTMLURL参数替换成Http://LocalHost/*.nsf/$$ViewTemplate for ViewName你看看,或者.
    差不多.
    function PrintFile()
    {
    var strResult=window.confirm("确认用Word打印吗?");
    if(strResult)
    {
    try
    {
    App.focus();
    document.execCommand("SelectAll");
    document.execCommand("Copy");
    App.focus();
    var WordApp=new ActiveXObject("Word.Application");
    WordApp.Application.Visible=true;
    var Doc=WordApp.Documents.Add();
    Doc.Activate();
    Doc.Content.Paste();
    Doc.PrintPreview();
    WordApp.DisplayAlerts=false;
    Doc.Close();
    WordApp.DisplayAlerts=true;
    WordApp.Quit();
    }
    catch(e){}
    }
    else
    {
    var hwnd=window.open("");
    hwnd.document.write(App.innerHTML);
    }
    return false;
    }
      

  3.   

    <HTML>
    <BODY>
    点击下面的按钮,开始打开Excel并创建数据表
    <SCRIPT LANGUAGE="VBScript">
    Function CreateNamesArray()
    ' Create an array to set multiple values at once.
      Dim saNames(5, 2)
      saNames(0, 0) = "John"  saNames(0, 1) = "Smith"
      saNames(1, 0) = "Tom"
      saNames(1, 1) = "Brown"
      saNames(2, 0) = "Sue"
      saNames(2, 1) = "Thomas"
      saNames(3, 0) = "Jane"
      saNames(3, 1) = "Jones"
      saNames(4, 0) = "Adam"
      saNames(4, 1) = "Johnson"
      CreateNamesArray = saNames
    End Function
    </SCRIPT><SCRIPT LANGUAGE="JScript">
    function AutomateExcel()
    {   // Start Excel and get Application object.
          var oXL = new ActiveXObject("Excel.Application");      oXL.Visible = true;   // Get a new workbook.
          var oWB = oXL.Workbooks.Add();
          var oSheet = oWB.ActiveSheet;   // Add table headers going cell by cell.
          oSheet.Cells(1, 1).Value = "First Name";
          oSheet.Cells(1, 2).Value = "Last Name";
          oSheet.Cells(1, 3).Value = "Full Name";
          oSheet.Cells(1, 4).Value = "Salary";   // Format A1:D1 as bold, vertical alignment = center.
          oSheet.Range("A1", "D1").Font.Bold = true;
          oSheet.Range("A1", "D1").VerticalAlignment =  -4108; //xlVAlignCenter   // Create an array to set multiple values at once.   // Fill A2:B6 with an array of values (from VBScript).
          oSheet.Range("A2", "B6").Value = CreateNamesArray();   // Fill C2:C6 with a relative formula (=A2 & " " & B2).
          var oRng = oSheet.Range("C2", "C6");
          oRng.Formula = "=A2 & \" \" & B2";   // Fill D2:D6 with a formula(=RAND()*100000) and apply format.
          oRng = oSheet.Range("D2", "D6");
          oRng.Formula = "=RAND()*100000";
          oRng.NumberFormat = "$0.00";   // AutoFit columns A:D.
          oRng = oSheet.Range("A1", "D1");
          oRng.EntireColumn.AutoFit();   // Manipulate a variable number of columns for Quarterly Sales Data.
          DispalyQuarterlySales(oSheet);   // Make sure Excel is visible and give the user control
       // of Excel's lifetime.
          oXL.Visible = true;
          oXL.UserControl = true;
    }function DispalyQuarterlySales(oWS)
    {
          var iNumQtrs, sMsg, iRet;    // Number of quarters to display data for.
          iNumQtrs = 4;    // Starting at E1, fill headers for the number of columns selected.
          var oResizeRange = oWS.Range("E1", "E1").Resize(1,iNumQtrs);
          oResizeRange.Formula = "=\"Q\" & COLUMN()-4 & CHAR(10) & \"Sales\"";    // Change the Orientation and WrapText properties for the headers.
          oResizeRange.Orientation = 38;
          oResizeRange.WrapText = true;    // Fill the interior color of the headers.
          oResizeRange.Interior.ColorIndex = 36;    // Fill the columns with a formula and apply a number format.
          oResizeRange = oWS.Range("E2", "E6").Resize(5,iNumQtrs);
          oResizeRange.Formula = "=RAND()*100";
          oResizeRange.NumberFormat = "$0.00";    // Apply borders to the Sales data and headers.
          oResizeRange = oWS.Range("E1", "E6").Resize(6,iNumQtrs);
          oResizeRange.Borders.Weight = 2;  // xlThin    // Add a Totals formula for the sales data and apply a border.
          oResizeRange = oWS.Range("E8", "E8").Resize(1,iNumQtrs);
          oResizeRange.Formula = "=SUM(E2:E6)";
        // 9 = xlEdgeBottom
          oResizeRange.Borders(9).LineStyle = -4119; //xlDouble
          oResizeRange.Borders(9).Weight = 4; //xlThick    // Add a Chart for the selected data.      oResizeRange = oWS.Range("E2:E6").Resize(5,iNumQtrs);
          var oChart = oWS.Parent.Charts.Add();
          oChart.ChartWizard(oResizeRange, -4100, null, 2);  // -4100 = xl3dColumn
          oChart.SeriesCollection(1).XValues = oWS.Range("A2", "A6");
          for (iRet = 1; iRet <= iNumQtrs; iRet++) {
             oChart.SeriesCollection(iRet).Name = "=\"Q" + iRet + "\"";
          }
          oChart.Location(2, oWS.Name); // 2 = xlLocationAsObject    // Move the chart so as not to cover your data.
          oWS.Shapes("Chart 1").Top = oWS.Rows(10).Top;
          oWS.Shapes("Chart 1").Left = oWS.Columns(2).Left;
    }
    </SCRIPT>
    <P><INPUT id=button1 type=button value="创建 Excel" onclick="AutomateExcel"></P>
    </BODY>
    </HTML>
      

  4.   

    你也可以写代理直接输出就可以了,不过你用Office组件有导出按钮.
    Sub Initialize
    Print "Content-Type:application/vnd.ms-excel"
    Print "<head>"
    Print "<meta http-equiv=""Content-Type"" content=""text/html; charset=gb2312"">"
    Print "<meta name=""GENERATOR"" content=""Microsoft FrontPage 4.0"">"
    Print "<meta name=""ProgId"" content=""FrontPage.Editor.Document"">"
    Print "<title>报表打印预览</title>"
    Print "<link rel=""stylesheet"" type=""text/css"" href="""">"
    Print "</head><body>"
    Dim Session As New NotesSession
    Dim Db As NotesDatabase
    Set Db=Session.CurrentDatabase
    Dim View As NotesView
    Dim Doc As NotesDocument
    Set View=Db.GetView("DefaultView")
    Set Doc=View.GetFirstDocument
    Print "<table border=1 bordercolor=""#000000"">"
    Print "<tr><td colspan=""2"" algin=""center"">报表打印预览</td></tr>"
    Print "</table>"
    Print "<br><br>"
    Dim m_Head As Variant
    Dim m_Data As Variant
    Dim iCol As Integer
    Dim iResult As Integer
    Print "<table border=1 bordercolor=""#000000"">"
    While Not(Doc Is Nothing)
    Print "<tr>"
    Print "<td>"+Doc.Created+"</td>"
    m_Head=Doc.GetItemValue("Head")
    m_Data=Doc.GetItemValue("Data")
    Print "<td><table border=1 bordercolor=""#000000"">"
    Print "<tr>"
    iCol=0
    Forall m_Unit In m_Head
    Print "<td>"+m_Unit+"</td>"
    iCol=iCol+1
    End Forall
    Print "</tr>"
    iResult=0
    Forall m_Unit In m_Data
    If iResult Mod iCol=0 Then
    Print "<tr>"
    End If
    Print "<td>"+m_Unit+"</td>"
    iResult=iResult+1
    If iResult Mod iCol=0 Then
    Print "</tr>"
    End If
    End Forall
    Print "</table>"
    Print "</tr>"
    Set Doc=View.GetNextDocument(Doc)
    Wend
    Print "</table>"
    Print "</body></html>"
    End Sub
      

  5.   

    我原来是这么写的,可导到excel里是
    乱码
    sub Initialize
    Print |Content-Type:application/vnd.ms-excel|
    Dim s As New notesSession
    Dim db As Notesdatabase
    Dim view As notesView
    Dim doc As notesDocument
    Dim counter As Integer
    Set db=s.CurrentDatabase
    Set view = db.GetView ("vwc")
    Set doc = view.GetFirstDocument
    Print |<Table border=1>|
    Forall c In view.Columns
    If (Not c.isHidden) Then
    Print |<th>| & c.Title & |</th>|
    End If
    End Forall
    While Not (doc Is Nothing)
    counter% = 0
    Print |<tr>|
    Forall values In doc.ColumnValues
    If (Not view.Columns (counter%).IsHidden) Then
    Print |<td valign="top">|
    If Isscalar (values) Then
    Print values
    Else
    Forall v In values
    Print v & |<br/>|
    End Forall
    End If
    Print |</td>|
    End If
    counter% = counter% + 1
    End Forall
    Print |</tr>|
    Set doc = view.GetNextDocument (doc)
    Wend
    Print |</table>|
    end sub
      

  6.   

    不要省略[指定字符编码]
    Print "<meta http-equiv=""Content-Type"" content=""text/html; charset=gb2312"">"
      

  7.   

    就这句话我考了过去还是乱码,有人说可以用js把网页另存为excel,可怎么才能实现?
      

  8.   

    这样吧!
    <script language="javascript">
    function exportExcel(atblData){
    if (typeof(EXPORT_OBJECT)!="object"){
    document.body.insertAdjacentHTML("afterBegin","<OBJECT style='display:none' classid=clsid:0002E510-0000-0000-C000-000000000046 id=EXPORT_OBJECT></Object>");
    }
    with (EXPORT_OBJECT){
    DataType = "HTMLData";
    HTMLData =atblData.outerHTML;
    try{
    ActiveSheet.Export("C:\\out.xls", 0);
    alert('导出完毕');
    }
    catch (e){
    alert('导出Excel表失败,已取消操作,或请确定已安装Excel2000(或更高版本),并且没打开同名xls文件');
    }
    }
    }
    </script>
    <table id="tblData"  class="clsTable" cellspacing="1" cellpadding="3" border="1" bordercolor="#3399FF">
    <tr><td>aaaaaaaaaa</td></tr>
    </table>
    <a href="#" onClick="exportExcel(tblData)">将当前页的查询结果导出到excel</a>
      

  9.   

    安全级别不要太高否则不能运行<input type="button" name="out_excel" onclick="AutomateExcel();" value="导出到excel" class="notPrint">  导出到Excel代码 <SCRIPT LANGUAGE="javascript"> 
    <!-- 
    function AutomateExcel() 

    // Start Excel and get Application object. 
    var oXL = new ActiveXObject("Excel.Application"); 
    // Get a new workbook. 
    var oWB = oXL.Workbooks.Add(); 
    var oSheet = oWB.ActiveSheet; 
    var table = document.all.data; 
    var hang = table.rows.length;
    var lie = table.rows(0).cells.length; // Add table headers going cell by cell. 
    for (i=0;i<hang;i++) 

    for (j=0;j<lie;j++) 

    //oSheet.Cells(i+1,j+1).Font.Bold = True 
    //oSheet.Cells(i+1,j+1).Font.Size = 50 
    //oSheet.Cells(i+1,j+1).Alignment = 2
    oSheet.Cells(i+1,j+1).value = table.rows(i).cells(j).innerText; 
    } } 
    oXL.Visible = true; 
    oXL.UserControl = true; 

    //-->
    </SCRIPT><table border="1" width="100%" id="data">
    <tr>
    <td>&nbsp;姓名</td>
    <td colspan="2">年龄</td>
    <td>出生日期</td>
    </tr>
    <tr>
    <td>6</td>
    <td> </td>
    <td colspan="2">8</td>
    </tr>
    <tr>
    <td height="22">1</td>
    <td height="22">2</td>
    <td colspan="2" height="22">4</td>
    </tr>
    </table>
    <table border="1" width="100%" id="data">
             <tr>
                <td cosplan ="5">某某报表</td>
             </tr>
    <tr>
    <td>&nbsp;姓名</td>
    <td colspan="2">年龄</td>
    <td>出生日期</td>
    </tr>
    </table>