用table导出Excel

 1   public string TableContent()
 2   {
 3           IList<ActionListInfo> lt = cache.Get(listCache) as IList<ActionListInfo>;
 4             StringBuilder builder = new StringBuilder();
 5             if (lt != null)
 6             {
 7                 System.Reflection.PropertyInfo[] myPropertyInfo = lt.Firs().GetTyp ().GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
 8                 int i = 0, j;
 9                 builder.Append("<table border='1'>");
10                 builder.Append("<tr>");
11                 for (i = 0, j = myPropertyInfo.Length - 1; i < j; i++)
12                 {
13                     System.Reflection.PropertyInfo pi = myPropertyInfo[i];
14                     string headname = pi.Name;//单元格头部
15                     builder.Append("<th>" + headname + "</th>");
16                 }
17                 builder.Append("</tr>");
18                 foreach (ActionListInfo t in lt)
19                 {
20                    string state=myPropertyInfo[9].GetValue(t,null).ToString();
21                     builder.Append("<tr>");
22                     builder.Append("<td  style='textalign:left;"+color+"'>" +str+"</td>");                   
23                  }
24                   builder.Append("</tr>");            
25                   builder.Append("</table>");
26             }
27             return builder.ToString();
28    }

 

  

posted @ 2012-06-15 13:50  fycaijing  阅读(302)  评论(0编辑  收藏  举报