亚洲欧美日韩一区二区在线,成人资源www网在线最新版,国产精品亚洲不卡ahttp://www.aygfsteel.com/aiaiwoo/category/47138.htmlzh-cnSun, 16 Jan 2011 14:30:50 GMTSun, 16 Jan 2011 14:30:50 GMT60ASP.NET中上傳并讀取Excel文件數據http://www.aygfsteel.com/aiaiwoo/articles/342664.htmlaiaiwooaiaiwooMon, 10 Jan 2011 02:53:00 GMThttp://www.aygfsteel.com/aiaiwoo/articles/342664.htmlhttp://www.aygfsteel.com/aiaiwoo/comments/342664.htmlhttp://www.aygfsteel.com/aiaiwoo/articles/342664.html#Feedback0http://www.aygfsteel.com/aiaiwoo/comments/commentRss/342664.htmlhttp://www.aygfsteel.com/aiaiwoo/services/trackbacks/342664.html ASP.NET中上傳并讀取Excel文件數據,Excel文件數據,ASP.NET
在CSDN中,經常有人問如何打開Excel數據庫文件。本文通過一個簡單的例子,實現讀取Excel數據文件。

首先,創建一個Web應用程序項目,在Web頁中添加一個DataGrid控件、一個文件控件和一個按鈕控件。



在代碼視圖中首先導入OleDb命名空間:
using System.Data.OleDb;
在按鈕的單擊事件中輸入如下代碼:
string strPath="c:\\test\\" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".xls";
File1.PostedFile.SaveAs(strPath);
string mystring="Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = '"+ strPath +"';Extended Properties=Excel 8.0";
OleDbConnection cnnxls = new OleDbConnection (mystring);
OleDbDataAdapter myDa =new OleDbDataAdapter("select * from [Sheet1$]",cnnxls);
DataSet myDs =new DataSet();
myDa.Fill(myDs);
DataGrid1.DataSource=myDs.Tables[0];
DataGrid1.DataBind();
其中C:\test對ASPNET用戶要有讀寫的權限.

aiaiwoo 2011-01-10 10:53 發表評論
]]>
將Asp.Net頁面輸出到EXCEL里去http://www.aygfsteel.com/aiaiwoo/articles/342662.htmlaiaiwooaiaiwooMon, 10 Jan 2011 02:49:00 GMThttp://www.aygfsteel.com/aiaiwoo/articles/342662.htmlhttp://www.aygfsteel.com/aiaiwoo/comments/342662.htmlhttp://www.aygfsteel.com/aiaiwoo/articles/342662.html#Feedback0http://www.aygfsteel.com/aiaiwoo/comments/commentRss/342662.htmlhttp://www.aygfsteel.com/aiaiwoo/services/trackbacks/342662.html

必學:將Asp.Net頁面輸出到EXCEL里去

出處:CSDN 2004年12月14日 作者:AppleBBS 責任編輯:linjixiong


   其實,利用ASP.NET輸出指定內容的WORD、EXCEL、TXT、HTM等類型的文檔很容易的。主要分為三步來完成。 

一、定義文檔類型、字符編碼  


   Response.Clear();

   Response.Buffer= true;

   Response.Charset="utf-8";  

   //下面這行很重要, attachment 參數表示作為附件下載,您可以改成 online在線打開

   //filename=FileFlow.xls 指定輸出文件的名稱,注意其擴展名和指定文件類型相符,可以為:.doc    .xls    .txt   .htm  

   Response.AppendHeader("Content-Disposition","attachment;filename=FileFlow.xls");

   Response.ContentEncoding=System.Text.Encoding.GetEncoding("utf-8");  

   //Response.ContentType指定文件類型 可以為application/ms-excel    application/ms-word    application/ms-txt    application/ms-html    或其他瀏覽器可直接支持文檔 

   Response.ContentType = "application/ms-excel";

   this.EnableViewState = false;  

  二、定義一個輸入流  


   System.IO.StringWriter oStringWriter = new System.IO.StringWriter();

   System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);

  三、將目標數據綁定到輸入流輸出  


   this.RenderControl(oHtmlTextWriter);

   //this 表示輸出本頁,你也可以綁定datagrid,或其他支持obj.RenderControl()屬性的控件  

   Response.Write(oStringWriter.ToString());

   Response.End();  

  總結:本例程在Microsoft Visual Studio .NET 2003平臺下測試通過,適用于C#和VB,當采用VB的時候將 this 關鍵字改成 me 。



aiaiwoo 2011-01-10 10:49 發表評論
]]>
C#(asp.net)實現數據導出Excel表詳細代碼http://www.aygfsteel.com/aiaiwoo/articles/342661.htmlaiaiwooaiaiwooMon, 10 Jan 2011 02:47:00 GMThttp://www.aygfsteel.com/aiaiwoo/articles/342661.htmlhttp://www.aygfsteel.com/aiaiwoo/comments/342661.htmlhttp://www.aygfsteel.com/aiaiwoo/articles/342661.html#Feedback0http://www.aygfsteel.com/aiaiwoo/comments/commentRss/342661.htmlhttp://www.aygfsteel.com/aiaiwoo/services/trackbacks/342661.html 2010-6-25 22:57:32 來源:25億CMS系統
本例介紹的用C#(asp.net)實現數據導出Excel詳細代碼的方法,會輸出標準的Excel格式文件,非常穩定,不會死鎖Excel進程,支持中文文件名,支持表頭導出,支持大多數數據庫導入。

C#(asp.net)數據導出Excel實現算法:利用Excel組件將DataGrid控件內容生成Excel臨時文件,并存放在服務器上,然后用Response方法將生成的Excel文件下載到客戶端然后再將生成的臨時文件刪除。

25億CMS系統v2.9實現此功能,大家可以25億CMS系統后臺查看并研究。

C#(asp.net)數據導出Excel具體步驟:
1,在項目中引用Excel組件(Interop.Excel.dll),如需此組件,可以到技術社區(http://bbs.25yi.com)索取,25億官方技術部會提供。
2,aspx頁面代碼:
Width="690px" onpageindexchanging="gridview1_PageIndexChanging" PageSize="15" >































NextPageText="下一頁" PreviousPageText="上一頁" Mode="NextPreviousFirstLast" />


3,cs代碼:
public void DataSourse()
{
//GridView數據綁定
GridView1.DataSource = bllintable.GetModds(9, Remark, this.pbComment.CurrentPage - 1, this.pbComment.PageSize, Language);
GridView1.DataBind();
}
public override void VerifyRenderingInServerForm(Control control)
{

}

private void Export(string FileType, string FileName)
{
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.UTF7;
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());
Response.ContentType = FileType;
this.EnableViewState = false;
StringWriter tw = new StringWriter();
HtmlTextWriter hell = new HtmlTextWriter(tw);
GridView1.AllowPaging = false;
DataSourse();
GridView1.RenderControl(hell);
Response.Write(tw.ToString());
Response.End();
GridView1.AllowPaging = true;
DataSourse();


}
直接把上述代碼復制到頁面中,修改GridView綁定參數既可以運行,如有疑問,可以官方技術社區(http://bbs.25yi.com)提問。
作者: 網站設計@ CMS系統
原載: 25億企業網站管理系統
版權所有。轉載時必須以鏈接形式注明作者和原始出處及本聲明。

aiaiwoo 2011-01-10 10:47 發表評論
]]>
把DataTable直接轉換為IListhttp://www.aygfsteel.com/aiaiwoo/articles/338822.htmlaiaiwooaiaiwooTue, 23 Nov 2010 08:52:00 GMThttp://www.aygfsteel.com/aiaiwoo/articles/338822.htmlhttp://www.aygfsteel.com/aiaiwoo/comments/338822.htmlhttp://www.aygfsteel.com/aiaiwoo/articles/338822.html#Feedback0http://www.aygfsteel.com/aiaiwoo/comments/commentRss/338822.htmlhttp://www.aygfsteel.com/aiaiwoo/services/trackbacks/338822.html/// <summary>
        
/// DataTable 轉換為List 集合
        
/// </summary>
        
/// <typeparam name="TResult">類型</typeparam>
        
/// <param name="dt">DataTable</param>
        
/// <returns></returns>
        public static List<TResult> ToList<TResult>(this DataTable dt) where TResult : classnew()
        {
            
//創建一個屬性的列表
            var prlist = new List<PropertyInfo>();
            
//獲取TResult的類型實例  反射的入口
            Type t = typeof(TResult);
            
//獲得TResult 的所有的Public 屬性 并找出TResult屬性和DataTable的列名稱相同的屬性(PropertyInfo) 并加入到屬性列表 
            Array.ForEach(t.GetProperties(), p => { if (dt.Columns.IndexOf(p.Name) != -1) prlist.Add(p); });
            
//創建返回的集合
            var oblist = new List<TResult>();

            
foreach (DataRow row in dt.Rows)
            {
                
//創建TResult的實例
                var ob = new TResult();
                
//找到對應的數據  并賦值
                prlist.ForEach(p =>
                {
                    
if (row[p.Name] != DBNull.Value)
                        p.SetValue(ob, row[p.Name], 
null);
                });
                
//放入到返回的集合中.
                oblist.Add(ob);
            }
            
return oblist;
        }


aiaiwoo 2010-11-23 16:52 發表評論
]]>
使用Microsoft Web Deploy技術自動部署http://www.aygfsteel.com/aiaiwoo/articles/338800.htmlaiaiwooaiaiwooTue, 23 Nov 2010 06:52:00 GMThttp://www.aygfsteel.com/aiaiwoo/articles/338800.htmlhttp://www.aygfsteel.com/aiaiwoo/comments/338800.htmlhttp://www.aygfsteel.com/aiaiwoo/articles/338800.html#Feedback0http://www.aygfsteel.com/aiaiwoo/comments/commentRss/338800.htmlhttp://www.aygfsteel.com/aiaiwoo/services/trackbacks/338800.html閱讀全文

aiaiwoo 2010-11-23 14:52 發表評論
]]>
主站蜘蛛池模板: 鄂尔多斯市| 都江堰市| 手游| 招远市| 原阳县| 襄汾县| 邻水| 房山区| 尚义县| 分宜县| 微山县| 诸城市| 屏南县| 龙江县| 吕梁市| 镇原县| 沙湾县| 子洲县| 来宾市| 开封县| 虎林市| 外汇| 潜江市| 德安县| 宁蒗| 纳雍县| 南安市| 富蕴县| 连城县| 浪卡子县| 大余县| 红原县| 白城市| 沂源县| 扎囊县| 健康| 柳林县| 镇江市| 新安县| 石景山区| 阳泉市|