-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request 'Add macro sample: Hide unhide rows and columns' f…
…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
Showing
5 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
51 changes: 51 additions & 0 deletions
51
.../Docs/Plugin and Macros/Macros/Samples/Hide or unhide rows and columns/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters