Tip: Change your loop to the following to also support derived classes:
foreach (var item in controlList )
{
GridView asGridView = item as GridView;
if (asGridView != null)
{
Utilities.RenderControlInExcel(asGridView, workBook);
}
DetailsView asDetailsView = item as DetailsView;
if (asDetailsView != null)
{
detailsRowStart = Utilities.RenderControlInExcel(
asDetailsView, detailsSheet, detailsRowStart);
}
Add a using
statement to WriteToResponse
:
using(System.IO.MemoryStream theStream = new System.IO.MemoryStream()){
}
The term view.Rows[row].Cells[col].
is used many times. Extract to a variable to improve performance and readability.