C Export Method for Excel

  • 2021-06-29 11:51:14
  • OfStack

This time you need to use C#as a page to export the data queried in the grid to Excel.I have found a lot of C#export Excel code on the web, it is not available to try and try.Many codes are for.net 2.0 or 3.0, but my program was developed with.net 1.0, which makes many functions unusable.After that, I changed my mind and looked for "UltraWebGrid's method of exporting Excel". I found a batch of widely circulated text in CSDN, but the results of my human flesh test were still not available.Just when I was almost in despair, I found that the original UltraWebGrid had its own control to export Excel.It's easy to use, just register the front end and call the back end.Here is a simple example.

PS: UltraWebGrid really has too few Chinese documents to use.

The code for modle.aspx is as follows: Register the control in line 1, add an Export button in line 2, and add an UltraWebGridExcelExporter control in line 3.


<%@ Register Assembly="Infragistics.WebUI.UltraWebGrid.ExcelExport.v5.1, Version=5.1.20051.37, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb" Namespace="Infragistics.WebUI.UltraWebGrid.ExcelExport" TagPrefix="igxl" %>
<asp:button id="Button2" runat="server" Text=" export " Width="64px"></asp:button>
<igxl:UltraWebGridExcelExporter ID="UltraWebGridExcelExporter1" runat="server" DownloadName="Workbook1.xls"></igxl:UltraWebGridExcelExporter>
modle.aspx.cs The code is as follows, defined UltraWebGridExcelExporter And then call Export Function. 

 
protected Infragistics.WebUI.UltraWebGrid.ExcelExport.UltraWebGridExcelExporter UltraWebGridExcelExporter1;
private void Button2_Click(object sender, System.EventArgs e){
    UltraWebGridExcelExporter1.Export(this.UltraWebGrid1);          
}

The above is the whole content of this article, I hope you like it.


Related articles: