public async Task <IActionResult> GeneraXlsRaccomandateInDistinta(string distinta) { try { _logger.LogInformation("Stored procedure execution: new_dettaglio_distinte_storico_cartelle_2"); var nddsc2Query = new DAL.StoredProcedure.SP_new_dettaglio_distinte_storico_cartelle2(_context); // crea file EXCEL string sFileName = @"DettaglioDistinteStoricoCartelle_" + distinta + ".xlsx"; //string URL = string.Format("{0}://{1}/{2}/{3}/{4}", Request.Scheme, Request.Host, ControllerContext.ActionDescriptor.ControllerName, ControllerContext.ActionDescriptor.ActionName, sFileName); _logger.LogInformation("Create XLSX file: " + sFileName); var stream = new MemoryStream(); await Task.Run(() => { using (var package = new ExcelPackage(stream)) { // add a new worksheet to the empty workbook var worksheet = package.Workbook.Worksheets.Add(distinta); // Call to set column width to display data so that is read fine SetColumnWidth(worksheet, XlsTypes.RaccomandateInDistinta); //First add the headers worksheet.Cells[1, 1].Value = "CODICE RACCOMANDATA"; worksheet.Cells[1, 2].Value = "FILE RRDP30NO"; worksheet.Cells[1, 3].Value = "DATA POSTALIZZAZIONE"; using (var cells = worksheet.Cells[1, 1, 1, 3]) { cells.Style.Font.Bold = true; cells.Style.Fill.PatternType = ExcelFillStyle.Solid; cells.Style.Fill.BackgroundColor.SetColor(Color.LightGray); } //Add values var numRigaCella = 2; foreach (var item in nddsc2Query.Get(distinta).Result) { worksheet.Cells[numRigaCella, 1].Value = item.CodeRacc; worksheet.Cells[numRigaCella, 2].Value = item.FileName; worksheet.Cells[numRigaCella, 3].Value = $"{item.DataSpedizione:dd/MM/yyyy}"; //DateTime.FromOADate(item.DataSpedizione); numRigaCella++; } package.Save(); //Save the workbook. } }); var fileName = AppendInfoToFile(sFileName, stream, out var fileType); return(File(stream, fileType, fileName)); } catch (Exception ex) { _logger.LogError("Error generating xls: " + ex.Message); return(BadRequest(ex.Message)); } }
public async Task <IActionResult> RaccomandateInDistinta(NewStoricoCartelle filtroRicerca) { // GET /StoricoCartelle/RaccomandateInDistinta/DIP05420180726H00001 Task <IEnumerable <NewStoricoCartelle.Elenco_Raccomandate_In_Distinta> > result = null; try { _logger.LogInformation("Stored procedure execution: new_dettaglio_distinte_storico_cartelle_2"); var nddsc2Query = new DAL.StoredProcedure.SP_new_dettaglio_distinte_storico_cartelle2(RepositoryContext); result = nddsc2Query.Get(filtroRicerca.Distinta); filtroRicerca.RaccomandateInDistinta = result.Result; return(Ok(filtroRicerca)); } catch (Exception ex) { _logger.LogError(ex, ex.Message); return(Content(ex.Message)); } }