This project has moved. For the latest updates, please go here.

How can i add new columns and new rows in existing table

Dec 11, 2012 at 5:41 AM

I worked with excel file which used to be a template in this file have one sheet and in sheet have one table (one column and one row, cause of didn't know how many columns and rows it dynamic)

How can i add new columns and new rows in existing table

thanks.

Coordinator
Dec 11, 2012 at 6:18 PM

.InsertColumnsBefore/After, .InsertRowsAbove/Below

            var wb = new XLWorkbook();
            var ws = wb.AddWorksheet("Sheet1");
 
            ws.FirstCell().SetValue("Code")
              .CellBelow().SetValue("AAA")
              .CellBelow().SetValue("BBB");
 
            var table = ws.RangeUsed().CreateTable();
 
            table.InsertColumnsAfter(1);
            table.FirstRow()
                 .LastCell().SetValue("Price")
                 .CellBelow().SetValue(10)
                 .CellBelow().SetValue(12);
 
            table.DataRange.InsertRowsBelow(1);
            table.DataRange.LastRow()
                .FirstCell().SetValue("CCC")
                .CellRight().SetValue(14);
Dec 12, 2012 at 8:16 AM

Thanks, you example code worked fine this is a great help for me