Private void getexcel ()
{
Userlogin ul = (userlogin) session ["userinfo"];
Dataset DS = new dataset ();
If (infomainclass. enabled)
{
DS = new childrenmanager (). getchildrenlist (keywords. Text, convert. toint32 (infomainclass. selectedvalue ));
}
Else {
DS = new childrenmanager (). getchildrenlist (keywords. Text, ul. childschoolid );
}
Stringbuilder where = new stringbuilder ();
If (! Common. nullcheck. datasetisnull (DS) // determines whether the DS is empty ,,
{
Stringbuilder finalhtml = new stringbuilder ();
Finalhtml. appendline ("<HTML> Finalhtml. appendline ("<style type = \" text/CSS \ "> tr {Height: 25px ;}</style> ");
Finalhtml. append (gettablehtml (DS ));
Finalhtml. appendline ("</body>
Httpresponse resp = httpcontext. Current. response;
Stringbuilder sb = new stringbuilder ();
Resp. contentencoding = system. Text. encoding. utf8;
Resp. contenttype = "application/MS-excel ";
Resp. appendheader ("content-disposition", "attachment?filename=child.xls ");
Resp. Write (finalhtml. tostring ());
Resp. End ();
}
Else
{
Clientscript. registerstartupscript (this. GetType (), "nodata", "alert (\" cannot find qualified students! \ "); Window. Close ();", true );
}
}
String [] Columns = {"school name", "name", "Household Register Type", "certificate number", "gender", "Date of Birth", "ethnicity ", "domicile registration address", "actual residence", "Father's name", "Father's phone number", "Mother's name", "Mother's phone number", "other guardian's name ", "Relationship between other guardians and children", "telephone number of other guardians"
};
String [] colnames = {"school name", "name", "Household Register Type", "certificate number", "gender", "Date of Birth", "nationality ", "domicile registration address", "actual residence", "Father's name", "Father's phone number", "Mother's name", "Mother's phone number", "other guardian's name ", "Relationship between other guardians and children", "telephone number of other guardians"
};
Private string gettablehtml (Dataset DS)
{
Stringbuilder finalhtml = new stringbuilder ();
Finalhtml. appendline ("<Table border = 1 style = \" font-size: 14px; \ "> ");
// Generate the title line
Finalhtml. appendline ("<tr> ");
For (INT I = 0; I <columns. length; I ++)
{
Finalhtml. appendformat ("<TD> {0} </TD>", colnames [I]);
}
Finalhtml. appendline ("</tr> ");
Foreach (datarow DR in DS. Tables [0]. Rows)
{
Finalhtml. appendline ("<tr> ");
For (INT I = 0; I <columns. length; I ++)
{
String colname = columns [I];
Object val = Dr [colname];
// Handle Special Cases
If (colname. Equals ("Date of Birth") | colname. indexof ("date")> = 0)
{
Try
{
Val = convert. todatetime (VAL). tostring ("yyyy-mm-dd ");
}
Catch {}
}
Finalhtml. appendformat ("<TD style = \" Vnd. ms-excel.numberformat: @ \ ">{0} </TD>", Val );
}
Finalhtml. appendline ("</tr> ");
}
Finalhtml. appendline ("</table> ");
Return finalhtml. tostring ();
}
Protected void button#click (Object sender, imageclickeventargs E)
{
Getexcel ();
}