Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

148
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!