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. Image for the cookie policy date
close icon

Export to Excel - Selected row/column

Hi,

I have used Syncfusion.GridExcelConverter.GridExcelConverterControl to export entire content of grid to excel.

However, Is there a way to export to excel:
just few selected row(s) or column(s)(only visible), or range of selected cells for both GGC, DBG.

Thanks,
Pravin


1 Reply

HA haneefm Syncfusion Team October 26, 2007 09:53 PM UTC

Hi Pravin,

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;
}
}
}

For DataBoundGrid Sample :GDBGSelectCellExport.zip
For GroupingGrid Sample Sample :GGCSelectCellExport.zip

Best regards,
Haneef

Loader.
Live Chat Icon For mobile
Up arrow icon