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

Export to Excel - Selected row/column

Thread ID:

Created:

Updated:

Platform:

Replies:

69427 Oct 26,2007 04:35 PM UTC Oct 26,2007 09:53 PM UTC WinForms 1
loading
Tags: GridControl
Pravin Patel
Asked On October 26, 2007 04:35 PM UTC

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


haneefm [Syncfusion]
Replied On 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

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

;