Skip to content

Commit

Permalink
Merge pull request 'Add macro sample: Hide unhide rows and columns' f…
Browse files Browse the repository at this point in the history
…rom feature/hide_unhide_rows-columns into develop

Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/api.onlyoffice.com/pulls/92
Reviewed-by: Natalia Ovchinnikova <[email protected]>
  • Loading branch information
LinneyS committed Dec 25, 2024
2 parents a21cc94 + da3dfc8 commit fac1862
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- macros: added remove extra spaces in document macro sample
- macros: added the Sum of highlighted cells macro sample
- macros: added change font family and size in presentations macro sample
- macros: added hide unhide rows or columns in spreadsheet macro sample

## 6.3.0
- docspace oauth api: added a new section
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
order:
---

## Description

Hides or unhides the specified rows and/or columns in the spreadsheet.

<!-- This code snippet is shown in the screenshot. -->

<!-- eslint-skip -->

```ts
(function()
{
const sheet = Api.GetActiveSheet()
const range = sheet.GetRange("A1:M1")
const rowsToHide = [5, 8, 9, 12, 14, 16, 21, 22, 31, 32, 33]
const columnsToHide = [2,4,5,7,8,10,11,13,14,16]
const hidden = sheet.GetRows(rowsToHide[0]).GetHidden()
hideUnhideDetails(hidden)
// Unhide if hidden, Hide if unhidden
function hideUnhideDetails(hidden) {
rowsToHide.forEach(row => {
sheet.GetRows(row).SetHidden(!hidden)
})
columnsToHide.forEach(column => {
range.GetCols(column).SetHidden(!hidden)
})
}
})();
```

Methods used: GetActiveSheet, GetRange, GetRows, GetHidden, GetCols, SetHidden

## Reference Microsoft VBA macro code

<!-- code generated with AI -->

```vb
Sub HideUnhide()
Rows("5:10").Hidden = Not Rows("5:10").Hidden
Columns("B:D").Hidden = Not Columns("B:D").Hidden
End Sub
```

## Result

<!-- imgpath -->

![Hide or unhide rows and columns](/assets/images/plugins/hide-unhide-rows-columns.png)
6 changes: 6 additions & 0 deletions site/pages/Docs/Plugin and Macros/Macros/Samples/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ In this example we are changing the font family and/or size in the presentation.

[More](Change%20font%20family%20and%20size/index.md)

## Hide or unhide rows and columns

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

[More](Hide%20or%20unhide%20rows%20and%20columns/index.md)

## Support

If you want to request a feature or report a bug regarding macros, use the issues section [on GitHub.](https://github.com/ONLYOFFICE/plugin-macros/issues)
Expand Down

0 comments on commit fac1862

Please sign in to comment.