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++)
相关文档:
首先建立控件GridView1,注意噢
页面EnableEventValidation="false"必须的。
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" AutoGenerateColumns="false" runat="server">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Panel ID="P ......
部门要做一个网站,我以前用的是php或asp做的,这回想改用asp.net做,主要基于两点考虑,第一:想通过asp.net学习c#及其.net框架。第二:自己又想偷懒,不想从头开始做网站,于是就想用开源的netcms来改改。于是有了我的系列文章。根据我的学习进度我会每天更新,请朋友们关注。 ......
在BS项目中,某个aspx页面需要引用外部脚本文件,通过在页面head节<script language="" src="">方式引用指定的js之后,仍然无效。通过alert方式调试,发现是由于js文件编码与js文件内容不符。由于js文件中包含中文注释,所以需要设置js文件为可识别中文的gb2312编码。其方法在网上也讲述,以下为网摘内容:
&n ......
在今天,MVC(Model-View-Controller)设计模式与测试驱动开发方法(Test-Driven Development 简称TDD)被广泛应用于企业级WEB应用的开发中。MVC设计模式强制我们将应用分解成三个部分:模型(Model)负责业务数据的存储及管理,视图(View)负责呈现数据,并为用户提供与系统交互的界面接口,而控制器(Controller)则负责将用户动作 ......