Oh my!
You wanted to convert single ordinary numbers from textual representation to number values.
The Text to Columns...
isn’t the appropriate tool for this if doing it by user code. You need to make sure that the cells of the respective range don’t preserve a non-numeric or misleading NumberFormat
. Then the content must be re-inserted for recognition as numbers. To use the .FormulaArray
for this step is a little trick.
To apply the General
format and aasignment of the key 0 (zero) to the respective property of the range object should suffice. If your needs are different, you can giv an additional cell serving as a NF template.
Sub Converter()
rgN = "$G$32:$G$40" REM Hard coded here.
doc = ThisComponent
sheet = doc.CurrentController.ActiveSheet
rg = sheet.getCellRangeByName(rgN)
da = rg.getDataArray
numFormatKey = 0 REM Should apply number format "General"
rg.NumberFormat = numFormatKey
rg.setFormulaArray(da)
End Sub
Hard coded ranges in Sub aren’t an exactly good idea. The following code allows to parametrize the task in a simple way. (Now also for the nuimber format.)
Sub toTemplateNF_Converter()
REM Many more enhancements possible.
paramCellN ="A1"
REM Name of Template cell, also containing tjhe name of the range to work on.
doc = ThisComponent
sheet = doc.CurrentController.ActiveSheet
paramCell = sheet.getCellRangeByName(paramCellN)
rg = sheet.getCellRangeByName(paramCell.String)
numFormatKey = paramCell.NumberFormat
da = rg.getDataArray
rg.NumberFormat = numFormatKey
rg.setFormulaArray(da)
End Sub
See also:
disask73043example.ods (13.6 KB)