ASP.NETÓÚExcelµÄ½»»¥
public DataSet ExcelToDS(string Path)
{
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + Path + ";" + "Extended Properties=Excel 8.0;";
OleDbConnection conn = new OleDbConnection(strConn);
conn.Open();
string strExcel = "";
OleDbDataAdapter myCommand = null;
DataSet ds = null;
strExcel = "select * from [»õÎïÅÉËÍÇé¿ö$]";
myCommand = new OleDbDataAdapter(strExcel, strConn);
ds = new DataSet();
myCommand.Fill(ds, "table1");
conn.Close();
myCommand.Dispose();
return ds;
}
¶ÔÓÚEXCELÖÐµÄ±í¼´sheet([sheet1$])Èç¹û²»Êǹ̶¨µÄ¿ÉÒÔʹÓÃÏÂÃæµÄ·½·¨µÃµ½
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" +"Data Source="+ Path +";"+"Extended Properties=Excel 8.0;";
OleDbConnection conn = new OleDbConnection(strConn);
DataTable schemaTable = objConn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables,null);
string tableName=schemaTable.Rows[0][2].ToString().Trim();
//
public void ExportGridView(GridView gridView1, string filename)
{
string attachment = "attachment; filename=" + filename + ".xls";
HttpResponse Response = HttpContext.Current.Response;
Response.ClearContent();
Response.Charset = "UTF-8";
Response.ContentEncoding = Encoding.Default;
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
// Create a form to contain the grid
HtmlForm frm = new HtmlForm();
gridView1.Parent.Controls.Add(frm);
frm.Attributes["runat"] = "server";
frm.Controls.Add(gridView1);
frm.RenderControl(htw);
//GridView1.RenderControl(htw);
Response.Write(sw.ToString());
Ïà¹ØÎĵµ£º
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Syste ......
asp.net´íÎó´¦Àí·½·¨ ´ó²¿·Ö¶¼Óà try catch
ÎÒÃÇÒ²¿ÉÒÔÔÚÒ³Ãæ¶¨Òå protected void Page_Error(object sender, EventArgs e)·½·¨´¦Àí´íÎóÐÅÏ¢
{
//ÏÈ»ñÈ¡µ±Ç°·¢ÉúÒì³£
Exception ex = Server.GetLastError().GetBaseException();
if (ex is ArgumentOu ......
public class SqlCheck
{
public SqlCheck()
{
//
// TODO: ÔÚ´Ë´¦Ìí¼Ó¹¹Ô캯ÊýÂß¼
& ......
¼¯ºÏÊôÐÔÏàÐÅ´ó¼Ò¶¼ºÜÊìϤҲºÜ³£ÓÃ,ÈçDropDownList,ListBoxµÈ¿Ø¼þ
﹤asp:DropDownList ID="DropDownList1" runat="server"﹥ ﹤asp:ListItem﹥²âÊÔ1﹤/asp:ListItem﹥ & ......
ÔÚasp.netÖеÄSession´æ´¢·½Ê½²»ÏóaspÄÇÑùµ¥Ò»£¬Ò»¹²ÌṩÁËÈýÖÖ´æ´¢·½Ê½£¬ÓÉÓÚ×î½üÒ»¸ö2000¶àÈËʹÓõÄwebÈí¼þ³öÏÖÁ˹ÊÕÏ£¬Óû§Ã¿ÌìÔçÉÏÔÚijһʱ¿Ì³öÏÖÄÑÒԵǽÏÖÏ󣬽Ó×ÅSession¶ªÖµ³öÏÖ£¬Ö»ÓÐÖØÆôIIS,»ò»úÆ÷.Õâʱ³ÌÐò»Ö¸´Õý³£ÁË.ÕûÌì¶¼²»»á³öÏÖͬÑùµÄÎÊÌâ £¬µ«ÊǵڶþÌìÒÀ¾É!ÕâÖÖÏÖÏó³ÖÐøÁ˺ü¸Ì죬ÎÒ¼ì²éÁËÒ»ÏÂÈÕÖ¾Îļþ£¬¸ ......