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:
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.
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 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:
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 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:
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:
Presentation editor
Creating chart presentation
Create a chart presentation:
Creating presentation
Create a presentation on a specific topic:
PDF editor
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: