asp.net¶ÁÈ¡exclÖеÄÊý¾Ý¡¾×ª¡¿
¾³£ÐèÒªÔÚÊý¾Ý¿âÓëExeclÖ®¼ä»¥µ¼Êý¾Ý¡£netʱ´ú£¬ADO.NET¿ÉÒÔʹÓÃʹÓÃMicrosoft.Jet.OleDb·ÃÎÊ·ÃÎÊExcel£¬ÍøÉÏÒѾÓкܶàÀàËƵÄ×ÊÔ´£¬×îµäÐÍÒ²ÊÇ×î¼òµ¥µÄ¿ÉÄÜÈçÏ£º£¨asp.net»·¾³£©
// Á¬½Ó×Ö·û´®
string xlsPath = Server.MapPath("~/app_data/somefile.xls"); // ¾ø¶ÔÎïÀí·¾¶
string connStr = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Extended Properties=Excel 8.0;" +
"data source=" + xlsPath;
// ²éѯÓï¾ä
string sql = "SELECT * from [Sheet1$]";
DataSet ds = new DataSet();
OleDbDataAdapter da = new OleDbDataAdapter(sql, connStr);
da.Fill(ds); // Ìî³äDataSet
// ÔÚÕâÀï¶ÔDataSetÖеÄÊý¾Ý½øÐвÙ×÷
// Êä³ö£¬°ó¶¨Êý¾Ý
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
ºÜ¼òµ¥°É£¿£¡Ò»ÇоÍÏñ²Ù×÷Êý¾Ý¿âÒ»Ñù£¬Ö»ÊÇÐèҪעÒâµÄÊÇ£º
1¡£Êý¾ÝÌṩ³ÌÐòʹÓÃJet£¬Í¬Ê±ÐèÒªÖ¸¶¨Extended Properties ¹Ø¼ü×ÖÉèÖà Excel Ìض¨µÄÊôÐÔ£¬²»Í¬°æ±¾µÄExcel¶ÔÓ¦²»Í¬µÄÊôÐÔÖµ£ºÓÃÓÚ Extended Properties ÖµµÄÓÐЧ Excel °æ±¾¡£
¶ÔÓÚ Microsoft Excel 8.0 (97)¡¢9.0 (2000) ºÍ 10.0 (2002) ¹¤×÷²¾£¬ÇëʹÓà Excel 8.0¡£
¶ÔÓÚ Microsoft Excel 5.0 ºÍ 7.0 (95) ¹¤×÷²¾£¬Çë
Ïà¹ØÎĵµ£º
asp.net×°Ôؽø¶ÈÌõ¼°¹¤×÷Ò³Ãæ¿ò¼ÜÖ÷ÒªÓÉ4¸ö²¿·Ö×é³É,Õâ4¸ö²¿·ÖµÄÃû³Æ¼°ÔÚÕû¸ö¿ò¼ÜÖÐËùÆðµ½µÄ×÷ÓÃÈçÏÂ:
1.Èë¿ÚÁ´½ÓµØÖ·Ò³Ãæ(aspx):±ÈÈç,µÇ¼ҳÃæ.Ìṩµ½Ä¿±êµØÖ·µÄÒ»¸öÁ´½Ó,²¢Ïò¸ÃÄ¿±ê´«µÝһЩÆô¶¯±ØÐëµÄ»ù±¾Á´½Ó²ÎÊý.
2.Èë¿ÚÁ´½ÓÄ¿±êÒ³Ãæ(aspx):¸ÃÄ¿±ê¶ÔÏóÊÇÕû¸ö¿ò¼ÜµÄºËÐÄ,Ò³Ãæ×°ÔØʱͨ¹ýdocument.writeÊä³ö2¸öiframe,Æä ......
¿´µ½ºÜ¶àÅóÓÑÎÊÕâ¸öÎÊÌâ,ËäÈ»ºÜ¼òµ¥,µ«ÊǺܳ£ÓÃ,ÄóöÀ´ÌÖÂÛÏ°ɡ£¡£¡£¸ßÊÖÆ®¹ý£¡
¼ÇµÃ¼¸Äêǰż¸Õѧ.NETµÄʱºòżÊÇÕâÑù¸ÉµÄ
+Õ¹¿ª-C#
<%@ Control Language="c#" %>
//html...
<script runat="server">
public string BackClo ="red"; //ÕâÀﶨÒåÁËÒ»¸ö²ÎÊý
public void Page_Load()
{ }
</sc ......
1 »ñÈ¡´íÎóÐÅÏ¢²¢µ½Ö¸¶¨Ò³Ã治ҪʹÓÃResponse.Redirect,¶øÓ¦¸ÃʹÓÃServer.Transfer
e.g
// in global.asax
protected void Application_Error(Object sender, EventArgs e) {
if (Server.GetLastError() is HttpUnhandledException)
Server.Transfer("MyErrorPage.aspx");
//ÆäÓàµÄ·ÇHttpUnhandledExceptio ......
Request¶ÔÏó¹¦ÄÜÊÇ´Ó¿Í»§¶ËµÃµ½Êý¾Ý£¬³£ÓõÄÈýÖÖÈ¡µÃÊý¾ÝµÄ·½·¨ÊÇ£ºRequest.Form¡¢Request.QueryString£¬Request¡£ÆäµÚÈýÖÖÊÇÇ°Á½ÖÖµÄÒ»¸öËõд£¬¿ÉÒÔÈ¡´úÇ°Á½ÖÖÇé¿ö¡£¶øÇ°Á½ÖÖÖ÷Òª¶ÔÓ¦µÄFormÌύʱµÄÁ½ÖÖ²»Í¬µÄÌá½»·½·¨£º·Ö±ðÊÇPost·½·¨ºÍGet·½·¨¡£
Request ¶ÔÏóµÄÊôÐԺͷ½·¨± ......