This is a migrated thread and some comments may be shown as answers.

Exporting multiple grids to one excel doc

2 Answers 175 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Deasun
Top achievements
Rank 3
Bronze
Bronze
Bronze
Deasun asked on 24 Oct 2019, 12:37 PM
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 Answers, 1 is accepted

Sort by
0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 25 Oct 2019, 12:51 PM
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.
0
Deasun
Top achievements
Rank 3
Bronze
Bronze
Bronze
answered on 25 Nov 2019, 06:10 PM

Thanks.

Worked great.

Tags
GridView
Asked by
Deasun
Top achievements
Rank 3
Bronze
Bronze
Bronze
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Deasun
Top achievements
Rank 3
Bronze
Bronze
Bronze
Share this question
or