图片上传

导入操作
返回与 Web 服务器上的指定虚拟路径相对应的物理文件路径。
string filePath = Server.MapPath("~/Document/用户导入模板.xls");
思路:
1、获取上传的文件;
2、把文件转换为二进制数组;
3、二进制数组转成内存流;
4、利用NPOI把内存流中的数据读取成Excel
5、使用NPOI读取数据
获取文件的后缀
把文件转换为二进制数组;
byte[] fileBytes = new byte[xlsFile.ContentLength];
xlsFile.InputStream.Read(fileBytes, 0, xlsFile.ContentLength);
二进制数组转成内存流;
MemoryStream excleMemoryStream = new MemoryStream(fileBytes);
先把Excel保存到临时表格里面(DataTable中)
DataTable dt = new DataTable();
获取标题行— 第二行,索引为1;第一行是说明
NPOI.SS.UserModel.IRow rowHeader = sheet.GetRow(1);
FirstCellNum:获取某行第一个单元格下标
LastCellNum:获取某行的列数 !!!!!
FirstRowNum:获取第一个实际行的下标
LastRowNum:获取最后一个实际行的下标
移除空行
List removeList = new List();
遍历所有的行
for (int i = 0; i < dt.Rows.Count; i++)
{
bool rowDataIsEmpty = true;//标识是否是空行-默认为空行
遍历DataRow的所有列
for (int j = 0; j < dt.Columns.Count; j++)
{
判断数据是否为空
if (!string.IsNullOrEmpty(dt.Rows[i][j].ToString().Trim()))
{
rowDataIsEmpty = false;
}
}
如果是空行,添加到removeList
if (rowDataIsEmpty)
{
removeList.Add(dt.Rows[i]);
}
}
移除掉空行
for (int i = 0; i < removeList.Count; i++)
{
dt.Rows.Remove(removeList[i]);
}
数据验证
===将dataTable中的数据转换为List<S_User>
定义存放容器(用于保存新增的数据)
List<S_User> saveUsers = new List<S_User>();
1、自定义列用户头像
function customUserPicture(data)
{
var picture = data.picture;
if (picture != undefined && picture != null && picture != ‘’)
{
return ‘查  看’;
}
else {
return “未上传”;
}
}
2、查看按钮(显示图片)
function openUserPicture(picture){
图片路径
var pictureUrl = ‘@Url.Content("~/Document/userPicture/")’ + picture;
图片元素
var img = ‘’;
layer.open({
type: 1,// 页面层
title: false,//关闭标题
closeBtn: 0,//不显示关闭按钮
shadeClose: true,//点击遮罩层关闭弹窗
content: img //弹窗显示内容
});
}
图片双击事件(点击input type =file)
function showImageSelectDialog(){
//使用jqury触发文件选择框的点击事件
KaTeX parse error: Expected 'EOF', got '#' at position 3: ("#̲userPictureFile…/i;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值