Word Tables, Lists and Layout
word_structureCreate and modify Word tables, lists, sections, page setup, headers, footers, and page numbers, including bulk cell edits and table structure changes.
Instructions
Tables, lists and page layout: create and change tables and lists, sections, page setup, headers and footers, and page numbers. Body text is word_edit. Every edit backs the file up first and saves atomically. set_cells edits a document open in Word live; the other ops refuse it. Ops, one per line, as name(required; opt optional): what it does. file_path, live and backup are not repeated; word_help shows them:
set_header_footer(part, text; opt section ref_type alignment include_page_number replace_content): Set a section's header or footer text, replacing the whole part. ref_type 'first' is a different first page, no section break needed.
set_section_properties(opt section orientation page_width_pt page_height_pt margins_pt columns line_numbering): Set one section's page size, orientation, margins, columns and line numbering; with no changes it returns the current values.
insert_list(items; opt kind location continue_from start_at levels): Insert a bulleted or numbered list with real bullet/number glyphs (numbering.xml as needed).
create_table(data; opt location header_row width_pt): Create a table from 2D string data with single-line borders and a bold repeating header row (header_row=False for none).
set_table_properties(table_index; opt style banded_rows first_row_header column_widths header_row_repeat): Set table-wide attributes; pass any combination.
set_cells(table_index; opt edits block nested track author): Write many table cells in one call.
delete_table(table_index): Delete a whole table and its contents.
modify_table_structure(table_index, action; opt target at count copy_format_from width_pt start end columns range row cell at_row): Insert or delete rows or columns, or merge, unmerge or split one table (action picks which; extra arguments are refused).
format_cells(table_index, targets, formatting): Format table cells in bulk. More ops follow, in the same format, in the op parameter's description.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| op | Yes | The operation to run: an op listed in this tool's description, or one of these, in the same format: - sort_table(table_index, column; opt numeric descending has_header): Sort a table's data rows by one column (CELL index, 0-based). - import_table(data; opt table_index at_end after_text has_header): Fill a table from data: a .csv path, a .json path (export_table's form or a bare row list), or an inline list of lists. - set_list_numbering(num_id; opt restart_at level continue_from levels force): Change how one existing list numbers itself (num_id from list_elements(type='lists')). - set_page_numbers(opt section position alignment prefix x_of_y format): Add a page-number field to the header or footer, and set a section's number format and starting number. - setup_chapter_headers(opt level include_number alignment first_page_blank scope): Put the current chapter title in each page's running header with a STYLEREF field; other header content is replaced. - move_section(heading_text; opt before_heading after_heading at_end): Move a heading and its ENTIRE section (content and tables until the next same-or-higher heading) before or after another heading, or to the end. | |
| args | No | The op's arguments as an object. Include file_path (the absolute .docx path) unless the op's line names other paths or the op reads no document; unknown keys are refused. word_help lists every argument. |