我使用了以上语句将一些数据写入EXCEL文件中,可它总是在后台运行,怎么让它可见呢?
快来救我啊,谢谢啊

解决方案 »

  1.   

    to:net_lover(孟子E章)
    楼上的大虾,那我在visual c#中,选择 asp.net web 应用程序,这是在后台运行的程序,我想
    点击一个按钮,那么客户端就能打开一个excel 表,我的一些数据就都进入这个excel 表里面去了,这如何去做啊,我是新手,希望您能帮助,谢谢!
      

  2.   

    to:net_lover(孟子E章)
    楼上的大虾,那我在visual c#中,选择 asp.net web 应用程序,这是在后台运行的程序,我想
    点击一个按钮,那么客户端就能打开一个excel 表,我的一些数据就都进入这个excel 表里面去了,这如何去做啊,我是新手,希望您能帮助,谢谢!
    我的信箱: [email protected]
    希望别的大虾,也来帮忙
      

  3.   

    在ASP.NET中将数据直接输出成Excel内容 ExcelExport.aspx<%@ Page Language="vb" AutoEventWireup="false" Codebehind="ExcelExport.aspx.vb"
     Inherits="aspxWeb.mengxianhui.com.ExcelExport"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
      <HEAD>
        <title>ExcelExport</title>
        <meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
        <meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
        <meta name="vs_defaultClientScript" content="JavaScript">
        <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
      </HEAD>
      <body MS_POSITIONING="GridLayout">
        <form id="Form1" method="post" runat="server">
          <asp:datagrid id="DataGrid1" runat="server" CellPadding="4" BackColor="White"
           BorderColor="#CC9966" BorderWidth="1px" BorderStyle="None" Width="100%" Height="100%"
            Font-Size="9pt" Font-Names="宋体">
            <SelectedItemStyle Font-Bold="True" ForeColor="#663399" BackColor="#FFCC66"></SelectedItemStyle>
            <AlternatingItemStyle BackColor="#FFCC99"></AlternatingItemStyle>
            <ItemStyle BorderWidth="2px" ForeColor="#330099" BorderStyle="Solid"
             BorderColor="Black" BackColor="White"></ItemStyle>
            <HeaderStyle Font-Bold="True" HorizontalAlign="Center" BorderWidth="2px"
             ForeColor="#FFFFCC" BorderStyle="Solid" BorderColor="Black" BackColor="#990000"></HeaderStyle>
          </asp:datagrid>
        </form>
      </body>
    </HTML>ExcelExport.aspx.vbPublic Class ExcelExport
        Inherits System.Web.UI.Page
      Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid#Region " Web 窗体设计器生成的代码 "    '该调用是 Web 窗体设计器所必需的。
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()  End Sub    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) _
         Handles MyBase.Init
            'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
            '不要使用代码编辑器修改它。
            InitializeComponent()
        End Sub#End Region  Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
        Handles MyBase.Load
        '在此处放置初始化页的用户代码
        ' 定义是否是 SQL Server 数据库,这里为False
        Dim blnIsSQLServer As System.Boolean = False
        Dim strSQL As String
        Dim objDataset As New DataSet()
        Dim objConn As Object
        Dim strCnn As String    If blnIsSQLServer Then
          strCnn = "User ID=sa;Initial Catalog=Northwind;Data Source=.\NetSDK;"
          objConn = New System.Data.SqlClient.SqlConnection(strCnn)
          objConn.Open()
          Dim objAdapter As New System.Data.SqlClient.SqlDataAdapter()
          strSQL = "Select * from customers where country='USA'"
          objAdapter.SelectCommand = New System.Data.SqlClient.SqlCommand(strSQL, objConn)
          objAdapter.Fill(objDataset)
        Else
          strCnn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("Test.mdb")
          objConn = New System.Data.OleDb.OleDbConnection(strCnn)
          objConn.Open()
          Dim objAdapter As New System.Data.OleDb.OleDbDataAdapter()
          strSQL = "Select Top 10 Title From Document"
          objAdapter.SelectCommand = New System.Data.OleDb.OleDbCommand(strSQL, objConn)
          objAdapter.Fill(objDataset)
        End If
        Dim oView As New DataView(objDataset.Tables(0))
        DataGrid1.DataSource = oView
        DataGrid1.DataBind()
        objConn.Close()
        objConn.Dispose()
        objConn = Nothing
        If Request.QueryString("bExcel") = "1" Then
          Response.ContentType = "application/vnd.ms-excel"
          ' 从Content-Type header中去除charset设置
          Response.Charset = ""      ' 关闭 ViewState
          Me.EnableViewState = False
          Dim tw As New System.IO.StringWriter()
          Dim hw As New System.Web.UI.HtmlTextWriter(tw)
          ' 获取control的HTML
          DataGrid1.RenderControl(hw)
          ' 把HTML写回浏览器
          Response.Write(tw.ToString())
          Response.End()
        End If
      End Sub
    End Class
      

  4.   

    test.htm<html>
    <frameset rows="10%,90%">
    <frame noresize="0" scrolling="no" name="top" src="top.htm">
    <frame noresize="0" scrolling="yes" name="bottom" src="ExcelExport.aspx">
    </frameset>
    </html>
    top.htm<html>
    <head>
    <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312" />
    <script language="vbscript">
      Sub Button1_onclick
      Select Case Select1.selectedIndex
        Case 0
          Dim sHTML
          sHTML = window.parent.frames("bottom").document.forms(0).children("DataGrid1").outerhtml
          Dim oXL, oBook
          Set oXL = CreateObject("Excel.Application")
          Set oBook = oXL.Workbooks.Add
          oBook.HTMLProject.HTMLProjectItems("Sheet1").Text = sHTML
          oBook.HTMLProject.RefreshDocument
          oXL.Visible = true
          oXL.UserControl = true
        Case 1
          window.open("ExcelExport.aspx?bExcel=1")
        Case 2
          window.parent.frames("bottom").navigate "ExcelExport.aspx?bExcel=1"
        Case 3
          window.parent.frames("bottom").location.href="ExcelExport.aspx"
      End Select
    End Sub
    </script>
    </head><body>
    输出数据到Excel:
    <SELECT id="Select1" size="1" name="Select1">
    <OPTION value="0" selected>Automation自动化输出</OPTION>
    <OPTION value="1">MIME Type (在新窗口输出)</OPTION>
    <OPTION value="2">MIME Type (在幀中输出)</OPTION>
    <OPTION value="3">恢复原状</OPTION>
    </SELECT>
    <INPUT type="button" id="Button1" value="开始输出数据到Excel">
    </body>
    </html>