© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
5 replies
MeHow

❔ DocumentFormat.OpenXML - insert row into an Excel Table

Hi, I have a problem with inserting a row into the Table in Excel document. I had no problems with inserting cell values, but when I want to add a collection of objects as rows it does not update the table.
Here's the code:
void InsertDeskIntoATable(Table table, Desk desk)
{
    var row = new TableRow();

    var props = desk.GetType().GetProperties();

    foreach (var prop in props)
    {
        var value = prop.GetValue(desk, null) ?? 0;
        var cell = new TableCell(new Paragraph(new Run(new Text(value.ToString()))));
        row.Append(cell);
    }

    table.Append(row);
    table.Save();
}

public class Desk
{
    public int Width { get; set; }
    public int Height { get; set; }
}
void InsertDeskIntoATable(Table table, Desk desk)
{
    var row = new TableRow();

    var props = desk.GetType().GetProperties();

    foreach (var prop in props)
    {
        var value = prop.GetValue(desk, null) ?? 0;
        var cell = new TableCell(new Paragraph(new Run(new Text(value.ToString()))));
        row.Append(cell);
    }

    table.Append(row);
    table.Save();
}

public class Desk
{
    public int Width { get; set; }
    public int Height { get; set; }
}


I'm using reflections cause I want to make the function generic in the future, it works fine but the table in my file does not update. The reference to the table is correct and the other data saves properly. Just not the table 🙂
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ OpenXML Excel FOOTER
C#CC# / help
2y ago
insert mac addresses into a table of sqlite db
C#CC# / help
2y ago
Insert into Access Database
C#CC# / help
16mo ago
✅ how to create and insert images that represent program data into excel file
C#CC# / help
2y ago