/**/ /// <Summary>
/// Export from DataGrid
/// </Summary>
/// <Param name = "DG"> Source data grid </Param>
/// <Param name = "M"> Largest row </Param>
/// <Param name = "N"> Maximum Column </Param>
/// <Param name = "Header"> Header of the columns to be hidden in the Excel worksheet [you also need to set the column header to placeholder]. </Param>
/// <Param name = "hidecolumnindex"> Index of the column to be hidden [starting from 0] </Param>
Public Void Exportexcelbydatagrid (system. Web. UI. webcontrols. DataGrid DG, Int M, Int N, String [] Header, Params Byte [] Hidecolumnindex)
{
// Replace & nbsp;
For ( Int I = 0 ; I < DG. Items. Count; I ++ )
{
For ( Int J = 0 ; J < DG. Columns. Count; j ++ )
{
If (DG. items [I]. cells [J]. Text = " & Nbsp; " )
{
DG. items [I]. cells [J]. Text= "";
}
}
}
Excel = New Excel ();
// Excel. setlicense (systemconfig. getjavasstr ("aposeexcellicense"), (system. Web. UI. Page) system. Web. httpcontext. Current. Handler );
Worksheet Sheet = Excel. worksheets [ 0 ];
Sheet. cells. importdatagrid (DG, 0 , 0 , M, n, True );
Foreach ( Byte Index In Hidecolumnindex)
{
Sheet. cells. hidecolumn (INDEX );
}
// Add the header
Sheet. cells. insertrow ( 0 );
For ( Byte I = 0 ; I < Header. length; I ++ )
{
Sheet. cells [0, I]. putvalue (header [I]);
}
Sheet. Name = " Sheet1 " ;
Excel. Save ( " Export.xls " , Savetype. openinbrowser, fileformattype. Default, httpcontext. Current. Response );
}