Innhald
Innhaldsliste 🔎︎

# Using Calc Functions in Macros

In addition to the native BASIC functions, you can call Calc functions in your macros and scripts and set Calc functions in cell formulas.

## Oppkall av interne Calc-funksjonar i Basic

Bruk funksjonen CreateUNOService for å få tilgang til tenesta com.sun.star.sheet.FunctionAccess.

### Eksempel:

The example below creates a function named MyVlook that calls the VLOOKUP Calc function over a data array passed as argument and returns the value found by the function.

        Function MyVlook(Lookup, DataArray As Object, Index As Integer, SortedRangeLookup as Byte)
            Dim oService As Object
            Set oService = createUnoService("com.sun.star.sheet.FunctionAccess")
            ' Always use the function name in English
            MyVlook = oService.callFunction("VLOOKUP", Array(Lookup, DataArray, Index, SortedRangeLookup))
        End Function

The macro below presents an example of how the MyVlook function can be called. If first creates a 5-by-2 data array and then calls the function MyVlook and shows the returned value using MsgBox.

        Sub CallingMyVlook()
            ' Creates a 5 by 2 array and fills it with data
            Dim myData(1 to 5, 1 to 2) as Variant
            myData(1, 1) = 1 : myData(1, 2) = "Strongly disagree"
            myData(2, 1) = 3 : myData(2, 2) = "Disagree"
            myData(3, 1) = 5 : myData(3, 2) = "Undecided"
            myData(4, 1) = 7 : myData(4, 2) = "Agree"
            myData(5, 1) = 9 : myData(5, 2) = "Strongly agree"
            ' Looks up the data array
            Dim result as String
            result = MyVlook(4, myData, 2, 1)
            ' Shows the message "Disagree"
            MsgBox result
        End Sub

## Setting Cell Formulas Containing Internal Calc Functions

Use the formula text string to add a formula to a spreadsheet cell.

All Calc functions must be expressed with their English names.

### Eksempel:

    Sub AssignFormulaToCell
    REM Add a formula to cell A1. Function name must be in English.
        oCell = ThisComponent.Sheets.getByIndex(0).getCellRangeByName("A1")
        oCell.Formula = "=SUM(B1:B10)"
    REM Cell A1 displays the localized function name
    End Sub

## Oppkall av Calc-tilleggsfunksjonar i BASIC

Tilleggsfunksjonane i Calc finst i com.sun.star.sheet.addin.Analysis.

### Eksempel:

    REM Example calling Add-in function SQRTPI
    Funksjonen MySQRTPI(arg som dobbel) som dobbel
       Dim oService as Object
       oService = createUNOService("com.sun.star.sheet.addin.Analysis")
       MySQRTPI = oService.getSqrtPi(arg)
    End Function

## Setting Cell Formulas with Add-In Functions

The Add-In function must be expressed by its UNO service name.

### Eksempel:

    Sub AssignAddInFormulaToCell
    REM Add an Add-In formula to cell A1. Function name is the UNO service name.
        oCell = ThisComponent.Sheets.getByIndex(0).getCellRangeByName("A1")
        oCell.Formula = "=com.sun.star.sheet.addin.Analysis.getBin2Dec(B1)"
    REM Cell A1 displays the localized function name
    End Sub

## Add-In Functions UNO service Names

The table below presents a list of all Calc Add-In functions and their respective UNO service names.

Calc Function name | UNO service name
PÅLØPT.PERIODISK.RENTE | com.sun.star.sheet.addin.Analysis.getAccrint
PÅLØPT.FORFALLSRENTE | com.sun.star.sheet.addin.Analysis.getAccrintm
AMORDEGRC | com.sun.star.sheet.addin.Analysis.getAmordegrc
AMORLINC | com.sun.star.sheet.addin.Analysis.getAmorlinc
BESSELI | com.sun.star.sheet.addin.Analysis.getBesseli
BESSELJ | com.sun.star.sheet.addin.Analysis.getBesselj
BESSELK | com.sun.star.sheet.addin.Analysis.getBesselk
BESSELY | com.sun.star.sheet.addin.Analysis.getBessely
BINTILDES | com.sun.star.sheet.addin.Analysis.getBin2Dec
BINTILHEKS | com.sun.star.sheet.addin.Analysis.getBin2Hex
BINTILOKT | com.sun.star.sheet.addin.Analysis.getBin2Oct
KOMPLEKS | com.sun.star.sheet.addin.Analysis.getComplex
KONVERTER | com.sun.star.sheet.addin.Analysis.getConvert
KUPONG.DAGAROPPGJERTILPERIODESLUTT | com.sun.star.sheet.addin.Analysis.getCoupdaybs
KUPONG.DAGAR | com.sun.star.sheet.addin.Analysis.getCoupdays
KUPONG.DAGAROPPGJERTILNESTERENTEUTB | com.sun.star.sheet.addin.Analysis.getCoupdaysnc
KUPONG.NESTERENTEUTB | com.sun.star.sheet.addin.Analysis.getCoupncd
KUPONG.TALKUPONGPERIODAR | com.sun.star.sheet.addin.Analysis.getCoupnum
KUPONG.FØRRERENTEUTB | com.sun.star.sheet.addin.Analysis.getCouppcd
SAMLA.RENTE | com.sun.star.sheet.addin.Analysis.getCumipmt
SAMLA.HOVUDSTOL | com.sun.star.sheet.addin.Analysis.getCumprinc
DESTILBIN | com.sun.star.sheet.addin.Analysis.getDec2Bin
DESTILHEKS | com.sun.star.sheet.addin.Analysis.getDec2Hex
DESTILOKT | com.sun.star.sheet.addin.Analysis.getDec2Oct
DELTA | com.sun.star.sheet.addin.Analysis.getDelta
DISKONTERT | com.sun.star.sheet.addin.Analysis.getDisc
VALUTA.DESIMAL | com.sun.star.sheet.addin.Analysis.getDollarde
VALUTA.BRØK | com.sun.star.sheet.addin.Analysis.getDollarfr
PERIODAR | com.sun.star.sheet.addin.Analysis.getDuration
DAG.ETTER | com.sun.star.sheet.addin.Analysis.getEdate
EFFEKTIV.RENTE | com.sun.star.sheet.addin.Analysis.getEffect
MÅNADSSLUTT | com.sun.star.sheet.addin.Analysis.getEomonth
FEILF | com.sun.star.sheet.addin.Analysis.getErf
FEILFK | com.sun.star.sheet.addin.Analysis.getErfc
DOBBELFAKULTET | com.sun.star.sheet.addin.Analysis.getFactdouble
SVPLAN | com.sun.star.sheet.addin.Analysis.getFvschedule
SFF | com.sun.star.sheet.addin.Analysis.getGcd
GRENSEVERDI | com.sun.star.sheet.addin.Analysis.getGestep
HEKSTILBIN | com.sun.star.sheet.addin.Analysis.getHex2Bin
HEKSTILDES | com.sun.star.sheet.addin.Analysis.getHex2Dec
HEKSTILOKT | com.sun.star.sheet.addin.Analysis.getHex2Oct
IMABS | com.sun.star.sheet.addin.Analysis.getImabs
IMAGINÆR | com.sun.star.sheet.addin.Analysis.getImaginary
IMARGUMENT | com.sun.star.sheet.addin.Analysis.getImargument
IMKONJUGERT | com.sun.star.sheet.addin.Analysis.getImconjugate
IMCOS | com.sun.star.sheet.addin.Analysis.getImcos
IMCOSH | com.sun.star.sheet.addin.Analysis.getImcosh
IMCOT | com.sun.star.sheet.addin.Analysis.getImcot
IMCSC | com.sun.star.sheet.addin.Analysis.getImcsc
IMCSCH | com.sun.star.sheet.addin.Analysis.getImcsch
IMDIV | com.sun.star.sheet.addin.Analysis.getImdiv
IMEKSP | com.sun.star.sheet.addin.Analysis.getImexp
IMLN | com.sun.star.sheet.addin.Analysis.getImln
IMLOG10 | com.sun.star.sheet.addin.Analysis.getImlog10
IMLOG2 | com.sun.star.sheet.addin.Analysis.getImlog2
IMOPPHØG | com.sun.star.sheet.addin.Analysis.getImpower
IMPRODUKT | com.sun.star.sheet.addin.Analysis.getImproduct
IMREELL | com.sun.star.sheet.addin.Analysis.getImreal
IMSEKANT | com.sun.star.sheet.addin.Analysis.getImsec
IMSEKANTH | com.sun.star.sheet.addin.Analysis.getImsech
IMSIN | com.sun.star.sheet.addin.Analysis.getImsin
IMSINH | com.sun.star.sheet.addin.Analysis.getImsinh
IMROT | com.sun.star.sheet.addin.Analysis.getImsqrt
IMSUB | com.sun.star.sheet.addin.Analysis.getImsub
IMSUMMER | com.sun.star.sheet.addin.Analysis.getImsum
IMTAN | com.sun.star.sheet.addin.Analysis.getImtan
RENTESATS | com.sun.star.sheet.addin.Analysis.getIntrate
ERPARTAL | com.sun.star.sheet.addin.Analysis.getIseven
ERODDETAL | com.sun.star.sheet.addin.Analysis.getIsodd
MFM | com.sun.star.sheet.addin.Analysis.getLcm
MPERIODAR | com.sun.star.sheet.addin.Analysis.getMduration
MRUND | com.sun.star.sheet.addin.Analysis.getMround
MULTINOMINELL | com.sun.star.sheet.addin.Analysis.getMultinomial
NETTO.ARBEIDSDAGAR | com.sun.star.sheet.addin.Analysis.getNetworkdays
NOMINELL | com.sun.star.sheet.addin.Analysis.getNominal
OKTTILBIN | com.sun.star.sheet.addin.Analysis.getOct2Bin
OKTTILDES | com.sun.star.sheet.addin.Analysis.getOct2Dec
OKTTILHEKS | com.sun.star.sheet.addin.Analysis.getOct2Hex
AVVIKFP.PRIS | com.sun.star.sheet.addin.Analysis.getOddfprice
AVVIKFP.AVKASTNING | com.sun.star.sheet.addin.Analysis.getOddfyield
AVVIKSP.PRIS | com.sun.star.sheet.addin.Analysis.getOddlprice
AVVIKSP.AVKASTNING | com.sun.star.sheet.addin.Analysis.getOddlyield
PRIS | com.sun.star.sheet.addin.Analysis.getPrice
PRIS.DISKONTERT | com.sun.star.sheet.addin.Analysis.getPricedisc
PRIS.FORFALL | com.sun.star.sheet.addin.Analysis.getPricemat
KVOTIENT | com.sun.star.sheet.addin.Analysis.getQuotient
TILFELDIGMELLOM | com.sun.star.sheet.addin.Analysis.getRandbetween
MOTTEKEN.AVKAST | com.sun.star.sheet.addin.Analysis.getReceived
SUMMER.REKKJE | com.sun.star.sheet.addin.Analysis.getSeriessum
ROTPI | com.sun.star.sheet.addin.Analysis.getSqrtpi
TBILLEKV | com.sun.star.sheet.addin.Analysis.getTbilleq
TBILLPRIS | com.sun.star.sheet.addin.Analysis.getTbillprice
TBILLAVKASTNING | com.sun.star.sheet.addin.Analysis.getTbillyield
VEKENR | com.sun.star.sheet.addin.Analysis.getWeeknum
ARBEIDSDAG | com.sun.star.sheet.addin.Analysis.getWorkday
XIR | com.sun.star.sheet.addin.Analysis.getXirr
XNNV | com.sun.star.sheet.addin.Analysis.getXnpv
ÅRDEL | com.sun.star.sheet.addin.Analysis.getYearfrac
AVKAST | com.sun.star.sheet.addin.Analysis.getYield
AVKAST.DISKONTERT | com.sun.star.sheet.addin.Analysis.getYielddisc
AVKAST.FORFALL | com.sun.star.sheet.addin.Analysis.getYieldmat

Liknande emne

CreateUnoService-funksjonen