Introduction to WebExcelExporter, part of upcoming NetAdvantage for ASP.NET 10.2

Good news for everyone using Infragistics NetAdvantage for ASP.NET. The upcoming 10.2 release will include WebExcelExporter control!

The WebExcelExporter control allows you to automatically export Grid data. No matter  what kind of Infragistics DataGrid you are using (WebDataGrid or WebHierarchicalDataGrid), you can easily achieve your goal to get the data into an Excel™ file, in the format of your choice. The Excel™ file formats that are supported are Excel™ 97 to Excel™ 2003 (all these versions share a common format) and Excel™ 2007.

WebExcelExporter is separate control which lives in Infragistics.Web.UI.GridControls namespace, so you don’t need any additional tag prefixes or namespace declarations in order to use it.

 

Here is a list of features that are currently supported by WebExcelExporter:

·         ExportMode – defines the way exported files are presented. Files can be either sent to the browser for automatic downloading, or just saved to a WorkBook instance, so you decide what to do with the result

·         Exporting more than one grid at once, with an additional option specifying whether to export all grids in same WorkSheet, or each grid on a separate WorkSheet (default)

·         Exporting only grid data (when you have Paging or VirtualScrolling enabled) or the whole data in data source

·         Exporting into multiple Excel™ file formats (Excel™ 97 / Excel™ 2003 and Excel™ 2007)

·         Exporting styles, so you don’t lose the look and feel of your application

·         Exporting data in provided WorkBook or WorkSheet instance

·         Specifying row offset and column offset in the WorkSheet for exported data

·         Server events, which you can handle to apply your custom logic before or after the data is exported, as well as on each exported row

Before You Begin

In order to compile and run the samples illustrated here, you will need to install NetAdvantage for ASP.NET v. 10.2. You will also need a running instance of SQL Server (either Express or any other edition), and you will need to have the NorthWind data base attached to your SQL Server instance. You can either install the NorthWind data base following instructions at: http://msdn.microsoft.com/en-us/library/aa276825%28SQL.80%29.aspx or download the data base directly from: http://www.microsoft.com/downloads/details.aspx?familyid=06616212-0356-46a0-8da2-eebc53a68034&displaylang=en

Follow these steps:

1)      Create a web page (ASP.NET Web Form) with WebDataGrid bound to some Data Source

In HTML:

<ig:WebDataGrid runat="server" ID="wdgCustomers"

        DataSourceID="SqlDsCustomers"

        DataKeyFields="CustomerID"

        AutoGenerateColumns="false"

        >

            <Columns>

                <ig:BoundDataField Key="Country" DataFieldName="Country"
Header-Text="Country" />

                <ig:BoundDataField Key="City" DataFieldName="City"
Header-Text="City" />

                <ig:BoundDataField Key="CompanyName" DataFieldName="CompanyName"
Header-Text="Company" />

                <ig:BoundDataField Key="ContactName" DataFieldName="ContactName"
Header-Text="Contact" />

                <ig:BoundDataField Key="Phone" DataFieldName="Phone"
Header-Text="Phone" />

            </Columns>

        </ig:WebDataGrid>

 

        <asp:SqlDataSource runat="server"ID="SqlDsCustomers"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT * FROM [Customers] ORDER BY [Country]">

        </asp:SqlDataSource>

 

 

2)      Drag a WebExcelExporter control from the Visual Studio Toolbox onto your page:

a.       Set the WebExcelExporter’s property ExportMode to Download

b.      Set the control’s ID property to WebExcelExporter

c.       Set the control’s DownloadName property to “ExportedData”

In HTML:

<ig:WebExcelExporter runat="server" ID="WebExcelExporter"
ExportMode ="Download"
DownloadName="ExportedData" />

 

3)      Drag a Button control from Visual Studio Toolbox onto your page:

a.       Set the button’s ID property to btnExport

b.      Set the control’s Text property to “Export Data”

c.       Set the control’s OnClick to “btnExport_Click”

d.      Define the “btnExport_Click” handler in the code-behind and call one of the WebExcelExporter Export() method overloads

In HTML:

<asp:Button runat="server" ID="btnExport"
Text="Export Data" OnClick="btnExport_Click" />

 

In Code Behind (C#):

protected void btnExport_Click(object sender, EventArgs e)

{

    this.WebExcelExporter.Export(this.wdgCustomers);

}

 

 

4)      Run the application.

5)      Click the “Export Data” button.

After clicking the “Export Data” button, your browser will ask you whether you want to open or save file named “ExportedData.xls”.

So impatient for the release! Only a few days have left!


Comments  (9 )

321wolfgang
on Mon, Jun 14 2010 3:06 AM

Hi,

When will 10.2 with WebExcelExporter be available for download?

best regards

Wolfgang

Anton Staykov
on Wed, Jun 16 2010 5:20 PM

Hello,

They are now! Go and download fully functional trial!

vijayasingh
on Thu, Jul 22 2010 9:50 PM

Hi ,

same thing is not working when i bind with dataset directly?

Anton Staykov
on Fri, Jul 23 2010 7:34 AM

Hi,

In case of binding to data sources in the code behind you must make sure that you assign the data source object to the DataSource property of WebDataGrid on every page load (regardless of whether or not it is a PostBack action). You do not need to explicitly call DataBind() since it is invoked internally.

Please download this sample:

blogs.infragistics.com/.../WebExcelExporter_5F00_DataSet.zip

And let me know if youhave any issues using the WebExcelExporter. The sample uses DataSet as Grid's DataSource and prefill it using SQL DataAdapter from the Northwind database.

jcaudana
on Mon, Aug 2 2010 3:55 PM

Hi, I have in my webdatagrid a column templetedatafield with an image, but when I exported to excel this column is a html code, how can i export the image column of webdatagrid to excel?

Anton Staykov
on Tue, Aug 3 2010 4:38 AM

Hi jcaudana,

Currently we do not support exporting of Images in WebExcelExporter.

About TemplatedDataFields - if your template does not contain a servier side controls, it will most probably be exported. If a templated data field contains a server side controls, it cannot be exported.

seanham011
on Fri, Apr 22 2011 2:36 PM

I hope this thread isn't too stale, how do we set the single worksheet vs multiples?  I have a page with 6 grids set into distinct ultrawebtab tabs, and I can get them to all export into a single spreadsheet, but they all show up on the same 'worksheet' (despite the description saying default behavior is to multiple sheets) what is the attribute-setting to Force export to multiple sheets?

Thanks!

Shyam
on Wed, Jan 18 2012 2:56 AM

Hi

I have an issue in exporting like I have an behaviour SummaryRowand when exporting data to excel SummaryRow is not exported, please suggest how to het that and want to format data when exporting

void uwgeeDashboard_CellExported(object sender, ExcelCellExportedEventArgs e)

       {

           if (e.IsHeaderCell)

               e.WorksheetCell.Value = e.WorksheetCell.Value.ToString().Replace("<br />", "\n");

           if (e.IsSummaryCell && e.Summary != null)

           {

               string sFormat = e.WorksheetCell.CellFormat.ToString(); //e.Column.Format;

               if (sFormat != null && sFormat == "C")

               {

                   string sSymbol = LanguageManager.CurrentCulture.NumberFormat.CurrencySymbol;

                   e.Worksheet.Columns[5].CellFormat.FormatString = sSymbol + "#,##0.00;(" + sSymbol + "#,##0.00);-";

               }

           }

       }

Raj kumar
on Thu, Aug 29 2013 2:16 AM

Hi,

    I'm having an issue in exporting images from webdatagrid to MS Excel using webexcelexporter, is it possible to export image in excel? plz give some idea..

    Thanks in advance..

Add a Comment

Please Login or Register to add a comment.