When I cancel the grid_ElementExporting event for all cells in the row, but not for the row itself, it leaves an empty record in Excel file. Is there any way to eliminate these empty records? Please advise. Thanks.
grid_ElementExporting()
grid_ElementExported()
resulting Excel file - see attached picture.
grid_ElementExporting()
private
void
grdDataView_ElementExporting(
object
sender, GridViewElementExportingEventArgs e)
{
if
(e.Element == ExportElement.HeaderCell || e.Element == ExportElement.Cell)
e.Cancel =
true
;
}
grid_ElementExported()
private
void
grdDataView_ElementExported(
object
sender, GridViewElementExportedEventArgs e)
{
if
(e.Element == ExportElement.HeaderRow)
{
e.Writer.Write(String.Format(@
"<td>{0}</td>"
,
"Plan Code"
));
}
if
(e.Element == ExportElement.Row)
{
JobDetailModel obj = e.Context
as
JobDetailModel;
e.Writer.Write(String.Format(@
"<td>{0}</td>"
, obj.PlanCode));
}
}
resulting Excel file - see attached picture.
5 Answers, 1 is accepted
0
Hi Boris,
I have prepared a sample project, showing this. You may review how it is working. Regards,
Didie
the Telerik team
You have empty records as you do not exclude them when exporting. That is why the ElementExported event is fired for these rows. If you want to remove these rows from the result excel file, you should remove all empty rows in the output stream, like:
var strm =
new
MemoryStream();
this
.clubsGrid.Export(strm, exportOptions);
var reader =
new
StreamReader(strm);
strm.Position = 0;
var text = reader.ReadToEnd();
text = text.Replace(
"<tr>\r\n</tr>"
,
""
);
var writer =
new
StreamWriter(stream);
writer.Write(text);
writer.Flush();
I have prepared a sample project, showing this. You may review how it is working. Regards,
Didie
the Telerik team
Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Public Issue Tracking
system and vote to affect the priority of the items
0
bkagan98
Top achievements
Rank 1
answered on 06 Jun 2011, 04:54 PM
Hi Didie,
My data grid contains hundreds of thousands records and if I do everything in the memory stream, will it affect the performance?
Thanks.
My data grid contains hundreds of thousands records and if I do everything in the memory stream, will it affect the performance?
Thanks.
0
bkagan98
Top achievements
Rank 1
answered on 06 Jun 2011, 11:20 PM
That worked. One more question: would it be possible to show gridlines in generated XLS file? If yes, would you please tell how? Thanks.
0
Hi Boris,
Didie
the Telerik team
Unfortunately showing gridlines in generated export XLS file would not be possible.
If you have any further questions, please do not hesitate to contact us.
Didie
the Telerik team
Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Public Issue Tracking
system and vote to affect the priority of the items
0
Prithvi
Top achievements
Rank 1
answered on 08 Mar 2012, 04:03 PM
Hi,
Am very new to telerick control. Please let me know how to export data from radGridview to Excel (SILVERLIGHT). Please help me
While esporting the data if there is date field/combo box field in RadGrid, that data is not getting export to Excel instead it is showing empty cell(data missing ).
Thanks in advance. please help me.
Prithvi
Am very new to telerick control. Please let me know how to export data from radGridview to Excel (SILVERLIGHT). Please help me
While esporting the data if there is date field/combo box field in RadGrid, that data is not getting export to Excel instead it is showing empty cell(data missing ).
Thanks in advance. please help me.
Prithvi