Inserting Data into an Existing Table #570
-
I have a template containing multiple tables. Other formulae in the workbook calculate based on references to these tables (mostly array formulae that operate on full columns of these tables). I would like to open the workbook in R via openxlsx2, overwrite the data that is in the table with new data (possibly with more or fewer rows), and then save this populated workbook without any of the references to the tables being broken. As far as I can tell, I can remove tables and create tables, but I cannot replace the data in an existing table. Is there a way to do this, either directly or in a roundabout way? Attached is a very simple spreadsheet - to give a concrete example, suppose that I wanted to replace the data in columns a, b, c, and d on Sheet1 with {1,2,3,4}, {5,6,7,8}, {9,10,11,12}, and {13,14,15,16}. I would also want the arrays on Sheet2 to update correctly. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
Hi @ricewhitlam , appreciate your interest and the example, but currently this is not possible, it requires modifications to the table XML in addition to the worksheet and unfortunately for you I have no personal use case for this to dive into. |
Beta Was this translation helpful? Give feedback.
-
For future reference, adding data into the worksheet is possible, but tables bring their own XML file which has to be updated, unless it is overwritten with a same sized data region. The table is constructed here: Lines 2063 to 2080 in 2a20ee4 In the table attributes we'd have to update the total row count and ref, which should be something like "A1:D4". In addition the table XML carries XML children for all columns and if we have removed/renamed a column we have to update/remove it inside the XML. Otherwise the table will contain only subsets (if we simply write more rows than before) or the table XML will be treated as broken (if we write more or less columns or columns with different names). Ideally we should check if the data area we write to with |
Beta Was this translation helpful? Give feedback.
Hi @ricewhitlam , appreciate your interest and the example, but currently this is not possible, it requires modifications to the table XML in addition to the worksheet and unfortunately for you I have no personal use case for this to dive into.
Maybe there will be some rainy day that will change this.