Exemplo n.º 1
0
        public void Export()
        {
            IList <Student1> Student1s = new List <Student1>();

            for (int i = 0; i < 100; i++)
            {
                Student1 Student1 = new Student1()
                {
                    Id       = i,
                    Name     = $"姓名{i}",
                    Sex      = 2,
                    Email    = $"aaa{i}@123.com",
                    CreateAt = DateTime.Now.AddDays(-1).AddMinutes(i),
                    Image    = $"图片{i}"
                };
                Student1s.Add(Student1);
            }
            try
            {
                var workBook = workbookBuilder.CreateWorkbook();

                var excelPackage = exportService.Export <Student1>(Student1s).AddSheet <Student1>().AddSheet <Student1>().AddSheet <Student1>().AddSheet <Student1>();

                FileStream fs = File.Create("a.xlsx");
                excelPackage.Write(fs);
                fs.Close();
            }
            catch (Exception ex)
            {
            }
        }
Exemplo n.º 2
0
        public void Export()
        {
            IList <Student> students = new List <Student>();

            for (int i = 0; i < 100; i++)
            {
                Student student = new Student()
                {
                    Id       = i,
                    Name     = $"姓名{i}",
                    Sex      = 2,
                    Email    = $"aaa{i}@123.com",
                    CreateAt = DateTime.Now.AddDays(-1).AddMinutes(i),
                };
                students.Add(student);
            }
            try
            {
                var excelPackage = exportService.Export <Student>(students).AddSheet <Student>().AddSheet <Student>().AddSheet <Student>().AddSheet <Student>();

                FileInfo fileInfo = new FileInfo("a.xlsx");
                excelPackage.SaveAs(fileInfo);
            }
            catch (Exception ex)
            {
            }
        }
        public async Task <IActionResult> Get(Guid token, int year, int month, CancellationToken cancellationToken)
        {
            if (!_downloadTokenManager.ValidateToken(token))
            {
                throw new InvalidOperationException("Invalid download token");
            }

            using (var stream = new MemoryStream())
            {
                await _excelExport.Export(stream, year, month, cancellationToken);

                return(File(
                           stream.ToArray(),
                           "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
                           "users.xlsx"));
            }
        }
Exemplo n.º 4
0
        private void ExportPersons()
        {
            var filename = _messageDialogService.SaveExcelFileDialog();

            if (filename.IsNullOrEmpty() == false)
            {
                try
                {
                    var numberOfExportedPersons = _excelExportService.Export(filename);
                    _messageDialogService.OpenInformationDialog("Erfolgreich Exportiert", $"{numberOfExportedPersons} Personen wurden exportiert.");

                    InitializePersons();
                }
                catch (Exception)
                {
                    _messageDialogService.OpenErrorDialog("Fehler beim Exportieren", "Die Personen konnten nicht exportiert werden.");
                }
            }
        }