示例#1
0
        public async Task <ActionResult> DownloadExcelTableDocument()
        {
            TableGeneratorExcel excel = new TableGeneratorExcel();

            // we need to use anonoymus type to set the custom label names
            var customers = await _context.Customers.Select(x => new
            {
                FullName = x.ContactName,
                Company  = x.CompanyName,
                JobTitle = x.ContactTitle,
                x.Address,
                x.City,
            }).ToListAsync();

            var title = "Customers";

            var fileName = Helpers.GetExcelDocumentFileName(title);

            excel.Run(customers, title, fileName);

            //download file
            byte[] fileBytes = await Helpers.DownloadFile(fileName, _configuration, _hostingEnvironment);

            var file = File(fileBytes, "application/x-msdownload", fileName);

            return(file);
        }
示例#2
0
        public void CreateSpreadSheetTable()
        {
            ContextDbService service = new ContextDbService();
            var context = service.GetDbContext();

            var tableGenerator = new TableGeneratorExcel();

            var fileName = $"Customers {DateTime.Now.ToString().Replace("/", "").Replace(":", "")}.xlsx";

            tableGenerator.Run(context.Customers.ToList(), "Customers", fileName);
        }