ASP.netÁ¬½ÓExcel
Ê×ÏÈÌí¼ÓÃüÃû¿Õ¼ä
using System.Data.OleDb;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
strfile = Request.QueryString["filename"];//´ÓÆäËûÒ³Ãæ´«¹ýÀ´µÄÎļþ·¾¶
Excel(strfile);
}
}
private void Excel(string filepath)
{
try
{
Dataset ds = new DataSet();
string ConnStr = "Provider=Microsoft.Jet.OleDb.4.0;data source=" + filepath +
";Extended Properties='Excel 8.0; HDR=YES; IMEX=1'";//Á¬½ÓExcelµÄ×Ö·û´®
string query = "SELECT * from [student$]";//ExcelÖеıíÃû³Æ
OleDbCommand oleCommand = new OleDbCommand(query, new OleDbConnection(ConnStr));
OleDbDataAdapter oleAdapter = new OleDbDataAdapter(oleCommand);
oleAdapter.Fill(ds, "[student$]");
rowcount = ds.Tables[0].Rows.Count;
gridview1.DataSource = ds;
gridview1.DataBind();
lblmes.Text = "ÉÏ´«³É¹¦£¬Êý¾ÝÈçÏÂËùʾ£¬ÇëÈ·ÈÏ£º";//lblmesΪlabel£¬ÏÔʾÌáʾÐÅÏ¢
}
catch (OleDbException)
{
string filename = filepath.Substring(filepath.LastIndexOf('/') + 1);
lblmes.Text = "´íÎó£¡ÇëÈ·ÈÏÉÏ´«ÎļþÊÇ·ñÕýÈ·£¡µ±Ç°ÉÏ´«µÄÎļþΪ£º" + filename;
lbtnSure.Visible = false;
}
catch(Exception ee)
{
lblmes.Text = ee.Message;
}
}
Ïà¹ØÎĵµ£º
¡¾Ïà¶Ô·¾¶¡¿
Request.ApplicationPath
/src
Path.GetDirectoryName(HttpContext.Current.Request.RawUrl )
\\src\\Xiaoshe
Context.Request.Path
/src/Xiaoshe/Xiaoshe_New.aspx
Context.Request.CurrentExecutionFilePath
/src/Xiaoshe/Xiaoshe_New.aspx
Context.Request.FilePath
/src/Xiaoshe/Xiaoshe ......
ÈçºÎ£ºÔÚ ASP.NET ÍøÒ³ÖÐʵÏֻص÷
ÔÚ¿Í»§¶Ë»Øµ÷ÖУ¬¿Í»§¶Ë½Å±¾º¯Êý»áÏò ASP.NET ÍøÒ³·¢ËÍÇëÇ󣬸ÃÍøÒ³Ëæºó»áÔËÐÐÆäÕý³£ÉúÃüÖÜÆÚµÄ¼ò»¯°æ±¾ÒÔ´¦Àí¸Ã»Øµ÷¡£ÈôҪȷ±£»Øµ÷ʼþÔ´ÓÚÔ¤ÆÚµÄÓû§½çÃæ (UI)£¬¿ÉÒԶԻص÷½øÐÐÑéÖ¤¡£Ôڻص÷ÑéÖ¤ÖУ¬Ó¦ÏÈÔÚÍøÒ³³ÊÏÖ¹ý³ÌÖÐ×¢²áÒªÑéÖ¤µÄʼþ£¬È»ºóÔڻص÷¹ý³ÌÖжԸÃʼþ½øÐÐÑéÖ¤¡£Óйػص÷µ ......
Ò»¡¢ÐÞ¸ÄÅäÖÃWeb.ConfigÎļþÖеÄhttpRuntime½Úµã
¶ÔÓÚasp.net,ĬÈÏÖ»ÔÊÐíÉÏ´«4MÎļþ,Ôö¼ÓÈçÏÂÅäÖÃ,Ò»°ã¿ÉÒÔ×Ô¶¨Òå×î´óÎļþ´óС.
Ò»¡¢ÐÞ¸ÄÅäÖÃWeb.ConfigÎļþÖеÄhttpRuntime½Úµã
¶ÔÓÚasp.net,ĬÈÏÖ»ÔÊÐíÉÏ´«4MÎļþ,Ôö¼ÓÈçÏÂÅäÖÃ,Ò»°ã¿ÉÒÔ×Ô¶¨Òå×î´óÎļþ´óС.
<httpRuntime
executionTimeout="800"
maxRequestLengt ......
//default.aspx.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Runtime.InteropService ......