【问题标题】:Export GridView to Excel in GENERAL Format以 GENERAL 格式将 GridView 导出到 Excel
【发布时间】:2015-08-27 08:05:41
【问题描述】:

我正在尝试将我的GridView 导出到Excel。问题是当我将其导出为我设置为Text 的默认格式时,但我希望它在General 中。 这是我导出 Excel 的方式:

Response.Clear()
Response.Charset = ""
Response.AddHeader("content-disposition", "attachment;filename=RawTransactionReport.xls")
'set the response mime type for excel 
Response.ContentType = "application/vnd.ms-excel"
'create a string writer 
Dim stringWrite As New System.IO.StringWriter
'create an htmltextwriter which uses the stringwriter 
Dim htmlWrite As New System.Web.UI.HtmlTextWriter(stringWrite)
'tell the datagrid to render itself to our htmltextwriter 
 grdTransactions.RenderControl(htmlWrite)
 'shows number in string format
Dim Style As String = "<style> TD { mso-number-format:\@; } </style>"
'all that's left is to output the html 
Response.Write(Style)
Response.Write(stringWrite.ToString)
Response.End()

有什么办法可以将其设置为“通用”吗?实际上我的数字字段是summed,但如果格式是文本,你就不能对它们求和。所以我想要通用格式

【问题讨论】:

    标签: asp.net vb.net excel gridview export-to-excel


    【解决方案1】:

    就个人而言,我不会直接从您的GridView 导出数据,而是会返回到您的 GridView 的数据源并将其导出。

    通过这样做,您可以使用众多免费工具之一来创建一个真实 Excel 文件。

    这是我的免费产品(在 VB.Net 和 C# 中可用):

    Export to Excel

    因此,如果您的 GridView 填充了来自名为 NukesData 的 DataSet 的数据,您只需调用它:

    CreateExcelFile.CreateExcelDocument(NukesData, "NukesExcel.xlsx", Response)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-25
      • 1970-01-01
      相关资源
      最近更新 更多