We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on : November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Need to export selected rows from grid to excel

Thread ID:

Created:

Updated:

Platform:

Replies:

56596 Feb 16,2007 09:37 PM UTC Feb 23,2007 07:43 PM UTC WinForms 6
loading
Tags: XlsIO
Sachin Bamel
Asked On February 16, 2007 09:37 PM UTC

I am using syncfusion 4.2 & export gridcontrol to excel using

GridExcelConverterControl.GridToExcel(this.mGrid.Model, filename as string, Syncfusion.GridExcelConverter.ConverterOptions.RowHeaders);

But this method expects either grid control or GridModel. Is there any way I can only export only selected rows to excel.

Thanks,
Sachin

Administrator [Syncfusion]
Replied On February 20, 2007 11:41 PM UTC

Hi Sachin,

There is no built-in support for this. If you want to export the selected cells to excel, you need to derive the GridExcelConverterControl class and implement the SelectedRowExport method. Please refer to the attached sample for more details.

public void SelectedCellsExport(GridModel model,string FileName)
{
ExcelEngine engine = CreateEngine();
IWorkbook book = engine.Excel.Workbooks.Create( 1 );
IWorksheet sheet = book.Worksheets[ 0 ];
GridRangeInfoList list = model.SelectedRanges;
foreach( GridRangeInfo range in list)
{
switch( range.RangeType)
{
case GridRangeInfoType.Cells:
ExportCells(range,model,sheet);
break;
case GridRangeInfoType.Cols:
ExportCells(GridRangeInfo.Cells(1,range.Left,model.RowCount,range.Right),model,sheet);
break;
case GridRangeInfoType.Rows:
ExportCells(GridRangeInfo.Cells(range.Top,1,range.Bottom,model.ColCount),model,sheet);
break;
}
}
book.SaveAs(FileName);
book.Close();
}
public void ExportCells(GridRangeInfo range, GridModel model, IWorksheet sheet)
{
for(int i = range.Top, iRowRange = 1 ;i<= range.Bottom;i++,iRowRange++)
{
for(int j = range.Left,iColRange = 1 ;j<= range.Right;j++,iColRange++)
{
this.CopyStyle( model[i,j],sheet[iRowRange,iColRange]);
sheet[iRowRange,iColRange].Text = model[i,j].FormattedText;
}
}
}

Sample :GDBGExport.zip

Best regards,
Haneef

Administrator [Syncfusion]
Replied On February 21, 2007 05:38 PM UTC

Hi Hannef,

I am able to export selected rows. Thanks for your help. But I could not export row header now . As it was possible earlier with

gecc.GridToExcel(this.mGrid.Model, filename as string, Syncfusion.GridExcelConverter.ConverterOptions.RowHeaders);

Can I specify ConverterOptions also with the fix given by you.

Also there is a problem when i exceeds rows larger than 65536 which is the largest rows supported by excel.

Thanks,
Sachin

>Hi Sachin,

There is no built-in support for this. If you want to export the selected cells to excel, you need to derive the GridExcelConverterControl class and implement the SelectedRowExport method. Please refer to the attached sample for more details.

public void SelectedCellsExport(GridModel model,string FileName)
{
ExcelEngine engine = CreateEngine();
IWorkbook book = engine.Excel.Workbooks.Create( 1 );
IWorksheet sheet = book.Worksheets[ 0 ];
GridRangeInfoList list = model.SelectedRanges;
foreach( GridRangeInfo range in list)
{
switch( range.RangeType)
{
case GridRangeInfoType.Cells:
ExportCells(range,model,sheet);
break;
case GridRangeInfoType.Cols:
ExportCells(GridRangeInfo.Cells(1,range.Left,model.RowCount,range.Right),model,sheet);
break;
case GridRangeInfoType.Rows:
ExportCells(GridRangeInfo.Cells(range.Top,1,range.Bottom,model.ColCount),model,sheet);
break;
}
}
book.SaveAs(FileName);
book.Close();
}
public void ExportCells(GridRangeInfo range, GridModel model, IWorksheet sheet)
{
for(int i = range.Top, iRowRange = 1 ;i<= range.Bottom;i++,iRowRange++)
{
for(int j = range.Left,iColRange = 1 ;j<= range.Right;j++,iColRange++)
{
this.CopyStyle( model[i,j],sheet[iRowRange,iColRange]);
sheet[iRowRange,iColRange].Text = model[i,j].FormattedText;
}
}
}

Sample :GDBGExport.zip

Best regards,
Haneef

Administrator [Syncfusion]
Replied On February 21, 2007 08:44 PM UTC

Hi Sachin,

Here is a minimal sample that shows you "How to export the selected cell ranges with column header in the grid to excel?". Please try the attached sample and let me know if this helps.

sample : GDBGExportRowHeader.zip

Best regards,
Haneef

Sachin Bamel
Replied On February 21, 2007 11:22 PM UTC

Hi Haneef,

Thanks for your fix. I will appreciate if you can help me to export selected rows from grouping grid also.

Thanks,
Sachin


Administrator [Syncfusion]
Replied On February 22, 2007 08:25 PM UTC

Hi Sachin,

Here is a minimal sample that shows you "How to export the selected rows in a GroupingGrid to Excel?". Please refer the sample and let me know if this helps.
GGCSelecterRow_ExcelExport.zip

Best regards,
Haneef

Administrator [Syncfusion]
Replied On February 23, 2007 07:43 PM UTC

Hi Haneef,

This solution works when grid is expanded. Is it possible to do multiple selection when the grid is collapsed & export selected rows.

Thanks,
Sachin

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;