# Object model

Source: https://mroffice.ai/en/developers/embed/object-model

The Automation API covers the documents' objects as Office.js and ONLYOFFICE's Office API name them: a Word document's paragraphs, runs, tables, styles, content controls, comments, tracked changes, sections, headers, footers and pictures; an Excel workbook's sheets, ranges, formats, tables, charts, named ranges and comments; a presentation's slides, layouts, shapes, text, pictures, tables and notes; a PDF's pages, annotations and form fields. Your page, a plugin and a macro all call the same methods.

- Every method is a promise. A change runs through the editor's own commands and is one Undo step of the session's user; everyone in the document sees it, and it is saved with the file.
- A method that writes is refused in a view session (embed_view_only) and in a comment, review or fill-in session (embed_mode_read_only), except comments where the session may comment and form fields in a fill-in session.
- Objects are named by values that do not move when the document changes elsewhere: a block id, a table id, a search occurrence, an A1 address, a slide id and shape id, a page number, a field's name.
- Lengths are points and colours are #rrggbb, as Office.js has them.
- Calls made before ready wait for it; calls run one after another, in the order they were made.

One call per change, each its own Undo step:

```js
const editor = MROffice.open({ container: "#editor", token, onSelectionChange: (event) => console.log(event) });
await editor.ready;

const { paragraphs } = await editor.word.getParagraphs();
await editor.word.setParagraphFormat({ blockId: paragraphs[0].id }, { style: "Heading 1", alignment: "center" });
await editor.word.setTextFormat({ text: "ACME", all: true }, { bold: true, color: "#c00000" });
const [table] = await editor.word.getTables();
await editor.word.setTableCells(table.id, [["Total", "1,250"]], { row: 3 });

await editor.excel.setFormat("Sheet1!A1:D1", { bold: true, fill: "#dce6f1", numberFormat: "@" });
await editor.excel.addTable("Sheet1!A1:D20", { name: "Sales", style: "TableStyleMedium2" });
await editor.excel.addChart("column", "Sheet1!A1:B6", { title: "Sales by month" });

const { slideIndex } = await editor.powerpoint.getSelection();
await editor.powerpoint.addTextBox(slideIndex, "Draft", { left: 36, top: 36, width: 200, height: 40, format: { fontColor: "#c00000" } });

const fields = await editor.pdf.getFormFields();
await editor.pdf.setFormFieldValue(fields[0].name, "Jane Doe");

editor.on("contentChange", (event) => console.log("changed", event.dirty));
```

### Word

| Methods | What they cover |
| --- | --- |
| getText, getContent, getSelection, setSelection, search | The text, the body's blocks, the selection, and every match of a search with its occurrence number. |
| getParagraphs, insertParagraph, setParagraphFormat, deleteBlock | Paragraphs with their style, alignment, list, indents and spacing; a new paragraph before or after a block; deleting a block. |
| getRuns, setTextFormat, insertText, insertHtml, insertMarkdown, replaceText, insertBreak | Runs (text of one formatting each) and character formatting: bold, italic, underline, strikethrough, super- and subscript, font, size, colour, highlight, links. |
| getTables, insertTable, setTableCells, editTable | Tables: their cells as text, new tables, writing cells, adding or deleting rows and columns, a header row. |
| getStyles | The styles the document defines. |
| getContentControls, insertContentControl, removeContentControl, getBookmarks, addBookmark, deleteBookmark | Content controls and bookmarks: reading them, adding them around text, removing them. |
| getComments, addComment, replyToComment, resolveComment, deleteComment | Comments and their replies: reading, adding, replying, resolving and deleting. |
| getTrackedChanges, acceptTrackedChanges, rejectTrackedChanges, setTrackChanges | Track Changes: reading, accepting and rejecting changes, turning tracking on or off. |
| getSections, setPageSetup, setHeaderFooter | Sections: page size, orientation and margins, and header and footer text. |
| getImages, insertImage | Pictures: reading them and inserting one from a data: or https address. |
| getProperties, setProperties | Document properties (File > Info). |

### Excel

| Methods | What they cover |
| --- | --- |
| getSheets, addSheet, renameSheet, deleteSheet, activateSheet, setSheetVisibility | Sheets: adding, renaming, deleting, showing and hiding them. |
| getRange, getUsedRange, setValues, setFormulas, clear, find, getSelection, select | Ranges by A1 address: values, formulas, clearing, finding, and the selection. |
| getFormat, setFormat | Number formats, fonts, fill, alignment, wrapping and borders. |
| insertRows, deleteRows, insertColumns, deleteColumns, setColumnWidth, setRowHeight, merge, unmerge, freezePanes | Rows and columns: inserting and deleting them, their width and height, merged cells and frozen panes. |
| sort, setAutoFilter, setHyperlink | Sorting, the filter and hyperlinks. |
| getTables, addTable, deleteTable | Tables (Insert > Table). |
| getCharts, addChart, deleteChart | Charts made from a range. |
| getNamedRanges, addNamedRange, deleteNamedRange | Named ranges (Formulas > Name Manager). |
| getComments, addComment, deleteComment | Comments on cells. |

### PowerPoint

| Methods | What they cover |
| --- | --- |
| getSlides, getSelection, goToSlide, addSlide, deleteSlide, duplicateSlide, moveSlide, setSlideHidden | Slides: reading them, the slide shown and its selection, adding, deleting, duplicating, moving and hiding them. |
| getLayouts | The layouts New Slide offers. |
| getShapes, addTextBox, addShape, setShapeText, setShapeGeometry, setShapeFormat, deleteShape | Shapes with their place and size: text boxes, preset shapes, their text, position, size, rotation, fill, outline and font. |
| addImage, addTable, setTableCell | Pictures and tables on a slide, and a table cell's text. |
| replaceText | Replace All across the deck. |
| getNotes, setNotes | Speaker notes. |

### PDF

| Methods | What they cover |
| --- | --- |
| getPages, goToPage, rotatePage | Pages with their size and rotation; showing and turning a page. |
| getPageText, search | A page's text, and searching the document. |
| getAnnotations, addHighlight, addComment | Annotations: reading them, highlighting text, adding a note. |
| getFormFields, setFormFieldValue | Form fields: reading them and filling them in. |

> Every method with its parameters and results is in the API reference, generated from the SDK's TypeScript types (the reference is in English; mroffice-embed ships the same types).

### Events

Listen with editor.on(name, listener), or pass onSelectionChange and onContentChange to open(). The editor sends an event only once something listens to it, a moment after the change settles, so a burst of typing is one event.

| Event | When |
| --- | --- |
| documentReady | The document is open in its editor (sent once, when you start listening). |
| selectionChange | The selection changed: the selected text and its block in Word, the range and active cell in Excel, the slide and selected shapes in PowerPoint, the page shown in a PDF. |
| contentChange | The document changed, by anyone in it, Undo included; dirty says whether the change is still on its way to MR Office. |

### Compared with ONLYOFFICE

- ONLYOFFICE runs a function inside the editor (callCommand) against its Office API; MR Office runs each call as a message checked against the session, so a host page, a plugin and a macro have exactly the person's rights and no more.
- The objects and their names follow Office.js where the two differ, so code written for Word, Excel and PowerPoint add-ins reads the same.
