Quantcast
Channel: Apache OpenOffice Community Forum
Viewing all articles
Browse latest Browse all 1281

Macros and UNO API • Round all numeric cells to 2 decimals

$
0
0
I write a triple loop to round all cells whose type is number to 2:

Code:

sub roundAllCells   dim oFunAccess as object   oFunAccess = createUnoService( "com.sun.star.sheet.FunctionAccess" )   for each oSheet in ThisComponent.Sheets        oCurs = oSheet.createCursor()          oCurs.gotoEndOfUsedArea(True)        num_row = oCurs.Rows.Count        num_col = oCurs.Columns.Count        for  i=0 to num_row-1        for  j=0 to num_col-1            oCell = oSheet.getCellByPosition(j,i)            if  oCell.type  = 1 then                              oCell.value = oFunAccess.CallFunction( "round", array(oCell.value,2))            end if        next j        next i    nextend sub
It is so long ,can simplify it with pure starbasic code,instead of setting "CompatibilityMode( true )" to use "round(number,digitals)" in VBA?

 Edit: Changed subject, was How can simplify the function to round all cells whose type is number? 
Make your post understandable by others 
-- MrProgrammer, forum moderator 

Statistics: Posted by luofeiyu — Sat Feb 01, 2025 4:09 pm



Viewing all articles
Browse latest Browse all 1281

Trending Articles