asp.netºÏ²¢excel
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb; //µ¼ÈëÃüÃû¿Õ¼ä
using System.IO;
using Excel = Microsoft.Office.Interop.Excel;
using System.Reflection;
using System.Data;
using EnterExcel.BLL;
using EnterExcel.Models;
public partial class JoinExcel : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack) { }
}
private static List<string> listFiles = new List<string>();
List<Pencil> pencilList = new List<Pencil>();
//“½«ExcelÌí¼Óµ½¼¯ºÏÖДʼþ
protected void btnAdd_Click(object sender, EventArgs e)
{
listFiles.Add(this.fuSearchExcel.PostedFile.FileName);
}
//“µ¼ÈëExcelµ½½çÃæ”ʼþ
protected void btnJoinExcel_Click(object sender, EventArgs e)
{
//±éÀú¼¯ºÏ
foreach (string listFile in listFiles)
{
//½«Excel·¾¶Ñ»·¸³¸ø·½·¨
DataTable dt = CreateDataSource(listFile);
foreach (DataRow row in dt.Rows)
{
Pencil pencil = new Pencil();
pencil.Name = row[0].ToString();
pencil.Type = row[1].ToString();
pencil.Number = row[2].ToString();
pencil.Unit = row[3].ToString();
pencilList.Add(pencil);
}
}
this.gvInfo.DataSource = LoadExcelFiles(pencilList);
this.gvInfo.DataBind();
listFiles.Clear();
}
List<Pencil> list = new List<Pencil>();
public List<Pencil> LoadExcelFiles(List<Pencil> pencilList)
{
Pencil p = null;
for (int i = 0; i < pencilList.Count; i++)
Ïà¹ØÎĵµ£º
ÉÏ´ÎÎÒÃÇ˵µ½ÁË route ·ÓɵŦÄÜ,Õû¸ömvcÔËÐйý³Ì:
Route(·ÓÉ) --> Controller(¿ØÖÆÆ÷)-->action(·½·¨)
Õâ´ÎÎÒÃÇҪ˵µÄ¾ÍÊÇ controller ¿ØÖÆÆ÷ ºÍ action£º
¿ØÖÆÆ÷µÄ×÷ÓþÍÊÇ£ºµ±Ò»¸ö Request À´µÄʱºò£¬Ê×ÏÈRoute ½âÎö ÕÒµ½ÁË ¶ÔÓ¦ ¿ØÖÆÆ÷£¬¿ØÖÆÆ÷ÔÙ¸ù¾Ý action ¾ö¶¨¸øÎÒÃÇ·µ»ØʲôÑùµÄÄÚÈÝ¡£È磺
´úÂë ......
µÚÒ»ÖÖÊÊÓÃÓÚûÓн¨Á¢ÐéÄâ·¾¶µÄÏîÄ¿£¬¶øÇÒÏîÄ¿Ò²²»´óµÄÇé¿öÏ£¬Ö±½Ó´ò¶Ïµã£¬Ö®ºóµã»÷F5ÔËÐС£
µÚ¶þÖÖÊÊÓÃÓÚ½¨Á¢ÐéÄâ·¾¶µÄÏîÄ¿£¬´òºÃ¶Ïµã£¬Ö®ºóÑ¡Ôñµ÷ÊÔ->¸½¼Óµ½½ø³Ì->Ñ¡Ôñaspnet_wp.exe£¬Ö®ºó´ò¿ªä¯ÀÀÆ÷£¬´ò¿ªÒ³Ã棬µ½ÓжϵãµÄµØ·½»á×Ô¶¯¸ú×Ù½øÈ¥£¡~
×¢£ºÓеIJÙ×÷ϵͳ¿ÉÄÜÕÒ²»µ½aspnet_wp.exe ¿ÉÄÜ´æÔÚccc.exeÖ®À ......
Ò³Ãæµ¼³öExcelʱ£¬³£ÓõÄÖ±½ÓRenderControlµÄ·½·¨£¬Èç¹û±í¸ñÖÐÓÐÊý×Ö£¬ÔÚExcelÖÐÍùÍù¸ñʽ»áÂÒ£¬±ÈÈçÇ°ÃæÓÐ0£¬µ«ÏÔʾ³öÀ´ºó0¶¼±»È¥µôÁË¡£
Òò´ËÒªÔÚ°ó¶¨Êý×ÖµÄʱºò£¬ÊÖ¶¯Ö¸¶¨Ò»Ï´ËÁеĸñʽ£¬ÈÃÊý×ÖÒÔÎı¾·½Ê½ÏÔʾ¾ÍÐÐÁË
protected void myGridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
......
ÔÚ½ñÌ죬MVC(Model-View-Controller)Éè¼ÆģʽÓë²âÊÔÇý¶¯¿ª·¢·½·¨(Test-Driven Development ¼ò³ÆTDD)±»¹ã·ºÓ¦ÓÃÓÚÆóÒµ¼¶WEBÓ¦ÓõĿª·¢ÖС£MVCÉè¼ÆģʽǿÖÆÎÒÃǽ«Ó¦Ó÷ֽâ³ÉÈý¸ö²¿·Ö£ºÄ£ÐÍ(Model)¸ºÔðÒµÎñÊý¾ÝµÄ´æ´¢¼°¹ÜÀí£¬ÊÓͼ(View)¸ºÔð³ÊÏÖÊý¾Ý£¬²¢ÎªÓû§ÌṩÓëϵͳ½»»¥µÄ½çÃæ½Ó¿Ú£¬¶ø¿ØÖÆÆ÷(Controller)Ôò¸ºÔð½«Óû§¶¯×÷ ......
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string str = "123456789";
//string str1 = Eval("str").ToString ......