Samples
The following examples will show you how to use ONLYOFFICE macros and compare the JavaScript code with Microsoft Visual Basic for Applications code so that you could see the difference and understand what can be done to convert the VBA code to ONLYOFFICE macros.
Text document editor
Add state from zip code
In this example we are adding the "State" label and the text form prefilled with "CA" if the zip code of California is entered.
Generate hyperlinks
In this example we are generating and inserting hyperlinks instead of text URLs.
Generate word definitions
In this example we are generating word definitions in our documents using the Dictionary API offered by API Ninjas.
Insert text
In this example we are inserting text into the document at the current cursor position.
Insert unique id
In this example we are inserting a unique id into a form document.
Mask card numbers
In this example we are applying the mask to all forms with the specified form key to hide card numbers.
Remove extra spaces
In this example we are removing extra spaces in the text document.
Replace words in document
In this example we are replacing words in the text editor.
Reset all forms
In this example we are clearing all fields if necessary, for example after printing the document.
Set USA date format
In this example we are setting all date form formats to USA one.
Spreadsheet editor
Add chart
In this example we are creating the chart from the data in the "C5:D7" cell range.
Add comments and change cell colors in spreadsheet
In this example we are adding comments and changing the background colors of selected cells.
Change cell background color
In this example we are setting the background color of the cell B3 to blue.
Change cell font color
In this example we are seting the font color of the cell B4 to red.
Complete address information
In this example we are completing address information in the spreadsheet.
Currency conversion
In this example we are converting a base currency into multiple desired target currencies.
Find company logos
In this example we are finding company logos in a spreadsheet using the Logo API offered by API Ninjas.
Format range as table
In this example we are formatting the range of cells as a table.
Hide or unhide rows and columns
In this example we are hiding or unhiding specified rows and/or columns in the spreadsheet.
Highlight duplicates
In this example we are highlighting duplicates in the selected area with different colors to recognize duplicated values quickly.
Import CSV/TXT data
In this example we are importing data from remote CSV/TXT files into the spreadsheet.
Import hyperlinks
In this example we are importing hyperlinks between different worksheets in the spreadsheet.
Make cell font bold
In this example we are seting the font of the cell A2 to bold.
Merge cell range
In this example we are merging selected cell range.
Next blank row
In this example we are finding the next available blank row in a worksheet.
Recalculate worksheet values
This macro repeatedly recalculates worksheet cell values within one-second intervals.
Set column width
In this example we are setting the width for the second ("B") column.
Sum of highlighted cells
In this example we are summing the answer of all highlighted cells in a spreadsheet.
Unhide all rows and columns
In this example we are unhiding all the rows and columns in a worksheet.
Unmerge cell range
In this example we are unmerging selected cell range.
Write data to worksheet cell
In this example we are writing the data (the "Hello world" phrase) to fourth column of the third row of the worksheet.
Presentation editor
Change background color
In this example we are setting blue color as the background of even indexed slides, if it is odd sets an image.
Change font family and size
In this example we are changing the font family and/or size in the presentation.
Remove shapes from slides
In this example we are removing shapes from the presentation.
Support
If you want to request a feature or report a bug regarding macros, use the issues section on GitHub.
You can also request a macro sample by contacting us at marketing@onlyoffice.com.