public async Task <ActionResult> DownloadWordTableDocument() { TableGeneratorWord excel = new TableGeneratorWord(); // 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.GetWordDocumentFileName(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); }
public void GenerateTable() { ContextDbService service = new ContextDbService(); var context = service.GetDbContext(); // we need to use anonoymus type so set the custom label names var Customers = context.Customers.Select(x => new { FullName = x.ContactName, Company = x.CompanyName, JobTitle = x.ContactTitle, x.Address, x.City, }).ToList(); var tableGenerator = new TableGeneratorWord(); var fileName = $"Customers {DateTime.Now.ToString().Replace("/", "").Replace(":", "")}.docx"; tableGenerator.Run(Customers, "Customers", fileName); }