跳到主要内容

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.

More

In this example we are generating and inserting hyperlinks instead of text URLs.

More

Generate word definitions

In this example we are generating word definitions in our documents using the Dictionary API offered by API Ninjas.

More

Insert text

In this example we are inserting text into the document at the current cursor position.

More

Insert unique id

In this example we are inserting a unique id into a form document.

More

Mask card numbers

In this example we are applying the mask to all forms with the specified form key to hide card numbers.

More

Remove extra spaces

In this example we are removing extra spaces in the text document.

More

Replace words in document

In this example we are replacing words in the text editor.

More

Reset all forms

In this example we are clearing all fields if necessary, for example after printing the document.

More

Set USA date format

In this example we are setting all date form formats to USA one.

More

Spreadsheet editor

Add chart

In this example we are creating the chart from the data in the "C5:D7" cell range.

More

Add comments and change cell colors in spreadsheet

In this example we are adding comments and changing the background colors of selected cells.

More

Change cell background color

In this example we are setting the background color of the cell B3 to blue.

More

Change cell font color

In this example we are seting the font color of the cell B4 to red.

More

Complete address information

In this example we are completing address information in the spreadsheet.

More

Currency conversion

In this example we are converting a base currency into multiple desired target currencies.

More

Find company logos

In this example we are finding company logos in a spreadsheet using the Logo API offered by API Ninjas.

More

Format range as table

In this example we are formatting the range of cells as a table.

More

Hide or unhide rows and columns

In this example we are hiding or unhiding specified rows and/or columns in the spreadsheet.

More

Highlight duplicates

In this example we are highlighting duplicates in the selected area with different colors to recognize duplicated values quickly.

More

Import CSV/TXT data

In this example we are importing data from remote CSV/TXT files into the spreadsheet.

More

In this example we are importing hyperlinks between different worksheets in the spreadsheet.

More

Make cell font bold

In this example we are seting the font of the cell A2 to bold.

More

Merge cell range

In this example we are merging selected cell range.

More

Next blank row

In this example we are finding the next available blank row in a worksheet.

More

Recalculate worksheet values

This macro repeatedly recalculates worksheet cell values within one-second intervals.

More

Set column width

In this example we are setting the width for the second ("B") column.

More

Sum of highlighted cells

In this example we are summing the answer of all highlighted cells in a spreadsheet.

More

Unhide all rows and columns

In this example we are unhiding all the rows and columns in a worksheet.

More

Unmerge cell range

In this example we are unmerging selected cell range.

More

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.

More

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.

More

Change font family and size

In this example we are changing the font family and/or size in the presentation.

More

Remove shapes from slides

In this example we are removing shapes from the presentation.

More

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.