List <portresourceinfo> List = getlist () // obtain the data source
// Export excle
Response. Clear ();
Response. contenttype = "application/Excel ";
Response. addheader ("content-disposition", "inline; filename =" + httputility. urlencode ("port resource .xls", encoding. utf8 ));
Stringbuilder expstr = new stringbuilder ();
System. Io. stringwriter Sw = new system. Io. stringwriter (expstr );
Expstr. append ("<HTML> <body> ");
Expstr. append ("<Table> <tr> <TH> NO. </Th> <TH> device name </Th> <TH> Device Model </Th> <TH> device IP Address </Th> <TH> port name </Th> <TH> port description </Th> <TH> port bandwidth </Th> <TH> up/down </Th>> <TH> port status </Th> </tr> ");
Int I = 1;
Foreach (VAR item in List)
{
Expstr. appendformat ("<tr> <TD> {0} </TD> <TD >{1} </TD> <TD >{2} </TD> <TD> {3} </TD> <TD >{4} </TD> <TD >{5} </TD> <TD >{6} </TD> <TD> {7} </TD> <TD >{8} </TD> </tr> ",
I, item. devicename, item. divecetype,
Item. IPaddress, item. ifname, item. description,
Item. ifspeed, item. upordown, item. isfree
);
I ++;
}
Expstr. append ("</table> </body> Page. enableviewstate = false;
Response. Write (SW. tostring ());
Response. End ();
Export Excel after obtaining data