如何将Asp表数据导出到Excel? [英] How Do I Export The Asp Table Data To Excel ?
本文介绍了如何将Asp表数据导出到Excel?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<table id="tblsalary">
<tr style="background-color: #2291FF;">
<td align="left" class="salarytable1">
Basic Salary</td>
<td align="left" class="salarytable2" style="font-weight: bold">
<asp:Label ID="lblBasic" runat="server" Text="Label"></asp:Label>
</td>
<td align="left" class="salarytable1">
PF Employee Contribution</td>
<td align="left" class="salarytable2" style="font-weight: bold">
<asp:Label ID="lblPFcontribution" runat="server" Text="Label"></asp:Label>
</td>
</tr></table>
Protected Sub btndownload_Click(sender As Object, e As EventArgs) Handles btndownload.Click
Dim excel As GridExcelExport = New GridExcelExport(Me.tblsalary, "Salary Slip.xls")
excel.ExportNestedTable = True
excel.Export()
End Sub
推荐答案
- 导出用于填充表格的数据,而不是ASP.NET或HTML控件。
- Y.您可以使用Open XML SDK。有关使用它的示例,请参阅此CodeProject文章:创建基本的Excel工作簿使用Open XML [ ^ ]。
另请参阅本文中引用的过去答案:如何从MS Visual Studio 2010中的添加引用添加microsoft excel 15.0对象库 [ ^ ]。
顺便提一下,这些微软的文章解释为什么不建议在服务器设置中使用Office互操作:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q257757#kb2 [ ^ ],
http://support.microsoft.com/kb/257757/en-us [ ^ ]。
- Export data used to populate your table, not ASP.NET or HTML controls.
- You can use Open XML SDK. Please see this CodeProject article for the example of using it: Creating basic Excel workbook with Open XML[^].
See also my past answers referenced in this one: How to add microsoft excel 15.0 object library from Add Reference in MS Visual Studio 2010[^].
By the way, these Microsoft articles explain why using Office interop in server setting is not recommended:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q257757#kb2[^],
http://support.microsoft.com/kb/257757/en-us[^].
祝你好运。
这篇关于如何将Asp表数据导出到Excel?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文