在VB.NET Windows应用程序中导出到Excel。 [英] Export to Excel in VB.NET Windows Application.

查看:148
本文介绍了在VB.NET Windows应用程序中导出到Excel。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我想在VB.NET Windows应用程序中将Datagrid的内容导出到Excel文件。

请提供此代码。

Hi All,
I want to export the contents of Datagrid to Excel file in VB.NET Windows Application.
Please provide the code for this.

推荐答案

检查这些:



使用VB.Net导出到Excel [ ^ ]



将DataGrid导出为Excel,Word和文本文件 [ ^ ]



希望这会有所帮助:)
check these out:

Export to Excel using VB.Net[^]

Exporting DataGrid to Excel, Word and Text Files[^]

hope this helps :)


除了Uday回答:



不要将任何控件的内容导出到其他控件,打印,报告,导出文档。您需要一个单独的数据层。您可能已经使用某些数据层与数据网格绑定。使用数据生成PDF,而不是数据网格或任何其他控件。



如果不清楚(即使它很清楚),请了解以下建筑模式 http://en.wikipedia.org/wiki/Architectural_pattern_(computer_science) [ ^ ]):



MVVM - 模型视图模型,

http ://en.wikipedia.org/wiki/Model_View_ViewModel [ ^ ],



MVC - 模型 - 视图 - 控制器,

http://en.wikipedia.org/wiki/Model-view-controller [ ^ ]),



MVA - 模型 - 视图 - 适配器,

http://en.wikipedia.org/wiki/Model-view-adapter [ ^ ],



MVP - 模型 - 视图 - 演示者,

http: //en.wikipedia.org/wiki/Model-view-presenter [ ^ ]。

注意这些架构的动机。如果您了解它,您将能够创建更好的设计理念。



-SA
In addition to answer by Uday:

Don't export content of any controls to other controls, prints, reports, export document. You need to have a separate data layer. Probably you already using some data layer to bind with you data grid. Use data for generation of PDF, not data grid or any other control.

If this is not clear (and even it it is clear), learn about the following architectural patterns (http://en.wikipedia.org/wiki/Architectural_pattern_(computer_science)[^]):

MVVM — Model View View Model,
http://en.wikipedia.org/wiki/Model_View_ViewModel[^],

MVC — Model-View-Controller,
http://en.wikipedia.org/wiki/Model-view-controller[^]),

MVA — Model-View-Adapter,
http://en.wikipedia.org/wiki/Model–view–adapter[^],

MVP — Model-View-Presenter,
http://en.wikipedia.org/wiki/Model-view-presenter[^].
Pay attention for the motivation of those architectures. If you understand it, you would be able to create better design ideas.

—SA


Protected Sub btnsndexl_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnsndexl.Click
        If gdhidden.Rows.Count > 0 Then
            ExportGridView()
        Else
            ScriptManager.RegisterClientScriptBlock(btnsndexl, Me.GetType(), "MyScript", "alert('No Record Found');", True)
        End If
    End Sub







Private Sub ExportGridView()
       gdhidden.Visible = True
       Dim attachment As String = "attachment; filename=Report.xls"
       Response.ClearContent()
       Response.AddHeader("content-disposition", attachment)
       Response.ContentType = "application/ms-excel"
       Dim sw As New IO.StringWriter
       Dim htw As New UI.HtmlTextWriter(sw)
       gdhidden.RenderControl(htw)
       Response.Write(sw.ToString())
       Response.End()
       gdhidden.Visible = False
   End Sub


这篇关于在VB.NET Windows应用程序中导出到Excel。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆