Office API samples
The following examples will show you how to use ONLYOFFICE Office API to create and edit different types of documents.
Text document editor
Adding footer with date and company name
Create a document with footer containing date and company name. Used for standard document formatting
Adding header and footer with logo
Create a document with a professional header containing a company logo and organization name. The header is activated for all pages and includes properly positioned branding elements for official documents, reports, and corporate communications:
Adding page numbering in footer
Create a document with page numbering in the footer. Used in multi-page documents such as reports, contracts, and instructions. Allows readers to easily navigate the document structure:
Adding text watermark
Create a document with a "Confidential" text watermark for marking document confidentiality level. The watermark appears in the background as semi-transparent text and is applied to reports, contracts, and internal memos:
Adding image watermark
Create a document with an image watermark with custom settings:
Applying paragraph styles
Create a document that demonstrates copying and applying formatting styles from one paragraph to other paragraphs:
Auto-filling fields from JSON
Create a document template with content controls and demonstrate how to automatically populate them with data from a JSON object:
Checking unfilled content controls
Create a document with content controls and demonstrate how to validate and identify unfilled required fields:
Clearing all fields
Create a document with filled content controls and demonstrate how to clear all field values to reset the template:
Creating auto-width table
Create a document with a table that automatically adjusts column widths based on content:
Creating borderless table document
Create a document with a borderless table for structured information display:
Creating a bulleted task list
Create a document with a bulleted task list for enumerating tasks, steps, or requirements:
Creating a custom symbol list
Create a document with a custom symbol list using non-standard characters instead of typical bullet points:
Creating document with comments
Create a document with comments added to paragraphs and specific text fragments for review, approval, and collaborative discussion:
Creating event invitation
Create a custom-sized event invitation document with specific page dimensions and content:
Creating a document with fixed-width column table
Create a document with a table that has fixed column widths for predictable document structure:
Creating formal document
Create a document following the structure of a formal paper:
Creating formatted table
Create a document with a formatted table containing employee data with styled headers and center-aligned content:
Creating landscape document
Create a document with landscape page orientation for displaying wide tables, charts, or content that requires more horizontal space:
Creating nested list
Create a document with a multi-level nested list that combines numbered and bulleted items:
Creating nested table document
Create a document with nested tables (table within a table) for displaying hierarchical data:
Creating note blocks
Create a document with styled note blocks that highlight important information using left border formatting:
Creating a numbered steps list
Create a document with a numbered steps list for step-by-step instructions, algorithms, and procedures:
Creating paragraph with colored border
Create a document with a paragraph that has a decorative colored bottom border:
Creating product catalog document
Create a document with a product catalog table containing images and product information:
Creating quote paragraph
Create a document with a quote paragraph that has special visual formatting for highlighting quoted text or excerpts. The quote paragraph features increased left indent, light gray background, and italic styling for better visual distinction from regular text:
Creating report document
Create reports on all the comments added to the document and on every change which was made to the document in the review mode:
Creating sales report with merged table cells
Create a professional sales report document with a table containing merged cells and proper formatting:
Creating signature block
Create a document with a signature block containing position, name and signature line:
Creating structured report
Create a document with structured sections, specific formatting, alignment, and page breaks:
Creating table document
Create a document with a styled table filled with array-based values:
Creating table from JSON data
Create a document with a table populated from JSON data array:
Creating table in header or footer
Create a document with a table in the footer that displays repeating company information on every page:
Creating table with nested headers
Create a document with a table containing nested headers and merged cells. This structure is commonly used in analytical reports, plans, revenue tables, and activity reports where headers need to be grouped by periods, regions, categories, etc. The top cells are merged horizontally to span multiple subcategories:
Creating title page document
Create a document with a formatted title page featuring centered text and proper spacing:
Creating two-column text document
Create a document with text arranged in two columns. This layout is commonly used in instructions, brochures, articles, and official publications to present text compactly on one page, improving readability and visual balance.
Extracting filled fields
Create a document with various content controls (form fields) and demonstrate how to extract all filled values with their tags:
Extracting text from document
Create a document with sample content and demonstrate how to extract all text content as a string or array of paragraphs:
Finding field by tag
Create a document with various content controls and demonstrate how to find specific fields by their tags and retrieve their values:
Formatting variables in text
Create a document with formulas or variables styled differently from the main text:
Highlighting key terms
Create a document with highlighted key terms using bold formatting and color styling:
Highlighting text with background color
Create a document with colored highlighting inside sentences for visual emphasis:
Inserting hyperlink into sentence
Create a document with a clickable hyperlink embedded within a regular paragraph:
Inserting new content controls
Create a document template and demonstrate how to dynamically insert new content controls at different positions:
Inserting special symbols
Create a document with special Unicode symbols commonly used in legal, scientific, and financial documents:
Inserting text into a document
Create a document with formatted text using different methods:
Spreadsheet editor
Adding sequential numbers
Add sequential numbering to the first column of a table for better navigation and row referencing:
Checking duplicates
Identifies repeating values in a selected column and visually highlights rows with duplicates. Used for data cleaning and analysis - for example, in customer lists, orders, or employee records:
Commenting spreadsheet errors
This script checks all used cells for formula errors like "#DIV/0!" and comments each error:
Creating formatted table
Formats a table during creation
Creating pivot table by categories
Creates a pivot table based on source data, grouping rows by one column and calculating sum or count of values. Suitable for sales reports, inventory tracking, and task management:
Creating spreadsheet chart
Creates a custom chart filled with array-based values in the spreadsheet:
Creating spreadsheet with different cell types
Creates a spreadsheet with heterogeneous data types for working with tables containing text, dates, amounts, percentages, and ratings. This approach is suitable for project reports, surveys, and budget tables.
Creating spreadsheet with filters
Creates a spreadsheet with interactive filters in the header row that allows users to sort and filter data conveniently:
Exporting table to JSON
Converts cell values into a structured JSON array where each table row becomes a separate object. Used for transferring tabular data to other systems, APIs, and saving to databases:
Filling spreadsheet
Fill an empty spreadsheet with the data stored in arrays:
Inserting formulas
Add formulas to cells for calculations like sum, average, and count. Used in reports, calculations, and templates where automatic totals are needed:
Removing empty rows
Removes rows where all cells contain no data. Used for cleaning tables before export, visual report assembly, or preparing final document versions. Especially useful after importing data from external sources:
Sorting data
Orders table rows by values in one of the columns. Used for convenient analysis, displaying best/worst values, alphabetical order, and other purposes. Works with numeric, text, and date values:
Presentation editor
Applying color scheme
Apply a unified color scheme to an entire presentation:
Creating background image slide
Create a slide with a background image and overlay text:
Creating bulleted list slide
Create a slide with a bulleted list for structured information presentation:
Creating chart presentation
Create a chart presentation:
Creating chart slide
Create a slide with a chart for data visualization:
Creating numbered list slide
Create a slide with a numbered list for step-by-step instructions:
Creating presentation
Create a presentation on a specific topic:
Creating table slide
Create a slide with a formatted table for data presentation:
Creating title slide
Create a presentation with a professional title slide:
PDF editor
Clearing all form values
Reset all filled form fields and return the form to its initial state for reuse, input cancellation, or quick clearing:
Creating advanced form
Create an advanced form with a table structure:
Creating basic form
Create a basic form with the image and text inputs:
Filling form
Fill a form with the data stored in the object:
Generating forms from JSON
Create forms automatically from simple JSON objects where field types and structure are determined automatically based on data context and values:
Getting all form values
Collect all form field values into a single JSON object after form completion for analysis, server submission, or database storage:
Getting form values by ID
Extract values from specific form fields using their unique identifiers for validation and dynamic processing:
Removing individual fields
Remove unnecessary fields from forms by their ID or index for interface simplification, hiding internal fields, or dynamic form customization based on user roles:
Setting default values
Automatically populate form fields based on user authentication data to reduce manual input and speed up form completion in personal dashboards, internal portals, and surveys:
Updating placeholders
Adapt placeholder text in form fields based on user language or usage context for better user experience in multilingual systems: