How to extend a data table

Hello, I would like to know how to extend an existing data table.
I know how to get the reference to the data table, I tried to modify the "Bottom" property of the TTableDefinition object, but this does not have the expected effect
Thank you very much for your reply

Hi,
You are likely forgetting to call "SetTable" after modifying the Bottom property. In FlexCel, with the only excaption of charts (*), objects are decoupled from the XlsFile object you got them from. That is, if you get a range from an XlsFile object, and then modify this range, the XlsFile object will remain unchanged. This is different from OLE where all objects are thightly coupled, and if you get a range from a file, modifying the range will modify the file.

So in FlexCel it alsways is:

Something = xls.GetSomething();
Modify(Something);
xls.SetSomething(Something);

Something has no pointers or knoledge of xls, changing it won't change xls.

This code should work to change a table bottom:

  var xls = new XlsFile("table.xlsx", true); 
  var table = xls.GetTable("table1"); 
  table.Range.Bottom = 20;
   xls.SetTable(table); 
  xls.Save("result.xlsx"); 

But you might find it easier to just xls.InsertAndCopyRows to insert new rows in the table, so the full thing (not just the table) expands correctly to the larger number of rows. (InsertAndCopyRows, despite the name, can be used to only Insert rows)

(*) Charts are a special case here, because the cost of decoupling the chart from the XlsFile would be too big and a lot of unnecessary copying would be needed. So when you get a chart with
chart = xls.GetChart()
This chart is still coupled with xls, and if you change the chart object you will change the xls object too.
But as said this is a particular case, which was decided after a lot of thought because it was much more efficient for the chart case. For all other objects in FlexCel, you need to do a "Set" after "Get" to modify the xlsfile object.

Once again, fast and quality support
Thank you for the complete and very relevant answer.
As suggested, my software fills now the canvas using the InsertAndCopyRange function

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.