asp.netÀïµ¼³öexcel±í·½·¨»ã×Ü
1¡¢ÓÉdatasetÉú³É
public void CreateExcel(DataSet ds,string typeid,string FileName)
{
HttpResponse resp;
resp = Page.Response;
resp.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
resp.AppendHeader("Content-Disposition", "attachment;filename=" + FileName);
string colHeaders= "", ls_item="";
int i=0;
//¶¨Òå±í¶ÔÏóÓëÐжÔÏñ£¬Í¬Ê±ÓÃDataSet¶ÔÆäÖµ½øÐгõʼ»¯
DataTable dt=ds.Tables[0];
DataRow[] myRow=dt.Select("");
// typeid=="1"ʱµ¼³öΪEXCEL¸ñʽÎļþ£»typeid=="2"ʱµ¼³öΪXML¸ñʽÎļþ
if(typeid=="1")
{
//È¡µÃÊý¾Ý±í¸÷ÁбêÌ⣬¸÷±êÌâÖ®¼äÒÔ\t·Ö¸î£¬×îºóÒ»¸öÁбêÌâºó¼Ó»Ø³µ·û
for(i=0;i colHeaders+=dt.Columns[i].Caption.ToString()+"\t";
colHeaders +=dt.Columns[i].Caption.ToString() +"\n";
//ÏòHTTPÊä³öÁ÷ÖÐдÈëÈ¡µÃµÄÊý¾ÝÐÅÏ¢
resp.Write(colHeaders);
//ÖðÐд¦ÀíÊý¾Ý
foreach(DataRow row in myRow)
{
//ÔÚµ±Ç°ÐÐÖУ¬ÖðÁлñµÃÊý¾Ý£¬Êý¾ÝÖ®¼äÒÔ\t·Ö¸î£¬½áÊøʱ¼Ó»Ø³µ·û\n
for(i=0;i ls_item +=row[i].ToString() + "\t";
ls_item += row[i].ToString() +"\n";
//µ±Ç°ÐÐÊý¾ÝдÈëHTTPÊä³öÁ÷£¬²¢ÇÒÖÿÕls_itemÒÔ±ãÏÂÐÐÊý¾Ý
resp.Write(ls_item);
ls_item="";
}
}
else
{
if(typeid=="2")
{
//´ÓDataSetÖÐÖ±½Óµ¼³öXMLÊý¾Ý²¢ÇÒдµ½HTTPÊä³öÁ÷ÖÐ
resp.Write(ds.
Ïà¹ØÎĵµ£º
ÌõÐÎÂëÊÇÆù½ñΪֹ×á¢ÊµÓõÄÒ»ÖÖ×Ô¶¯Ê¶±ð¼¼Êõ¡£ÌõÐÎÂë¼¼Êõ¾ßÓÐÒÔϼ¸¸ö·½ÃæµÄÓŵã
¡¡¡¡A£®ÊäÈëËٶȿ죺Óë¼üÅÌÊäÈëÏà±È£¬ÌõÐÎÂëÊäÈëµÄËÙ¶ÈÊǼüÅÌÊäÈëµÄ5±¶£¬²¢ÇÒÄÜʵÏÖ“¼´Ê±Êý¾ÝÊäÈ딡£
¡¡¡¡B£®¿É¿¿ÐԸߣº¼üÅÌÊäÈëÊý¾Ý³ö´íÂÊΪÈý°Ù·ÖÖ®Ò»£¬ÀûÓùâѧ×Ö·ûʶ±ð¼¼Êõ³ö´íÂÊΪÍò·ÖÖ®Ò»£¬¶ø²ÉÓÃÌõÐÎÂë¼¼ÊõÎóÂëÂʵ ......
ÔÚWeb±à³Ì¹ý³ÌÖУ¬´æÔÚןܶలȫÒþ»¼¡£±ÈÈçÔÚÒÔÇ°µÄASP°æ±¾ÖУ¬CookieΪ·ÃÎÊÕߺͱà³ÌÕ߶¼ÌṩÁË·½±ã£¬²¢Ã»ÓÐÌṩ¼ÓÃܵŦÄÜ¡£´ò¿ªIEä¯ÀÀÆ÷£¬Ñ¡Ôñ“¹¤¾ß”²Ëµ¥ÀïµÄ“InternetÑ¡Ï¬È»ºóÔÚµ¯³öµÄ¶Ô»°¿òÀïµ¥»÷“ÉèÖÔ°´Å¥£¬Ñ¡Ôñ“²é¿´Îļþ”°´Å¥£¬ÔÚµ¯³öµÄ´°¿ÚÖУ¬¾Í»áÏÔʾӲÅÌÀï ......
·ÖÒ³Õâ¸öÒ²ÊÇ×î¶àÈËÎʵģ¬Ò²ÊǺܻù´¡ºÜʵÓõġ£
ÍøÉÏÓкܶà·ÖÒ³´úÂë,Òª²»ÊÇÓÐǰ̨¾Íûºǫ́,Òª²»ÊÇÓкǫ́ûǰ̨,Òª²»ÊǾÍÊǿؼþ,Òª²»¾ÍÊÇÒ»´ó¶ÑSQL´úÂ룬ÈÃÈ˲»ÖªµÀÔõÑùÓá£
Á¦Çó×î¼òµ¥×îÒ׶®.Èý²ã¼Ü¹¹ÄÇЩ¾Í²»¸ãÁË¡£×Ô¼ºÏÂÔØÒ»¸ö
Èç¹ûÊÇaccess ¾ÍÓÃÕâ¸öSQLHELPER [URL=http://hi.csdn.net/link.php?url=http://blo ......
ΪʲôҪȥÁ˽âASP.NETÔËÐÐʱģÐÍ£¨HTTPRuntime£©
ÔÚѧϰASP.NET֮ǰ£¬×îºÃÏÈѧϰһÏÂASP.NETµÄÔËÐÐʱģÐÍ£¬ÆäʵASP.NETµÄ±à³ÌÄ£ÐÍ·ÖΪASP.NETµÄÔËÐÐʱģÐͺÍÒ³Ãæ±ä³ÉÄ£ÐÍ¡£Ðí¶àµÄ²Î¿¼ÊéÖ»ÊÇÖ±½ÓµÄ½éÉÜASP.NETµÄÒ³Ãæ±à³ÌÄ£ÐÍ£¬¶øºöÂÔÁËÔËÐÐʱģÐÍ£¬Ò³Ãæ±à³ÌÄ£ÐÍÊÇASP.NET³ÌÐòÔ±Ö÷Òª×öµÄÊÂÇ飬µ«ÔÚ×öÕâЩ¹¤×÷֮ǰ£¬³ä·ÖµÄ ......