Beispiel #1
0
        public async Task <object> Export([FromBody] ImportStudentDto model)
        {
            Dictionary <string, string> columnNames = new Dictionary <string, string>();
            List <string> lists = new List <string>();

            lists.Add("IdCard");

            var properties = typeof(ImportStudentDto).GetProperties();

            foreach (var property in properties)
            {
                var name = property.GetCustomAttribute <DisplayAttribute>()?.Name;
                if (!string.IsNullOrWhiteSpace(name))
                {
                    foreach (var list in lists)
                    {
                        if (list == property.Name)
                        {
                            columnNames.Add(property.Name, name);
                        }
                    }
                }
            }
            var students = await db.ImportStudentDtos.ToListAsync();

            var sc = await ExportExcelHelper.GetByteToExportExcel(students, columnNames, lists, "sheet1", "测试");

            return(File(sc, "application/octet-stream", "测试.xlsx"));
            //columnNames.Add("SerialNumber", "序号");
            //columnNames.Add("StudentCode", "学籍号");
            //columnNames.Add("Name", "姓名");
            //columnNames.Add("Gender", "性别");
            //columnNames.Add("IdCard", "身份证号");
        }