导入
This commit is contained in:
parent
e697d009bf
commit
3b53fa2ab0
@ -18,7 +18,7 @@ namespace MineTec.ProManager.GalleryFiles.Dto
|
||||
|
||||
public string projectnum { get; set; }//项目编号
|
||||
|
||||
public int patterntype { get; set; }//图样类型
|
||||
public string patterntype { get; set; }//图样类型
|
||||
|
||||
public string signaturecode { get; set; } //特征码
|
||||
|
||||
|
@ -282,6 +282,8 @@ namespace MineTec.ProManager.GalleryFiles
|
||||
Stream stream = file.OpenReadStream();
|
||||
using (var package = new ExcelPackage(stream))
|
||||
{
|
||||
//许可证,必须添加许可证,否则会报错
|
||||
ExcelPackage.LicenseContext = OfficeOpenXml.LicenseContext.NonCommercial;
|
||||
// 获取Exel指定工作簿,"Sheet1"也可以用索引代替
|
||||
ExcelWorksheet worksheet = package.Workbook.Worksheets["Sheet1"];
|
||||
// 获取数据行数
|
||||
@ -289,18 +291,40 @@ namespace MineTec.ProManager.GalleryFiles
|
||||
// 待处理数据存储列表
|
||||
List<PatternExcelImportDto> ExcelData = new List<PatternExcelImportDto>();
|
||||
// 获取每行数据
|
||||
for (int row = 1; row <= RowNum; row++)
|
||||
for (int row = 5; row <= RowNum; row++)
|
||||
{
|
||||
//类型必须为string类型,防止为null时转换出错,在具体校验时,再进行验证
|
||||
string index = worksheet.Cells[row, 3].Value == null ? "" : worksheet.Cells[row, 3].Value.ToString();//序号
|
||||
string importmode = worksheet.Cells[row, 4].Value == null ? "" : worksheet.Cells[row, 4].Value.ToString();//导入模式
|
||||
string filenum = worksheet.Cells[row, 5].Value == null ? "" : worksheet.Cells[row, 5].Value.ToString();//图纸编号
|
||||
string projectnum = worksheet.Cells[row, 6].Value == null ? "" : worksheet.Cells[row, 6].Value.ToString();//项目编号
|
||||
string patterntype = worksheet.Cells[row, 7].Value == null ? "" : worksheet.Cells[row, 7].Value.ToString();//图样类型
|
||||
string signaturecode = worksheet.Cells[row, 8].Value == null ? "" : worksheet.Cells[row, 8].Value.ToString();//特征码
|
||||
string subcode = worksheet.Cells[row, 9].Value == null ? "" : worksheet.Cells[row, 9].Value.ToString();//附加尾号
|
||||
string filename = worksheet.Cells[row, 10].Value == null ? "" : worksheet.Cells[row, 10].Value.ToString();//图样名称
|
||||
string pictureframe = worksheet.Cells[row, 11].Value == null ? "" : worksheet.Cells[row, 11].Value.ToString();//图幅
|
||||
string remark = worksheet.Cells[row, 12].Value == null ? "" : worksheet.Cells[row, 12].Value.ToString();//备注
|
||||
ExcelData.Add(new PatternExcelImportDto
|
||||
{
|
||||
// 获取每列数据
|
||||
Account = worksheet.Cells[row, 1].Value.ToString(),
|
||||
Password = worksheet.Cells[row, 2].Value.ToString(),
|
||||
Name = worksheet.Cells[row, 3].Value.ToString(),
|
||||
Sex = worksheet.Cells[row, 4].Value.ToString(),
|
||||
UserRole = worksheet.Cells[row, 5].Value.ToString()
|
||||
msg = "",//提示信息
|
||||
result = "",//导入结果
|
||||
index = index,//序号
|
||||
importmode = importmode,//导入模式
|
||||
filenum = filenum,//图纸编号
|
||||
projectnum = projectnum,//项目编号
|
||||
patterntype = patterntype,//图样类型
|
||||
signaturecode = signaturecode,//特征码
|
||||
subcode = subcode,//附加尾号
|
||||
filename = filename,//图样名称
|
||||
pictureframe = pictureframe,//图幅
|
||||
remark = remark,//备注
|
||||
});
|
||||
}
|
||||
//数据获取完毕,开始校验
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -128,21 +128,37 @@
|
||||
|
||||
upload.render({
|
||||
elem: '#LAY-excel-upload', //绑定元素
|
||||
url: '/upload/', //上传接口(PS:这里不用传递整个 excel)
|
||||
auto: false, //选择文件后不自动上传
|
||||
accept: 'file',
|
||||
choose: function (obj) {// 选择文件回调
|
||||
var files = obj.pushFile()
|
||||
var fileArr = Object.values(files)// 注意这里的数据需要是数组,所以需要转换一下
|
||||
url: apiUrl + '/api/services/app/GalleryFiles/Excel', //上传接口(PS:这里不用传递整个 excel)
|
||||
auto: true, //选择文件后不自动上传
|
||||
multiple: false,
|
||||
accept: 'file', //普通文件
|
||||
exts: 'xlsx', //只允许上传pdf和jpg
|
||||
size: 102400, //限制文件大小,单位 KB
|
||||
// choose: function (obj) {// 选择文件回调
|
||||
// var files = obj.pushFile()
|
||||
// var fileArr = Object.values(files)// 注意这里的数据需要是数组,所以需要转换一下
|
||||
|
||||
// 用完就清理掉,避免多次选中相同文件时出现问题
|
||||
for (var index in files) {
|
||||
if (files.hasOwnProperty(index)) {
|
||||
delete files[index]
|
||||
}
|
||||
// // 用完就清理掉,避免多次选中相同文件时出现问题
|
||||
// for (var index in files) {
|
||||
// if (files.hasOwnProperty(index)) {
|
||||
// delete files[index]
|
||||
// }
|
||||
// }
|
||||
// //$('#LAY-excel-upload').next().val('');
|
||||
// uploadExcel(fileArr) // 如果只需要最新选择的文件,可以这样写: uploadExcel([files.pop()])
|
||||
// }
|
||||
done: function (res) {
|
||||
//上传成功,获取接口返回状态,根据返回的数据进行相应操作
|
||||
console.log(res);
|
||||
if (res.result.code == 1) {
|
||||
layer.msg('上传成功');
|
||||
}
|
||||
//$('#LAY-excel-upload').next().val('');
|
||||
uploadExcel(fileArr) // 如果只需要最新选择的文件,可以这样写: uploadExcel([files.pop()])
|
||||
else if (res.result.code == 0) {
|
||||
return layer.msg('上传失败');
|
||||
}
|
||||
},
|
||||
error: function () {
|
||||
//上传过程失败,进行相应操作
|
||||
}
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user