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£®¿É¿¿ÐԸߣº¼üÅÌÊäÈëÊý¾Ý³ö´íÂÊΪÈý°Ù·ÖÖ®Ò»£¬ÀûÓùâѧ×Ö·ûʶ±ð¼¼Êõ³ö´íÂÊΪÍò·ÖÖ®Ò»£¬¶ø²ÉÓÃÌõÐÎÂë¼¼ÊõÎóÂëÂʵ ......
vs2008ÖÐн¨b/s½á¹¹µÄÏîÄ¿ÓÐÁ½ÖÖÀàÐÍ£¬Ò»ÖÖÊÇweb application,¼´webÓ¦ÓóÌÐò£¬ÁíÍâÒ»ÖÖÊÇwebÍøÕ¾£¬Ð½¨ÏîĿʱÈç¹ûÑ¡ÔñµÄ²»ÕýÈ·£¬ÔÚºóÐøµÄ¿ª·¢¹ý³ÌÖоͲ»¿É±ÜÃâµÄ»áÓöµ½ÒªÐÞ¸ÄÏîÄ¿ÀàÐ͵ÄÇé¿ö¡£¾¹ýÔÚÍøÉϱ¬×ßÒÔ¼°²âÊÔ£¬ÒÔÏÂÊǽâ¾öasp.netÓ¦ÓóÌÐò¸ÄÍøÕ¾ÏîÄ¿µÄ·½·¨¼°±³¾°ÖªÊ¶£º
1.vs2008µÄÏîÄ¿ÀàÐÍÊÇͨ¹ýguidÀ´È·¶¨µÄ ......
ΪʲôҪȥÁ˽âASP.NETÔËÐÐʱģÐÍ£¨HTTPRuntime£©
ÔÚѧϰASP.NET֮ǰ£¬×îºÃÏÈѧϰһÏÂASP.NETµÄÔËÐÐʱģÐÍ£¬ÆäʵASP.NETµÄ±à³ÌÄ£ÐÍ·ÖΪASP.NETµÄÔËÐÐʱģÐͺÍÒ³Ãæ±ä³ÉÄ£ÐÍ¡£Ðí¶àµÄ²Î¿¼ÊéÖ»ÊÇÖ±½ÓµÄ½éÉÜASP.NETµÄÒ³Ãæ±à³ÌÄ£ÐÍ£¬¶øºöÂÔÁËÔËÐÐʱģÐÍ£¬Ò³Ãæ±à³ÌÄ£ÐÍÊÇASP.NET³ÌÐòÔ±Ö÷Òª×öµÄÊÂÇ飬µ«ÔÚ×öÕâЩ¹¤×÷֮ǰ£¬³ä·ÖµÄ ......
//ÏÈ¿´¿´ASP.NETÒ³ÃæË¢ÐµÄʵÏÖ·½·¨£º
//µÚÒ»£º
private void Button1_Click( object sender, System.EventArgs e ) { Response.Redirect( Request.Url.ToString( ) ); }
//µÚ¶þ£º
private void Button2_Click( object sender, System.EventArgs e ) { Response.Write( " < script language=javascript> ......
using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.UI;
/// <summary>
/// һЩ³£ÓõÄJsµ÷ÓÃ
/// Ìí¼ÓаæËµÃ÷£ºÓÉÓھɰæÆÕ±é²ÉÓÃResponse.Write(string msg)µÄ·½Ê½Êä³öjs½Å±¾£¬ÕâÖÖ
/// ·½Ê½Êä³öµÄjs½Å±¾»áÔÚhtmlÔªËØµÄ<html>&a ......