Exporting multiple grids to one excel doc

3 posts, 1 answers
  1. Deasun
    Deasun avatar
    31 posts
    Member since:
    May 2019

    Posted 24 Oct 2019 Link to this post

    grid export function

    WINFORMS
        gridview ver: 2019.3.917.40

    What happens is the excel doc ends up with only the one sheet, the 2nd one.
    Why?
    What am I doing wrong?

    I send in;
         a grid Telerik.WinControls.UI.RadGridView objGrid
         SheetName
         NbrOfGrids
        
    Calling code!
         strDocToOpen = exportGrid(radGrid1, "sheetname1", 2);
         strDocToOpen = exportGrid(radGrid2, "sheetname2", 2);
        
         Call to Open strDocToOpen
        

    EXPORT Function code!

    // export the grid to an excel file
    Telerik.WinControls.Export.GridViewSpreadExport exporter = new Telerik.WinControls.Export.GridViewSpreadExport(objGrid)
    {
        ExportFormat = Telerik.WinControls.Export.SpreadExportFormat.Xlsx
    };
    Telerik.WinControls.Export.SpreadExportRenderer exporterRenderer = new Telerik.WinControls.Export.SpreadExportRenderer();

    exporter.SheetName = strSheetName;   

    // if more then one grid to be in exceldoc
    if (intNbrOfGrids > 1)
    {
        exporter.FileExportMode = Telerik.WinControls.Export.FileExportMode.NewSheetInExistingFile;
    };

    string strPathToMyDocuments = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
    strFileName = "MyDoc";

    exporter.RunExport(strPathToMyDocuments + @"\" + strFileName + ".xlsx", exporterRenderer);
     
    Returns  (strPathToMyDocuments + @"\" + strFileName + ".xlsx")
  2. Answer
    Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3624 posts

    Posted 25 Oct 2019 Link to this post

    Hello, Deasun,        

    The GridViewSpreadExport.FileExportMode property determines whether the data will be exported into an existing or a new file. Setting it to NewSheetInExistingFile will create a new sheet in an already existing file.

    I have prepared a sample project for your reference which seems to export both grids on two sheets in a single file. Please refer to the attached zip file. Could you please give it a try and see how it works for your scenario?

    I hope this information helps. If you need any further assistance please don't hesitate to contact me.

    Regards,
    Dess | Tech Support Engineer, Sr.
    Progress Telerik

    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. Deasun
    Deasun avatar
    31 posts
    Member since:
    May 2019

    Posted 25 Nov 2019 in reply to Dess | Tech Support Engineer, Sr. Link to this post

    Thanks.

    Worked great.

Back to Top