-
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 'feature/Sum_Of_Highlighted_Cells' from feature/Su…
…m_Of_Highlighted_Cells into develop Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/api.onlyoffice.com/pulls/85
- Loading branch information
Showing
26 changed files
with
96 additions
and
21 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.
2 changes: 1 addition & 1 deletion
2
site/pages/Docs/Plugin and Macros/Macros/Samples/Add chart/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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
--- | ||
order: -13 | ||
order: -14 | ||
--- | ||
|
||
## Description | ||
|
2 changes: 1 addition & 1 deletion
2
...cros/Macros/Samples/Add comments and change cell colors in spreadsheet/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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
--- | ||
order: -1 | ||
order: -2 | ||
--- | ||
|
||
## Description | ||
|
2 changes: 1 addition & 1 deletion
2
...ges/Docs/Plugin and Macros/Macros/Samples/Change cell background color/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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
--- | ||
order: -20 | ||
order: -21 | ||
--- | ||
|
||
## Description | ||
|
2 changes: 1 addition & 1 deletion
2
site/pages/Docs/Plugin and Macros/Macros/Samples/Change cell font color/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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
--- | ||
order: -19 | ||
order: -20 | ||
--- | ||
|
||
## Description | ||
|
2 changes: 1 addition & 1 deletion
2
...ges/Docs/Plugin and Macros/Macros/Samples/Complete address information/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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
--- | ||
order: -3 | ||
order: -4 | ||
--- | ||
|
||
## Description | ||
|
2 changes: 1 addition & 1 deletion
2
site/pages/Docs/Plugin and Macros/Macros/Samples/Currency exchange rates/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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
--- | ||
order: -9 | ||
order: -10 | ||
--- | ||
|
||
## Description | ||
|
2 changes: 1 addition & 1 deletion
2
site/pages/Docs/Plugin and Macros/Macros/Samples/Format range as a table/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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
--- | ||
order: -14 | ||
order: -15 | ||
--- | ||
|
||
## Description | ||
|
2 changes: 1 addition & 1 deletion
2
site/pages/Docs/Plugin and Macros/Macros/Samples/Highlight duplicates/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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
--- | ||
order: -12 | ||
order: -13 | ||
--- | ||
|
||
## Description | ||
|
2 changes: 1 addition & 1 deletion
2
site/pages/Docs/Plugin and Macros/Macros/Samples/Import CSV or TXT data/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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
--- | ||
order: -8 | ||
order: -9 | ||
--- | ||
|
||
## Description | ||
|
2 changes: 1 addition & 1 deletion
2
site/pages/Docs/Plugin and Macros/Macros/Samples/Insert text/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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
--- | ||
order: -10 | ||
order: -11 | ||
--- | ||
|
||
## Description | ||
|
2 changes: 1 addition & 1 deletion
2
site/pages/Docs/Plugin and Macros/Macros/Samples/Insert unique id/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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
--- | ||
order: -4 | ||
order: -5 | ||
--- | ||
|
||
## Description | ||
|
2 changes: 1 addition & 1 deletion
2
site/pages/Docs/Plugin and Macros/Macros/Samples/Make cell font bold/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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
--- | ||
order: -18 | ||
order: -19 | ||
--- | ||
|
||
## Description | ||
|
2 changes: 1 addition & 1 deletion
2
site/pages/Docs/Plugin and Macros/Macros/Samples/Merge cell range/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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
--- | ||
order: -17 | ||
order: -18 | ||
--- | ||
|
||
## Description | ||
|
2 changes: 1 addition & 1 deletion
2
site/pages/Docs/Plugin and Macros/Macros/Samples/Next blank row/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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
--- | ||
order: -11 | ||
order: -12 | ||
--- | ||
|
||
## Description | ||
|
2 changes: 1 addition & 1 deletion
2
...ges/Docs/Plugin and Macros/Macros/Samples/Recalculate worksheet values/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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
--- | ||
order: -7 | ||
order: -8 | ||
--- | ||
|
||
## Description | ||
|
2 changes: 1 addition & 1 deletion
2
.../pages/Docs/Plugin and Macros/Macros/Samples/Remove shapes from slides/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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
--- | ||
order: -5 | ||
order: -6 | ||
--- | ||
|
||
## Description | ||
|
2 changes: 1 addition & 1 deletion
2
.../pages/Docs/Plugin and Macros/Macros/Samples/Replace words in document/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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
--- | ||
order: -2 | ||
order: -3 | ||
--- | ||
|
||
## Description | ||
|
2 changes: 1 addition & 1 deletion
2
site/pages/Docs/Plugin and Macros/Macros/Samples/Set column width/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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
--- | ||
order: -15 | ||
order: -16 | ||
--- | ||
|
||
## Description | ||
|
68 changes: 68 additions & 0 deletions
68
site/pages/Docs/Plugin and Macros/Macros/Samples/Sum of Highlighted Cells/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,68 @@ | ||
--- | ||
order: -1 | ||
--- | ||
|
||
## Description | ||
|
||
Sums the answer of all highlighted cells in a spreadsheet. | ||
|
||
<!-- This code snippet is shown in the screenshot. --> | ||
|
||
<!-- eslint-skip --> | ||
|
||
``` ts | ||
(function () { | ||
const oWorksheet = Api.GetActiveSheet(); | ||
const range1 = oWorksheet.GetRange("B1"); // Set your range for the color reference | ||
const colorReference = range1.SetFillColor(Api.CreateColorFromRGB(91, 155, 213)); // Set targeted background color. To use fill color from the existing range, comment this line out | ||
const targetedColor = range1.GetFillColor() | ||
const range2 = oWorksheet.GetRange("A1:A16"); // Set the targeted range in the spreadsheet | ||
const result = oWorksheet.GetRange("A17"); // Set the cell where the result will be displayed | ||
let sum = 0; | ||
let cellColorCode; | ||
|
||
range2.ForEach(function (range) { | ||
const cellColor = range.GetFillColor(); | ||
|
||
if (cellColor!== "No Fill"){ | ||
cellColorCode = cellColor.GetRGB() | ||
} else { | ||
cellColorCode = null; | ||
} | ||
|
||
if (cellColorCode && cellColorCode === targetedColor.GetRGB()) { | ||
const value = range.GetValue(); | ||
if (!isNaN(parseFloat(value))) { | ||
sum += parseFloat(value); | ||
} | ||
} | ||
}); | ||
result.SetValue(`The sum: ${sum}`) | ||
})(); | ||
``` | ||
|
||
Methods used: GetActiveSheet, GetRange, SetFillColor, CreateColorFromRGB, GetFillColor, ForEach, GetRGB, GetValue | ||
|
||
## Reference Microsoft VBA macro code | ||
|
||
``` vb | ||
Sub SumHighlightedCells() | ||
Dim cell As Range | ||
Dim total As Double | ||
|
||
' Loop through each cell in the selection | ||
For Each cell In Selection | ||
' Check if the cell contains a numeric value | ||
If IsNumeric(cell.Value) Then | ||
total = total + cell.Value | ||
End If | ||
Next cell | ||
|
||
' Display the sum in a message box | ||
MsgBox "The sum of the highlighted cells is: " & total | ||
End Sub | ||
``` | ||
|
||
## Result | ||
|
||
![Sum of highlighted cells](/assets/images/plugins/sum-of-highlighted-cells.png) |
2 changes: 1 addition & 1 deletion
2
...ages/Docs/Plugin and Macros/Macros/Samples/Unhide all 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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
--- | ||
order: -6 | ||
order: -7 | ||
--- | ||
|
||
## Description | ||
|
2 changes: 1 addition & 1 deletion
2
site/pages/Docs/Plugin and Macros/Macros/Samples/Unmerge cell range/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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
--- | ||
order: -16 | ||
order: -17 | ||
--- | ||
|
||
## Description | ||
|
2 changes: 1 addition & 1 deletion
2
...ges/Docs/Plugin and Macros/Macros/Samples/Write data to worksheet cell/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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
--- | ||
order: -21 | ||
order: -22 | ||
--- | ||
|
||
## Description | ||
|
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