[Customauthorize]
Public Fileresult Exportcustomermanagervisitexcel (string datetype, String realvisitdate, String isrenew)
{
string DateFormat = "Yyyy-mm-dd";
Switch (datetype)
{
Case "0": DateFormat = "YYYY-MM-DD"; Break
Case "1": DateFormat = "yyyy-mm"; Break
Case "2": DateFormat = "yyyy"; Break
Default:dateformat = "YYYY-MM-DD"; Break
}
ilist<customermanagervisitstatistics> listtotal = Orderitemmanager.getcustomermanagervisitstatistics ( DateFormat, Realvisitdate, isrenew);
StringWriter strwriter = new StringWriter ();
HtmlTextWriter htmlwriter = new HtmlTextWriter (Strwriter);
if (Listtotal.count > 0)
{
StringBuilder sb = new StringBuilder ();
Sb. Append ("<table cellspacing=\" 0\ "rules=\" all\ "border=\" 1\ "style=\" border-collapse:collapse;\ ">");
Sb. Append ("<thead>");
Sb. Append ("<tr>");
Sb. Append ("<th> Group name </th>");
Sb. Append ("<th> name </th>");
Sb. Append ("<th> date </th>");
Sb. Append ("<th> return visit Total </th>");
Sb. Append ("<th> Total Customer </th>");
Sb. Append ("<th> intent customer ratio (%) </th>");
Sb. Append ("<th> Group return visit Total </th>");
Sb. Append ("<th> Group total Customer </th>");
Sb. Append ("<th> Group average (%) </th>");
Sb. Append ("</tr>");
Sb. Append ("</thead>");
Sb. Append ("<tbody>");
String html = "";
String groupfirstrow = "";
String groupotherrow = "";
String displaygroupname = "";
String groupName = "";
int grouprowspan = 0;
int groupvisitcount = 0;
int groupintentioncount = 0;
foreach (Customermanagervisitstatistics item in Listtotal)
{
if (item. ParentID = = "0")
{
if (Grouprowspan > 0 && groupfirstrow! = "")
{
Groupfirstrow = "<tr><td rowspan=" + grouprowspan.tostring () + ">" + displaygroupname + "</td>" + Grou Pfirstrow + "<td rowspan=" + grouprowspan.tostring () + ">" + groupvisitcount
+ "</td><td rowspan=" + grouprowspan.tostring () + ">" + groupintentioncount + "</td><td rowspan=" + grouprowspan.tostring () + ">";
if (Groupvisitcount = = 0)
{
Groupfirstrow = Groupfirstrow + "0</td></tr>";
}
Else
{
Groupfirstrow = Groupfirstrow + math.round (decimal. Parse ((decimal) groupintentioncount/groupvisitcount * 100). ToString ()), 2). ToString () + "</td></tr>";
}
html = html + groupfirstrow + Groupotherrow;
}
GroupName = Item. GroupName;
Displaygroupname = Item. GroupName + "(" + Item. Customermanagername + ")";
Grouprowspan = 0;
Groupvisitcount = 0;
Groupintentioncount = 0;
Groupfirstrow = "";
Groupotherrow = "";
}
Else
{
Grouprowspan = Grouprowspan + 1;
Groupvisitcount = Groupvisitcount + item. Visitcount;
Groupintentioncount = Groupintentioncount + item. Intentioncount;
if (Grouprowspan = = 1)
{
Groupfirstrow = "<td>" + item. Customermanagername + "</td>" + "<td>" + item. Realvisitdate + "</td>" + "<td>" + item. Visitcount + "</td>" + "<td>" + item. Intentioncount + "<td>" + item. Intentionrate + "</td>";
}
Else
{
Groupotherrow = Groupotherrow + "<tr><td>" + item. Customermanagername + "</td>" + "<td>" + item. Realvisitdate + "</td>" + "<td>" + item. Visitcount + "</td>" + "<td>" + item. Intentioncount + "<td>" + item. Intentionrate + "</td></tr>";
}
}
}
if (Grouprowspan > 0 && groupfirstrow! = "")
{
Groupfirstrow = "<tr><td rowspan=" + grouprowspan.tostring () + ">" + displaygroupname + "</td>" + Grou Pfirstrow + "<td rowspan=" + grouprowspan.tostring () + ">" + groupvisitcount
+ "</td><td rowspan=" + grouprowspan.tostring () + ">" + groupintentioncount + "</td><td rowspan=" + grouprowspan.tostring () + ">";
if (Groupvisitcount = = 0)
{
Groupfirstrow = Groupfirstrow + "0</td></tr>";
}
Else
{
Groupfirstrow = Groupfirstrow + math.round (decimal. Parse ((decimal) groupintentioncount/groupvisitcount * 100). ToString ()), 2). ToString () + "</td></tr>";
}
html = html + groupfirstrow + Groupotherrow;
}
Sb. Append (HTML);
Sb. Append ("</tbody>");
Sb. Append ("</table>");
Strwriter.write (sb.) ToString ());
}
Else
{
Strwriter.writeline ("No data! ");
}
byte[] filecontents = encoding.getencoding ("gb2312"). GetBytes ("Return File (filecontents, "application/vnd.ms-excel", String. Format ("{0}.xls", "Return to statistics Summary" + DateTime.Now.Date.ToString ("YyyyMMdd"));
}
C # HTML Export Excel