title: How to extend the range of an Excel Table in OpenPyXL?
body: <p>The documentation on table manipulation in OpenPyXL is pretty light (see <a href="https://openpyxl.readthedocs.io/en/stable/worksheet_tables.html?highlight=range" rel="nofollow noreferrer">here</a>).</p>
  <p>How to add new lines in a table?</p>
  <p>The way I have found so far consists in adding data, deleting the table, and recreating it.</p>
  <p>Would there be a more efficient way? And also, by doing so, I loose the style of the table (and cannot add a style successfully when I re-create the table).</p>
  <p>Thanks</p>
  <pre class="lang-py prettyprint-override"><code>import re
  from copy import deepcopy
  from pathlib import Path
  
  from openpyxl import load_workbook
  from openpyxl.worksheet.table import Table, TableStyleInfo
  
  TABLE_NAME = &quot;People&quot;
  xls_dir = Path(&quot;e:/AnsysDev/tfs_scripts/its&quot;) 
  
  wb = load_workbook(xls_dir / &quot;MyExcel.xlsx&quot;)
  ws = wb.active
  tb = ws.tables[TABLE_NAME]
  
  max_row = ws.max_row
  curr_ref = tb.ref
  style = deepcopy(tb.tableStyleInfo)
  
  data = [[&quot;Jack&quot;, 39]]
  for row in data:
      max_row += 1
      ws.append(row)
  
  new_ref = re.sub(r&quot;\d+$&quot;, str(max_row), curr_ref)
  
  del ws.tables[TABLE_NAME]
  
  tb.tableStyleInfo = style
  tb = Table(displayName=TABLE_NAME, ref=new_ref)
  ws.add_table(tb)
  
  new_xlsx = xls_dir / &quot;New_Excel.xlsx&quot;
  wb.save(new_xlsx)
  </code></pre>