2015-01-13 65 views
-4

我想导出为ex​​cel,但我想选择具有自定义着色和修改而不是默认excel页面的excel文件。我怎样才能在asp.net上用vb实现这一点。在asp.net上导出为ex​​cel

+4

到目前为止,您尝试了哪些操作?请尝试一下你所做的事情,特别是你卡在哪里。 – Codexer

+0

在客户端或服务器上选择一些东西? – Steve

+1

从ASP.NET或其他服务器技术中使用Office Interop是一个糟糕的主意。这些API被编写用于桌面应用程序,用于自动化Office(一套桌面应用程序)。服务器应用程序在许多方面有所不同,因此在其中使用Office Interop是非常非常糟糕的主意。它也不受Microsoft的支持,并可能违反您的Office许可证。见(http://support.microsoft.com/kb/257757) –

回答

0

尝试使用特定的库导出到asp.net中的excel。例如,存在Syncfusion XlsIo,Telerik或spreadsheetgear(这是专门针对excel的)。就我而言,我使用Syncfusion XlsIo以及与此自定义在Excel中的所有报告,也可以使用图形和条件格式

+0

我将尝试telerik,谢谢 – ZeeProgrammer

0
Public Sub ExportToExcel (dt As DataTable) 
    If dt.Rows.Count > 0 Then 
    Dim filename As String = "DownloadMobileNoExcel.xls" 
    Dim tw As New System.IO.StringWriter() 
    Dim hw As New System.Web.UI.HtmlTextWriter(tw) 
    Dim dgGrid As New DataGrid() 
    dgGrid.DataSource = dt 
    dgGrid.DataBind() 

    'Get the HTML for the control. 
    dgGrid.RenderControl(hw) 

    'Write the HTML back to the browser. 
    Response.ContentType = "application/vnd.ms-excel" 
    Response.AppendHeader("Content-Disposition", (Convert.ToString("attachment; filename=") & filename) + "") 
    Me.EnableViewState = False 
    Response.Write(tw.ToString()) 
    Response.End() 
    End If 
End Sub 
+0

您的方法将导出到默认的Excel表,有没有办法导出到驻留在项目文件夹中的自定义Excel表?我感谢你的时间。 – ZeeProgrammer