MeHow
MeHow
CC#
Created by MeHow on 3/3/2023 in #help
❔ 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 🙂
6 replies
CC#
Created by MeHow on 11/13/2022 in #help
Microsoft.Data.SqlClient is not supported on this platform - .net6.0+ EF 6.0.0
20 replies