How can I do to get the hexadecimal color from a cell using LIbre Office? - libreoffice

I have some cells which have a background color and I would like to get the hexadecimal color from this.
How can I do to get these hexadecimal code ?
Thank you very much !

A not very complex macro function can cope with this task.
REM ***** BASIC *****
Option VbaSupport 1
Function getBkColor(aCell As Range) As String
getBkColor = "#" + CreateUNOService("com.sun.star.sheet.FunctionAccess").callFunction("DEC2HEX",Array(aCell.CellRange.CellBackColor))
End Function

Related

Converting numbers into timestamps (inserting colons at specific places)

I'm using AutoHotkey for this as the code is the most understandable to me. So I have a document with numbers and text, for example like this
120344 text text text
234000 text text
and the desired output is
12:03:44 text text text
23:40:00 text text
I'm sure StrReplace can be used to insert the colons in, but I'm not sure how to specify the position of the colons or ask AHK to 'find' specific strings of 6 digit numbers. Before, I would have highlighted the text I want to apply StrReplace to and then press a hotkey, but I was wondering if there is a more efficient way to do this that doesn't need my interaction. Even just pointing to the relevant functions I would need to look into to do this would be helpful! Thanks so much, I'm still very new to programming.
hfontanez's answer was very helpful in figuring out that for this problem, I had to use a loop and substring function. I'm sure there are much less messy ways to write this code, but this is the final version of what worked for my purposes:
Loop, read, C:\[location of input file]
{
{ If A_LoopReadLine = ;
Continue ; this part is to ignore the blank lines in the file
}
{
one := A_LoopReadLine
x := SubStr(one, 1, 2)
y := SubStr(one, 3, 2)
z := SubStr(one, 5)
two := x . ":" . y . ":" . z
FileAppend, %two%`r`n, C:\[location of output file]
}
}
return
Assuming that the "timestamp" component is always 6 characters long and always at the beginning of the string, this solution should work just fine.
String test = "012345 test test test";
test = test.substring(0, 2) + ":" + test.substring(2, 4) + ":" + test.substring(4, test.length());
This outputs 01:23:45 test test test
Why? Because you are temporarily creating a String object that it's two characters long and then you insert the colon before taking the next pair. Lastly, you append the rest of the String and assign it to whichever String variable you want. Remember, the substring method doesn't modify the String object you are calling the method on. This method returns a "new" String object. Therefore, the variable test is unmodified until the assignment operation kicks in at the end.
Alternatively, you can use a StringBuilder and append each component like this:
StringBuilder sbuff = new StringBuilder();
sbuff.append(test.substring(0,2));
sbuff.append(":");
sbuff.append(test.substring(2,4));
sbuff.append(":");
sbuff.append(test.substring(4,test.length()));
test = sbuff.toString();
You could also use a "fancy" loop to do this, but I think for something this simple, looping is just overkill. Oh, I almost forgot, this should work with both of your test strings because after the last colon insert, the code takes the substring from index position 4 all the way to the end of the string indiscriminately.

How to make title interpret only part of a title string in Matlab

I'm creating a plot where I want to combine two strings into a title. I want to color the other part of my string. Here is my code (it will explain itself better):
title([csv_name ', {\color{blue}Bowel AUC: ' num2str(bowelAUC) ' }'])
In the variable csv_name I have a filename containing underscore _ characters and in the variable bowelAUC I have a number. I can color only part of my title string by using the guide in this post, that is using tex, but the problem now is that tex interpreter would also interpret the csv_name variable and I don't want this. Here you can see what I get:
The filename looks like this: ExportedPressure_130A_10-29-2014.csv
So I want title to interpret only the second part of my title, not the first...how to do this?
You need to replace _ by \_ so that TeX interprets them correctly. To do that you can use regexprep (note that within regexprep both characters are escaped again):
csv_name_escaped = regexprep(csv_name, '\_', '\\\_');
title([csv_name_escaped ', {\color{blue}Bowel AUC: ' num2str(bowelAUC) ' }'])

Fmax, Dmax. How do I put the "max" as a subscript?

In Python I am currently plotting some data and extracting the maximum values.
now i want to have a label which looks like this:
Fmax = ... and Dmax = ..., except for the max being a subscript, like "down".
The label currently looks like this:
a1.plot(z, k, label = "Kraft [Fmax: %s N], "%(round(max(k))))
Thanks for help in advance!
Unicode has some subscript letters:
u'Kraft [Fₘₐₓ: %s N], '
u'Kraft [F\u2098\u2090\u2093: %s N], ' # same value escaped for ASCII-safe source
but you would need to be using a font that supported them.
Otherwise, you would be dependent on whatever text formatting features are provided by whatever the graphics library you are using is; if none then you would have to place the max yourself manually in a smaller font at the right position.

how to change display in gtk.spinbutton

I have a gtk.spinbutton and I want to set the digits according to the locale
format.
like say I have a locale installed hungarian so my decimal separator is
'.'(dot) and thousand separator is ','(comma) eg: my spinbutton value is
1131191 so after the user focus out of the gtk.spinbutton my value should
convert to 11,311.91 . the conversion is made by me but I am not able to set
it to gtk.spinbutton either using set_text / set_value method.
Any help is appreciated !
Thanks
Formatting a SpinButton can be done by handling the output signal.
locale.setlocale(locale.LC_ALL, '')
def output(spin):
digits = int(spin.props.digits)
value = spin.props.value
text = locale.format('%.*f', (digits, value), True)
spin.props.text = text
return True
spin.connect('output', output)
If you also want to let users enter values in the localised format (e.g. let the user type "1,000" instead of "1000"), handle the input signal.
def input(spin, new_value):
text = spin.props.text
try:
value = locale.atof(text)
except ValueError:
return -1
p = ctypes.c_double.from_address(hash(new_value))
p.value = value
return True
spin.connect('input', input)
(This code is longer than it should be because PyGTK does not properly wrap input, hence the ctypes hack. It's just parsing the text and then assigning the numeric value to a pointer location.)
Credits: The ctypes hack and digits formatting are inspired by Tim Evans's post in the PyGTK mailing list.

How to convert Unicode characters to escape codes

So, I have a bunch of strings like this: {\b\cf12 よろてそ } . I'm thinking I could iterate over each character and replace any unicode (Edit: Anything where AscW(char) > 127 or < 0) with a unicode escape code (\u###). However, I'm not sure how to programmatically do so. Any suggestions?
Clarification:
I have a string like {\b\cf12 よろてそ } and I want a string like {\b\cf12 [STUFF]}, where [STUFF] will display as よろてそ when I view the rtf text.
You can simply use the AscW() function to get the correct value:-
sRTF = "\u" & CStr(AscW(char))
Note unlike other escapes for unicode, RTF uses the decimal signed short int (2 bytes) representation for a unicode character. Which makes the conversion in VB6 really quite easy.
Edit
As MarkJ points out in a comment you would only do this for characters outside of 0-127 but then you would also need to give some other characters inside the 0-127 range special handling as well.
Another more roundabout way, would be to add the MSScript.OCX to the project and interface with VBScript's Escape function. For example
Sub main()
Dim s As String
s = ChrW$(&H3088) & ChrW$(&H308D) & ChrW$(&H3066) & ChrW$(&H305D)
Debug.Print MyEscape(s)
End Sub
Function MyEscape(s As String) As String
Dim scr As Object
Set scr = CreateObject("MSScriptControl.ScriptControl")
scr.Language = "VBScript"
scr.Reset
MyEscape = scr.eval("escape(" & dq(s) & ")")
End Function
Function dq(s)
dq = Chr$(34) & s & Chr$(34)
End Function
The Main routine passes in the original Japanese characters and the debug output says:
%u3088%u308D%u3066%u305D
HTH