public void TableInsertAboveFromRows() { var wb = new XLWorkbook(); IXLWorksheet ws = wb.AddWorksheet("Sheet1"); ws.FirstCell().SetValue("Value"); IXLTable table = ws.Range("A1:A2").CreateTable(); table.SetShowTotalsRow() .Field(0).TotalsRowFunction = XLTotalsRowFunction.Sum; //wb.SaveAs(@"D:\Excel Files\ForTesting\Sandbox1.xlsx"); IXLTableRow row = table.DataRange.FirstRow(); row.Field("Value").Value = 3; row = row.InsertRowsAbove(1).First(); row.Field("Value").Value = 2; row = row.InsertRowsAbove(1).First(); row.Field("Value").Value = 1; //wb.SaveAs(@"D:\Excel Files\ForTesting\Sandbox2.xlsx"); Assert.AreEqual(1, ws.Cell(2, 1).GetDouble()); Assert.AreEqual(2, ws.Cell(3, 1).GetDouble()); Assert.AreEqual(3, ws.Cell(4, 1).GetDouble()); //wb.SaveAs(@"D:\Excel Files\ForTesting\Sandbox.xlsx"); }
public void TableInsertAboveFromRows() { using (var wb = new XLWorkbook()) { IXLWorksheet ws = wb.AddWorksheet("Sheet1"); ws.FirstCell().SetValue("Value"); IXLTable table = ws.Range("A1:A2").CreateTable(); table.SetShowTotalsRow() .Field(0).TotalsRowFunction = XLTotalsRowFunction.Sum; IXLTableRow row = table.DataRange.FirstRow(); row.Field("Value").Value = 3; row = row.InsertRowsAbove(1).First(); row.Field("Value").Value = 2; row = row.InsertRowsAbove(1).First(); row.Field("Value").Value = 1; Assert.AreEqual(1, ws.Cell(2, 1).GetDouble()); Assert.AreEqual(2, ws.Cell(3, 1).GetDouble()); Assert.AreEqual(3, ws.Cell(4, 1).GetDouble()); } }