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.
Unfortunately, activation email could not send to your email. Please try again.

Export to Excel - Selected row/column

Thread ID:

Created:

Updated:

Platform:

Replies:

69427 Oct 26,2007 12:35 PM Oct 26,2007 05:53 PM Windows Forms 1
loading
Tags: GridControl
Pravin Patel
Asked On October 26, 2007 12:35 PM

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 05:53 PM

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.

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.

;