B/S中Exel导入操作
来源:互联网 发布:centos root密码忘记了 编辑:程序博客网 时间:2024/05/06 01:26
第一:将上传文件保存到内存中
前端
private Stream ReadPostedFile()
{
int intDocLen = fl_path.PostedFile.ContentLength;//文件具体大小
byte[] docbuffer = new byte[intDocLen];//缓存大小,为上传文件创建缓存数组
Stream objStream = fl_path.PostedFile.InputStream;
objStream.Read(docbuffer, 0, intDocLen);
return objStream;
}
第二:使用操作Exel的第三方NPOI工具
后台
/// <summary>
/// 读取Exel表格中的数据
/// </summary>
/// <param name="exelSream">Exel文件流</param>
/// <returns>tb_AttendanceTable实体数据集合</returns>
public List<tb_AttendanceTable> ReadExelData(Stream exelSream)
{
//创建以后对象
List<tb_AttendanceTable> lst = new List<tb_AttendanceTable>();
using (exelSream)//读取文件
{
ExelHandleHelp(exelSream, lst);
}
return lst;//返回对象集合
}
/// <summary>
/// 返回 List集合对象
/// </summary>
/// <param name="exelSream">文件读取流</param>
/// <param name="lst">tb_AttendanceTable实体类型集合</param>
private static void ExelHandleHelp(Stream exelSream, List<tb_AttendanceTable> lst)
{
tb_AttendanceTable attendanceT = null;
//创建一个工作簿
using (Workbook wkbook = new HSSFWorkbook(exelSream))
{
for (int i = 0; i < wkbook.NumberOfSheets; i++)
{
using (Sheet sheet = wkbook.GetSheetAt(i))
{
for (int j = 1; j <= sheet.LastRowNum; j++)//从第二行开始:第一行为标题头
{
attendanceT = new tb_AttendanceTable();//创建对象实例
attendanceT.DB_Option_Action_ = "Insert";
Row curRow = sheet.GetRow(j);
for (int k = 0; k < curRow.LastCellNum; k++)
{
switch (k)
{
//获得cell中的值
case 0:
attendanceT.DepartmentName = curRow.GetCell(k).StringCellValue;//部门
break;
case 1:
attendanceT.EmployeeName = curRow.GetCell(k).StringCellValue;//姓名
break;
case 2:
attendanceT.AttendNumb = curRow.GetCell(k).StringCellValue;//考勤号
break;
case 3:
attendanceT.AttendDateTime = DateTime.Parse(curRow.GetCell(k).StringCellValue);//日期时间
break;
case 4:
attendanceT.MachineNumb = curRow.GetCell(k).StringCellValue;//机器号
break;
case 5:
attendanceT.SerialNumber = curRow.GetCell(k).StringCellValue;//编号
break;
case 6:
attendanceT.Comparison = curRow.GetCell(k).StringCellValue;//比对方式
break;
case 7:
attendanceT.CardNo = curRow.GetCell(k).StringCellValue;//卡号
break;
}
}
lst.Add(attendanceT);
}
}
}
}
}
第三:执行对数据的操作
Ex:导入数据库……
另一种上传Exel文件的方式为:
先保存到服务器,然后读取服务器(本地)文件*.xls;
读数据操作完后 然后删除本地文件;
注意:
string path = fl_path.Value;//获取文件的路径 fl_path
<input type="file" name="name" runat="server" id="fl_path" /> 文件选择控件
<form id="form1" runat="server" enctype="multipart/form-data" method="post">设置表单的entype、method属性
<asp:Button ID="Button1" runat="server" Text="数据导入" OnClick="Button1_Click" />放按钮
- B/S中Exel导入操作
- 从EXEL中导入数据
- B/S模式下导出动态生成Exel文件
- dbvisualizer 如何将Exel数据导入数据库表中
- exel数据导入mySQL
- asp导入EXEL文档
- python 操作exel
- vbs操作EXel
- java 操作exel
- exel操作技巧
- Exel的读取操作
- Aspose.Cells.dll操作exel
- B/S Excel导入到sql server
- B/S系统操作日志设计思路
- B/S系统操作日志设计思路
- 数据库操作示例(B/S结构)
- B/S操作客户端硬件的解决方案
- 在B/S模式下导入excel文件的思路
- IOS国际化取值问题
- Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
- hadoop中mapred.tasktracker.map.tasks.maximum的设置
- 用Route-Views查看全球路由的BGP路由表
- MySQL数据库百万级高并发网站实战
- B/S中Exel导入操作
- VS2005(VC++)远程调试方法
- jQuery对象访问-each(callback)
- UIButton 防止多按钮同时按下
- 彻底删除GIT中的文件,节省空间
- 平台总线设备驱动详解
- 选择排序与冒泡排序的联系和区别
- Android--hw_get_module解析
- jquery中$.Ajax()async和success在异步处理 编辑