From e697d009bfb1f5ee67be506f48a0d8ab18467020 Mon Sep 17 00:00:00 2001 From: Jimmy Date: Tue, 9 Nov 2021 23:58:31 +0800 Subject: [PATCH] =?UTF-8?q?excel=E5=AF=BC=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GalleryFiles/Dto/PatternExcelImportDto.cs | 33 ++++++++++++++++++ .../GalleryFiles/GalleryFilesAppService.cs | 34 +++++++++++++++++++ .../MineTec.ProManager.Application.csproj | 3 ++ 3 files changed, 70 insertions(+) create mode 100644 Code/src/MineTec.ProManager.Application/GalleryFiles/Dto/PatternExcelImportDto.cs diff --git a/Code/src/MineTec.ProManager.Application/GalleryFiles/Dto/PatternExcelImportDto.cs b/Code/src/MineTec.ProManager.Application/GalleryFiles/Dto/PatternExcelImportDto.cs new file mode 100644 index 0000000..fee7f8a --- /dev/null +++ b/Code/src/MineTec.ProManager.Application/GalleryFiles/Dto/PatternExcelImportDto.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace MineTec.ProManager.GalleryFiles.Dto +{ + public class PatternExcelImportDto + { + public string msg { get; set; } //提示信息 + + public string result { get; set; } //导入结果 + + public string index { get; set; } //序号 + + public string importmode { get; set; } //导入模式 + + public string filenum { get; set; }//图纸编号 + + public string projectnum { get; set; }//项目编号 + + public int patterntype { get; set; }//图样类型 + + public string signaturecode { get; set; } //特征码 + + public string subcode { get; set; } //附加尾号 + + public string filename { get; set; } //图样名称 + + public string pictureframe { get; set; } //图幅 + + public string remark { get; set; } //备注 + } +} diff --git a/Code/src/MineTec.ProManager.Application/GalleryFiles/GalleryFilesAppService.cs b/Code/src/MineTec.ProManager.Application/GalleryFiles/GalleryFilesAppService.cs index 23a1382..9b76bfb 100644 --- a/Code/src/MineTec.ProManager.Application/GalleryFiles/GalleryFilesAppService.cs +++ b/Code/src/MineTec.ProManager.Application/GalleryFiles/GalleryFilesAppService.cs @@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Http; using MineTec.ProManager.Commd; using MineTec.ProManager.FileStore.Dto; using MineTec.ProManager.GalleryFiles.Dto; +using OfficeOpenXml; using System; using System.Collections.Generic; using System.IO; @@ -272,5 +273,38 @@ namespace MineTec.ProManager.GalleryFiles var url = $@"\{uploadPath}\{dirPath}"; return url; } + + //导入 + public OutputBase Excel(IFormFile file) + { + var result = new OutputBase(); + + Stream stream = file.OpenReadStream(); + using (var package = new ExcelPackage(stream)) + { + // 获取Exel指定工作簿,"Sheet1"也可以用索引代替 + ExcelWorksheet worksheet = package.Workbook.Worksheets["Sheet1"]; + // 获取数据行数 + int RowNum = worksheet.Dimension.Rows; + // 待处理数据存储列表 + List ExcelData = new List(); + // 获取每行数据 + for (int row = 1; row <= RowNum; row++) + { + 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() + }); + } + } + + return result; + } + } } \ No newline at end of file diff --git a/Code/src/MineTec.ProManager.Application/MineTec.ProManager.Application.csproj b/Code/src/MineTec.ProManager.Application/MineTec.ProManager.Application.csproj index c7c927a..93a89d8 100644 --- a/Code/src/MineTec.ProManager.Application/MineTec.ProManager.Application.csproj +++ b/Code/src/MineTec.ProManager.Application/MineTec.ProManager.Application.csproj @@ -10,6 +10,9 @@ false MineTec.ProManager + + +