Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
240
Can UltraWebGrid Exptor to Excel In Multi-sheet
posted

Hi team,

Now I am in such a situation, I have a urtalwebgrid  and one of its colums named "category" ,and has three categories. When I use the UltraGridExcelExporter to export the webgrid I want to create three spreadsheets in a workbook,say "A","B","C",and exprot the data the each spreadsheet according to the colum named "category", just like rows with category "A", export to spreadsheet "A"; rows with category "B", export to spreadsheet "B"; rows with category "C", export to spreadsheet "C".

Can anyone give me some help.

Thanks Inadvance.

Parents
No Data
Reply
  • 49378
    Verified Answer
    posted

    Hi sunqy1212,

    Thank you for posting in the community.

    I am attaching a sample illustrating how your requirement can be achieved by creating a grid to be exported for each sheet and filtering the original datasource.  Below is the code used in this case:

    Code Snippet
    1.     protected void Button1_Click(object sender, EventArgs e)
    2.     {
    3.         UltraWebGrid grid1 = new UltraWebGrid();
    4.         UltraWebGrid grid2 = new UltraWebGrid();
    5.         UltraWebGrid grid3 = new UltraWebGrid();
    6.  
    7.         grid1.DataSource = GetData().Where(c => c.CategoryName == "A");
    8.         grid1.DataBind();
    9.         form1.Controls.Add(grid1);
    10.  
    11.         grid2.DataSource = GetData().Where(c => c.CategoryName == "B");
    12.         grid2.DataBind();
    13.         form1.Controls.Add(grid2);
    14.  
    15.         grid3.DataSource = GetData().Where(c => c.CategoryName == "C");
    16.         grid3.DataBind();
    17.         form1.Controls.Add(grid3);
    18.  
    19.         UltraWebGridExcelExporter1.ExportMode = Infragistics.WebUI.UltraWebGrid.ExcelExport.ExportMode.Custom;
    20.  
    21.         Workbook book = new Workbook();
    22.         book.Worksheets.Add("grid1");
    23.         book.Worksheets.Add("grid2");
    24.         book.Worksheets.Add("grid3");
    25.  
    26.         UltraWebGridExcelExporter1.Export(grid1, book.Worksheets["grid1"]);
    27.         UltraWebGridExcelExporter1.Export(grid2, book.Worksheets["grid2"]);
    28.         UltraWebGridExcelExporter1.Export(grid3, book.Worksheets["grid3"]);
    29.  
    30.         UltraWebGridExcelExporter1.ExportMode = Infragistics.WebUI.UltraWebGrid.ExcelExport.ExportMode.Download;
    31.  
    32.         UltraWebGrid dummy = new UltraWebGrid();
    33.         form1.Controls.Add(dummy);
    34.         UltraWebGridExcelExporter1.Export(dummy, book);
    35.  
    36.     }
    37. }

     Please note that the UltraWebGrid control is now outdated and as of .NetAdvantage 2011 Volume 2 is no longer included in our product package. I would suggest that you consider switching to the WebDataGrid/WebHieararchicalDataGrid. More information regarding these controls is available at:

    http://help.infragistics.com/NetAdvantage/ASPNET/2011.2/CLR4.0/?page=Web_WebDataGrid_WebDataGrid.html

    Additional samples demonstrating the features of these grids can be found at:
    http://samples.infragistics.com/aspnet/

    Hope this helps.

    UltraWebGridExportInDifferentSheetsBasedOnValues.zip
Children