¡Buenos días a todos!
Estoy tratando de agregar una nueva fila a un Excel al final de todos los datos.
Como puede ver, el Excel tiene un encabezado y luego todos los registros del "billingSummary". Al final de este último, me gustaría agregar una fila para calcular los totales.
var excelDataRows = new List<ExcelDataTableRow> { new ExcelDataTableRow { CellValues = new List<string> { "Fecha", "Contrato", "Consorcio", "Unidad", "Importe Cobrado", "Comisión Plataforma", "Neto", "Factura" } } }; excelDataRows.AddRange(billingSummary.OrderBy(x => x.PaymentDate) .ThenBy(x => x.OwnersAssociationCode) .ThenBy(x => x.FunctionalUnitCode) .Select(item => new ExcelDataTableRow { CellValues = new List<string> { item.PaymentDate.Day.ToString() + '/' + item.PaymentDate.Month.ToString() + '/' + item.PaymentDate.Year.ToString(), item.ContractCode.ToString(), item.OwnersAssociationCode.ToString(), item.FunctionalUnitCode.ToString(), item.TotalAmount.ToStringCurrency(), item.PlapsaComission.ToStringCurrency(), item.NetAmount.ToStringCurrency(), item.Type + ' ' + item.PointOfSale + '-' + item.Number, } })); //excelDataRows = new List<ExcelDataTableRow> //{ // new ExcelDataTableRow // { // CellValues = new List<string> // { // "HOLA", // "CHAU" // } // } //}; return excelDataRows;¡Espero que puedas ayudarme! ¡Gracias!
Con respecto al código que ha comentado al poner un nuevo valor a excelDataRows es resetear el valor de la lista, lo que hay que usar es el método Add que tiene la lista.
Aquí te dejo un ejemplo de cómo debes hacerlo en base al código que has comentado.
excelDataRows.Add(new ExcelDataTableRow { CellValues = new List<string> { "HOLA", "CHAU" } } ); return excelDataRows;