Exxort multiple grids to one excel file

Hi gang, Is it possible to somehow combine the results of several grids into a single file for Excel. I''d be happy with either having the result appear in excel as one grid per worksheet, or just having the multiple grids stack up vertically on one worksheet.

5 Replies

AD Administrator Syncfusion Team May 26, 2006 03:47 AM UTC

Hi Ralph, Yes it is possible to export multiple grids to a single XLS file as worksheets. Below is a code snippet. using Syncfusion.XlsIO; using Syncfusion.GridExcelConverter; private void button2_Click(object sender, System.EventArgs e) { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "Files(*.XLS)|*.XLS"; saveFileDialog.AddExtension = true; saveFileDialog.DefaultExt = ".XLS"; if(saveFileDialog.ShowDialog() == DialogResult.OK && saveFileDialog.CheckPathExists) { GridExcelConverterControl gec = new GridExcelConverterControl(); IWorkbook workBook = ExcelUtils.CreateWorkbook(new string[] {"Sheet1","Sheet2"}); gec.GridToExcel(this.gridControl1.Model, workBook.Worksheets[0]); gec.GridToExcel(this.gridControl2.Model, workBook.Worksheets[1]); workBook.SaveAs(saveFileDialog.FileName); workBook.Close(); ExcelUtils.ThrowNotSavedOnDestroy = false; } } } Regards, Calvin.


AD Administrator Syncfusion Team May 31, 2006 09:11 AM UTC

Calvin, Thanks for the (great) reply. I had not inferred the poss. from the api docs, so I''m grateful for your tip.


HA Harish April 10, 2008 02:11 PM UTC

Thanks for the sample code. I have another question related to this. Is there a way to name the worksheets that are created?



HA Harish April 10, 2008 03:32 PM UTC

Also I observed that every percentage column shows incorrect data. For ex 60% is shown as 0.6 in the excel. Any means to avoid this and show the actual value?



SR Sri Rajan Syncfusion Team April 25, 2008 03:09 PM UTC

HiRalph,

Thank you for your patience.

Issue 1:Is there a way to name the worksheets that are created?
>>>>>
Please refer the below code snippet to name a worksheet after it was created.
workBook.Worksheets[0].Name = "S1";

Issue 2: Problem in Percentage Column value.
>>>>
Percentage cell value is perfectly converted and displayed as correct value in excel(60% in grid is displayed as 60% in excel).Here is the minimal sample which shows this issue.
http://websamples.syncfusion.com/samples/Grid.Windows/F44533/main.htm

Please let me know if this helps.

Best Regards,
Srirajan



Loader.
Up arrow icon