Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Expand a table in EPPlus C#

Tags:

c#

excel

epplus

Is there any way that I can expand an existing table in EPPlus in C#. The way my program works is I create the table with only 2 rows and keep adding more. I just can't seem to find any sort of resize method in ExcelTable. Is there a dedicated method for this, or do I need to use some sort of alternative?

Edit: Okay I'm just going to clarify this. I already have EPPlus working and making an ExcelTable. My question is: How can I make an existing ExcelTable larger (add more rows)?

like image 847
Jordan Avatar asked Dec 31 '15 17:12

Jordan


1 Answers

This question is about one year old, but hoping that someone still needs an answer, there is a direct solution, although not complete because of a bug in EEPlus (I am working with v4.1).

ExcelWorksheet has an InsertRow(Int32, Int32, Int32) method. If you insert rows in an area that is part of the table, the table is also expanded. Simply use it's Address property to get the bounds. Just make sure to insert between the first and last row of the table.

There is a flaw I know about related to cell validation: even if you use the overload which can copy style from an existing row, the validation is not copied. Even worse, the validation is left where it was and it is not shifted with the cells. I have not tested, but I believe that if the validation has a range and not a cell as target, that one is also expanded if you insert rows into that range.

This won't help you if you wish to expand the table on data aready in the Worksheet - but you can still move rows. And neither when you have many tables side-by-side (which is a nightmare).

like image 64
ZorgoZ Avatar answered Sep 22 '22 20:09

ZorgoZ