/// <summary>
/// Export a group of objects to EXCEL
/// </summary>
/// <typeparam name="T">Type of the object to be exported</typeparam>
/// <param name="objList">A group of objects</param>
/// <param name="FileName">Exported file name</param>
/// <param name="columnInfo">Column name information</param>
public static void ExExcel<T>(List<T> objList, string FileName, Dictionary<string, string> columnInfo)
{
if ( == 0) { return; }
if ( == 0) { return; }
//Generate HTML of EXCEL
string excelStr = "";
Type myType = objList[0].GetType();
//Get the attribute to be displayed based on the reflection from the attribute name information passed in.
List<PropertyInfo> myPro = new List<PropertyInfo>();
foreach (string cName in )
{
PropertyInfo p = (cName);
if (p != null)
{
(p);
excelStr += columnInfo[cName] + "\t";
}
}
//End if no available attributes are found
if ( == 0) { return; }
excelStr += "\n";
foreach (T obj in objList)
{
foreach (PropertyInfo p in myPro)
{
excelStr += (obj, null)+"\t";
}
excelStr += "\n";
}
//Output EXCEL
HttpResponse rs = ;
= ("GB2312");
("Content-Disposition", "attachment;filename=" + FileName);
= "application/ms-excel";
(excelStr);
();
}