Insert rows in Table

Apr 4, 2012 at 10:14 AM

Hi there,

first of all thanks for the excellent job!

I want to feed an Excel sheet with data.

I have created a Table in an empty Excel sheet. I proceed like this to setup all the formatting upfront.  My Table consists in a header row and an empty row with the desired formatting

Through code I populate my table by :

retrieving the IXLTable object

getting its last row (which is my empty row)

and then I want to append rows to the table with data

My issue, cause I have one... ;-)

If I use the method InsertRowsAbove : the appended rows are part of my table, the style of the rows is Ok but the cells formatting is lost 

If I use the method InsertRowsBelow: the appended rows have the cells formatting I expect but are not part of the table (and obviously don't have the table style)

 

Any idea on how to append rows to the table keeping cells formatting?  

Thanks in advance!!

Coordinator
Apr 4, 2012 at 3:07 PM

table.DataRange.InsertRowsBelow

Apr 10, 2012 at 3:27 AM

Thanks. I tried but still got the same result:

=> the appended rows have the cells formatting I expect but are not part of the table (and obviously don't have the table style)

Coordinator
Apr 10, 2012 at 4:53 PM

How can I reproduce it? The following works just fine:

var wb = new XLWorkbook();
var ws = wb.AddWorksheet("Sheet1");
ws.FirstCell().SetValue("Categories")
    .CellBelow().SetValue("A")
    .CellBelow().SetValue("B");
var table = ws.RangeUsed().CreateTable();
var newRows = table.DataRange.InsertRowsBelow(2);
newRows.First().FirstCell().SetValue("C");
newRows.Last().FirstCell().SetValue("D");
wb.SaveAs(@"Sandbox.xlsx");