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
根据表单添加批注
根据表单字段的选择自动向文档添加上下文批注,可用于触发后续操作或标记需要关注的回复:
清除所有表单值
重置所有已填写的表单字段,将表单恢复到初始状态,以便重新使用、取消输入或快速清除:
创建高级表单
创建具有表格结构的高级表单:
创建基本表单
创建包含图片和文本输入的基本表单:
创建活动表单
构建带有渐变背景的样式化活动注册表单:
创建考试表单
创建包含选择题的学校考试表单:
创建反馈表单
创建带有评分表格的客户反馈表单:
从JSON创建表单
根据数据上下文和值自动确定字段类型和结构,从简单的JSON对象自动创建表单:
创建多个保密协议文档
在一个文件中生成多个个性化的保密协议(NDA)文档,为不同用户创建独立的部分:
创建入职清单
创建带有文档跟踪功能的入职清单表单:
创建采购订单
创建包含公司详情和订单项目的采购订单模板:
填充表单
使用对象中存储的数据填充表单:
获取所有表单值
在表单填写完成后,将所有表单字段值收集到单个JSON对象中,用于分析、服务器提交或数据库存储:
通过ID获取表单值
使用唯一标识符从特定表单字段中提取值,用于验证和动态处理:
删除单个字段
通过ID或索引从表单中删除不必要的字段,用于简化界面、隐藏内部字段或根据用户角色动态自定义表单:
设置默认值
根据用户身份验证数据自动填充表单字段,以减少手动输入并加速个人仪表板、内部门户和调查问卷中的表单填写:
更新占位符
根据用户语言或使用环境调整表单字段中的占位符文本,以在多语言系统中提供更好的用户体验:
验证考试表单
验证选择题测试的答案并计算分数(创建考试表单的延续):