parent
89d363187d
commit
5b70263914
@ -0,0 +1,7 @@ |
||||
using CORRESPONSALBackend.Models.Corresponsales; |
||||
|
||||
namespace CORRESPONSALBackend.Contracts.Corresponsalias.Services{ |
||||
public interface ICorresponsaliasFacturasService{ |
||||
public Task<MemoryStream> GetFacturasExcel(IEnumerable<CorresponsalFacturas> facturas, string folioGemco); |
||||
} |
||||
} |
@ -0,0 +1,39 @@ |
||||
using CORRESPONSALBackend.Contracts.Corresponsalias.Services; |
||||
using CORRESPONSALBackend.Models.Corresponsales; |
||||
using OfficeOpenXml; |
||||
using OfficeOpenXml.Table; |
||||
|
||||
namespace CORRESPONSALBackend.Services.Corresponsalias.Facturas{ |
||||
public class CorresponsaliasFactuasService : ICorresponsaliasFacturasService |
||||
{ |
||||
public async Task<MemoryStream> GetFacturasExcel(IEnumerable<CorresponsalFacturas> facturas, string folioGemco) |
||||
{ |
||||
try{ |
||||
ExcelPackage.LicenseContext = LicenseContext.NonCommercial; |
||||
using (ExcelPackage excelPackage = new ExcelPackage()){ |
||||
var worksheet = excelPackage.Workbook.Worksheets.Add("sheet1"); |
||||
worksheet.Cells["A1"].Value = "Referencia"; |
||||
worksheet.Cells["B1"].Value = "Factura"; |
||||
int currentRow = 2; |
||||
foreach(var factura in facturas){ |
||||
worksheet.Cells[$"A{currentRow}"].Value = folioGemco; |
||||
worksheet.Cells[$"B{currentRow}"].Value = factura.Factura; |
||||
currentRow++; |
||||
} |
||||
//Se crea la tabla en el rango de celdas donde se mostrara la inforamcion. |
||||
ExcelRange range = worksheet.Cells[1, 1,facturas.Count() + 1, 2]; |
||||
ExcelTable tab = worksheet.Tables.Add(range, "Table1"); |
||||
tab.TableStyle = TableStyles.Light1; |
||||
worksheet.Cells[worksheet.Dimension.Address].AutoFitColumns(); |
||||
excelPackage.Workbook.Calculate(); |
||||
var stream = new MemoryStream(); |
||||
excelPackage.SaveAs(stream); |
||||
stream.Position = 0; |
||||
return stream; |
||||
} |
||||
}catch(Exception ex){ |
||||
throw new Exception(ex.Message); |
||||
} |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue