Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

140
Visualizações
Insert row at the end of an excel C# .NET

Good morning everyone!

I am trying to add a new row to an excel at the end of all data.

As you can see, the excel has a header and then all the records from the "billingSummary". At the end of the latter, I would like to add a row to calculate the totals.

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;

I hope you can help me! Thank you!

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

With respect to the code that has commented when setting a new value to excelDataRows it is resetting the value of the list, what you have to use is the Add method that has the list.

Here I leave you an example of how you should do it based on the code that you have commented.

excelDataRows.Add(new ExcelDataTableRow
    {
        CellValues = new List<string>
        {
            "HOLA",
            "CHAU"
        }
    }
); 

return excelDataRows;
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda