asp.netµ¼³öExcel/Csv¸ñʽÊý¾Ý×îÓÅ·½°¸£¨C#£©
[ת]asp.netµ¼³öExcel/Csv¸ñʽÊý¾Ý×îÓÅ·½°¸£¨C#£©
±¾ÎÄת×Ô£ºhttp://www.cnblogs.com/lovenets2008/archive/2008/05/06/1184234.html
ÔÎÄÈçÏ£º
ºÃ¾ÃûÓÐдµãʲôÁË£¬Ò²ÐíÊÇ̫æ¡£Ò»ÄêÁË£¬»ýÀÛÁ˲»ÉٺõĶ«¶«£¬Óлú»áʱ¾Íд³öÀ´Óë´ó¼Ò·ÖÏí¡£
ºÃ£¬ÑÔ¹éÕý´«¡£
µ¼³öµ½Excel/CscÎļþ²¢²»ÄÑ£¬ËùÒÔ¾ÍÓкö෽·¨£º¿Ø¼þÖ±½ÓRender¡¢°ÑDataSetÊä³ö³ÉStringÔÙWrite³öÀ´µÈ£¬£¨µ±È»Èç¹ûµ÷ÓÃExcel³ÌÐòµÄ¿âÎļþµÄ»°»¹¿ÉÒÔʹÓøüÇ¿µÄÖ±½Ó²Ù×÷ExcelµÄ·½·¨£¬µ«ÕâÖÖ·½·¨ÓÃÓÚWeb·þÎñÏÔµÃÓеãÒªÇóÌ«¸ß£º±ØÐëÈÃWeb·þÎñÆ÷°²×°Ö¸¶¨°æ±¾µÄExcel»òÆäÖ§³Ö¿âÎļþ£©¡£¾ÍÆäÇ°Á½ÖÖ·½·¨£¬Êµ¼ÊÉÏÒ²ÊÇÒ»ÑùµÄ£¬RenderÒ²ÊÇ°ÑÓÉDataSetת±äµÄViewÉú³ÉΪһ¸öTableÊä³öµ½¿Í»§¶Ë¶øÒÑ£¬Ö»²»¹ýÒþ²ØÁËϸ½Ú£¬Èç¹û²»ÐÅ£¬ÄãÓÃEditPlusʲôµÄ¿´¿´Éú³ÉµÄ.xlsÎļþ¾ÍÖªµÀÁË¡£
ExcelµÄʶ±ðÁ¦Ì«Ç¿ÁË£¬ÒÔÖÁÓÚËü±¾ÉíµÄ¸ñʽ¡¢Csv¸ñʽ¡¢Tab·Ö¸ô·û¸ñʽ¡¢ÍøÒ³µÄTable¸ñʽµÈ¶¼Äܹ»ºÜºÃµÄ´ò¿ª¡£µ«ÊÇËü“Ì«´ÏÃ÷”ÁË£¬ÒÔÖÁÓÚ×Ô¶¯Ê¶±ðÊý×ÖºÍ×Ö·û´®£¬¶øÇÒÒª°Ñ³¬¹ý11λµÄÊý×Ö×Ô¶¯±äΪ¿Æѧ¼ÆÊý·¨µÄ¸ñʽ£¬ÄãÊÔÊÔÊäÈë“123456789012”£¬À뿪ÄǸöµ¥Ôª¸ñ£¬¾Í³É“123457E+11”ÁË£¬¹»´ÏÃ÷µÄ°É£¬²»¹ýÓÐʱ»áÈÃÎÒÃǸоõ²»±ã£¬ÒòΪÎÒÊäÈëµÄ¾ÍÊÇÎÒ×Ô¼ºµÄÉí·ÝÖ¤ºÅÂ룬β°ÍÉÏûÓГX”£¬±¾À´ºÃºÃµÄ15λÊý×Ö£¬µÃÏÖÔÚ³ÉÕâô¸ö¼ÆÊý·¨ÁË¡£ÄÇÎҾ͸ĸÄÏÔʾ¸ñʽ°É£¬¸ÄΪ°ÑÊý×ÖÏÔʾΪÎı¾£¬ºÃÁË¡£¿ÉÊǹú¼ÒµÄÉí·ÝÖ¤Éý¼¶ÁË£¬ºÅÂë±ä³É18룬ÎÒ°ÑËüÊäÈëµ½Êý¾Ý¿â£¬µ¼³öÀ´Ê±£¬Óøղŵķ½·¨´¦Àí¹ý£¬18λû´í£¬¿ÉÊÇ×îºóÈýλÔõô¶¼ÊÇÁãÁË£¡ExcelΪÎÒÃÇ×öÁËÌ«¶àµÄÊ£¬²»¹ÜÊÇÓ¦¸ÃµÄ»¹ÊDz»Ó¦¸ÃµÄ¡£
Ôõô½â¾ö£¿Çë¿´´úÂ룺
public static string ExportTable(DataSet ds)
{
string data = "";
//data = ds.DataSetName + "\n";
foreach (DataTable tb in ds.Tables)
{
//data += tb.TableName + "\n";
data += "<table cellspacing=\"0\" cellpadding=\"5\" rules=\"all\" border=\"1\">";
&nb
Ïà¹ØÎĵµ£º
ÔÚWeb±à³Ì¹ý³ÌÖУ¬´æÔÚןܶలȫÒþ»¼¡£±ÈÈçÔÚÒÔÇ°µÄASP°æ±¾ÖУ¬CookieΪ·ÃÎÊÕߺͱà³ÌÕ߶¼ÌṩÁË·½±ã£¬²¢Ã»ÓÐÌṩ¼ÓÃܵŦÄÜ¡£´ò¿ªIEä¯ÀÀÆ÷£¬Ñ¡Ôñ“¹¤¾ß”²Ëµ¥ÀïµÄ“InternetÑ¡Ï¬È»ºóÔÚµ¯³öµÄ¶Ô»°¿òÀïµ¥»÷“ÉèÖÔ°´Å¥£¬Ñ¡Ôñ“²é¿´Îļþ”°´Å¥£¬ÔÚµ¯³öµÄ´°¿ÚÖУ¬¾Í»áÏÔʾӲÅÌÀï ......
ͨ³££¬SQL Óï¾äºÍ´æ´¢¹ý³Ì°üÀ¨ÔËÐÐʱ¼ÆËãµÄ²ÎÊý¡£Ê¹ÓòÎÊý±àдµÄ SQL Óï¾ä³Æ×÷²ÎÊý»¯ SQL Óï¾ä¡£
ʹÓà SqlDataSource ¿Ø¼þʱ£¬¿ÉÒÔÖ¸¶¨Ê¹ÓòÎÊýµÄ SQL ²éѯºÍÓï¾ä¡£Í¨¹ý¸ù¾ÝÔËÐÐʱ¼ÆËãµÄÖµ¶ÁдÊý¾Ý¿âÐÅÏ¢£¬ÕâÓÐÖúÓÚÌáÉýÊý¾Ý°ó¶¨»·¾³µÄÁé»îÐÔ¡£¿ÉÒÔ´Ó¸÷ÖÖÔ´»ñÈ¡²ÎÊýÖµ¡£ÕâЩԴ°üÀ¨ ASP.N ......
//ÓÉÓÚJAVAÓïÑÔµÄÊý¾ÝÀàÐͶ¼ÊÇÓзûºÅÀàÐÍ£¬¶øC# C++Ò»°ãÊý¾ÝÀàÐͶ¼ÊÇ·ÖÓзûºÅºÍÎÞ·ûºÅ,
//Òò´ËÔÚͨÐŹý³ÌÖд«µÝµÄByte[]ÎÞ·¨Ö±½Óת»»³ÉC#ÐèÒªµÄÀàÐÍ£¬
//ÒÔÇ°µ¹ÊÇûעÒâÕâЩϸ½Ú£¬ÒòΪһ°ãÓÃÒ»ÖÖÓïÑÔ±à³Ì£¬
//´ó¶¼ÓÐÄÚÖõÄת»»·½·¨¡£¿çÓïÑÔ»·¾³µÄת»»¾ÍµÄ×Ô¼º¶¯ÊÖÏë°ì·¨ÁË¡£
1¡¢javaµÄByte[]ת»»³Éc#µÄInt32
private i ......
×î½ü×öÒ»¸öÍøÕ¾£¬ÀïÃæÉæ¼°µ½¼¶ÁªµÄÎÊÌ⣨ÈçÊ¡-ÊУ¬Æ·ÅÆ-ÐͺŵÈ), ÎÒÓõÄÊÇDropDownListÀ´ÊµÏֵģ¬ÉèÖø¸¼¶µÄAutoPostBackÊôÐÔΪÕæ.È»ºóÔÚËüµÄSelectedIndexChanged()ʼþÀïдÏàÓ¦µÄ´úÂ룬ÕâÑù¾ÍÄÜʵÏÖ¼¶Áª¹Øϵ£¨µ±È»ÕâÀïҪעÒâIsPostBackµÄÎÊÌ⣩. ×öºÃÖ®ºóÓÃʱ·¢ÏÖÒ»¸ö·Ç³£²»Ë¬µÄÎÊÌ⣬ÄǾ ......