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

Cannot use LoadFromDatatable more than once on same WS - Table1 name used w/ each load

Jul 11, 2014 at 1:24 PM
When I execute the first load into a new or completely empty WS, the LoadFromDataTable works perfectly.

However, if I would like to add a second group of numbers to the right of the first group, the LoadFromDataTable fails because it attempts to name the second table with the name (Table1) and this the Load fails. Is there anyway short of handcoding?

Combine this with an apparent inability to delete or rename an existing Table then the only alternative I see is to load each days values directly (wo/ using the LoadFromDataTable).

Would be nice if Load... had an optional parameter of TableName.

Any ideas, or alternatives.
Jul 15, 2014 at 3:35 AM
You can rename the DataTable prior to each load and you should not run into this issue.

However if you want a more permanent fix or to provide this functionality yourself you can overload the LoadFromDataTable method in the source.
var tbl = _worksheet.Tables.Add(new ExcelAddressBase(_fromRow, _fromCol, _fromRow + (rows==0 ? 1 : rows), _fromCol + Table.Columns.Count-1), Table.TableName);
Simply replace the Table.TableName with the overloaded string parameter that your new method includes. Alternatively you can instead of throwing the 'Table not Unique' exception, call the GetNewTableName() function to create a TableName with an incremented number based on the existing tables.

Just my 2c