Last active
December 7, 2023 07:46
-
-
Save ceruleancerise/93e458fe4c3a51ec1da6456a5645760c to your computer and use it in GitHub Desktop.
OpenOffice / LibreOffice: Set Selections' Values As Background Color To JSON (BASIC Macro)
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
REM ***** BASIC ***** | |
'Sets the value of selected cells as the hex code for the background color.' | |
'(More useful if you set this macro as a toolbar button.)' | |
SUB SetValueAsBackgroundColor | |
SET selectionRange = ThisComponent.CurrentSelection | |
FOR j = 0 TO selectionRange.Columns.getCount() - 1 | |
FOR i = 0 TO selectionRange.Rows.getCount() - 1 | |
SET cell = selectionRange.getCellByPosition(j, i) | |
colorAsDec = cell.CellBackColor | |
colorAsHex = CreateUNOService("com.sun.star.sheet.FunctionAccess").callFunction("DEC2HEX",Array(colorAsDec)) | |
'Pad hex string if needed.' | |
WHILE Len(colorAsHex) < 6 | |
colorAsHex = "0" + colorAsHex | |
WEND | |
cell.setString("#" + colorAsHex) | |
NEXT | |
NEXT | |
END SUB |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment