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.

Calling Internal Calc functions in Basic

Use the CreateUnoService function to access the com.sun.star.sheet.FunctionAccess service.

Örnek:

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. It 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.

note

All Calc functions must be expressed with their English names.


Örnek:


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

Calling Add-In Calc Functions in BASIC

The Calc Add-In functions are in the UNO services com.sun.star.sheet.addin.Analysis, com.sun.star.sheet.addin.DateFunctions and com.sun.star.sheet.addin.PricingFunctions.

Örnek:


REM Example calling Add-in function SQRTPI
Function MySQRTPI(arg as double) as double
   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.

Örnek:


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

UNO Service Names for Analysis Add-In Functions

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

Calc Function name

UNO service name

GERÇEKFAİZ

com.sun.star.sheet.addin.Analysis.getAccrint

GERÇEKFAİZV

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

BIN2DEC

com.sun.star.sheet.addin.Analysis.getBin2Dec

BIN2HEX

com.sun.star.sheet.addin.Analysis.getBin2Hex

BIN2OCT

com.sun.star.sheet.addin.Analysis.getBin2Oct

KARMAŞIK

com.sun.star.sheet.addin.Analysis.getComplex

ÇEVİR

com.sun.star.sheet.addin.Analysis.getConvert

KUPONGÜNBD

com.sun.star.sheet.addin.Analysis.getCoupdaybs

KUPONGÜN

com.sun.star.sheet.addin.Analysis.getCoupdays

KUPONGÜNDSK

com.sun.star.sheet.addin.Analysis.getCoupdaysnc

KUPONGÜNSKT

com.sun.star.sheet.addin.Analysis.getCoupncd

KUPONSAYI

com.sun.star.sheet.addin.Analysis.getCoupnum

KUPONGÜNÖKT

com.sun.star.sheet.addin.Analysis.getCouppcd

TOPÖDENENFAİZ

com.sun.star.sheet.addin.Analysis.getCumipmt

TOPANAPARA

com.sun.star.sheet.addin.Analysis.getCumprinc

DEC2BIN

com.sun.star.sheet.addin.Analysis.getDec2Bin

DEC2HEX

com.sun.star.sheet.addin.Analysis.getDec2Hex

DEC2OCT

com.sun.star.sheet.addin.Analysis.getDec2Oct

DELTA

com.sun.star.sheet.addin.Analysis.getDelta

İNDİRİM

com.sun.star.sheet.addin.Analysis.getDisc

LİRAON

com.sun.star.sheet.addin.Analysis.getDollarde

LİRAKES

com.sun.star.sheet.addin.Analysis.getDollarfr

SÜRE

com.sun.star.sheet.addin.Analysis.getDuration

SERİTARİH

com.sun.star.sheet.addin.Analysis.getEdate

ETKİN

com.sun.star.sheet.addin.Analysis.getEffect

SERİAY

com.sun.star.sheet.addin.Analysis.getEomonth

HATAİŞLEV

com.sun.star.sheet.addin.Analysis.getErf

TÜMHATAİŞLEV

com.sun.star.sheet.addin.Analysis.getErfc

ÇİFTFAKTÖR

com.sun.star.sheet.addin.Analysis.getFactdouble

GDPROGRAM

com.sun.star.sheet.addin.Analysis.getFvschedule

OBEB

com.sun.star.sheet.addin.Analysis.getGcd

BESINIR

com.sun.star.sheet.addin.Analysis.getGestep

HEX2BIN

com.sun.star.sheet.addin.Analysis.getHex2Bin

HEX2DEC

com.sun.star.sheet.addin.Analysis.getHex2Dec

HEX2OCT

com.sun.star.sheet.addin.Analysis.getHex2Oct

SANMUTLAK

com.sun.star.sheet.addin.Analysis.getImabs

SANAL

com.sun.star.sheet.addin.Analysis.getImaginary

SANBAĞ_DEĞİŞKEN

com.sun.star.sheet.addin.Analysis.getImargument

SANEŞLENEK

com.sun.star.sheet.addin.Analysis.getImconjugate

SANCOS

com.sun.star.sheet.addin.Analysis.getImcos

SANCOSH

com.sun.star.sheet.addin.Analysis.getImcosh

SANCOT

com.sun.star.sheet.addin.Analysis.getImcot

SANCSC

com.sun.star.sheet.addin.Analysis.getImcsc

SANCSCH

com.sun.star.sheet.addin.Analysis.getImcsch

SANBÖL

com.sun.star.sheet.addin.Analysis.getImdiv

SANÜS

com.sun.star.sheet.addin.Analysis.getImexp

SANLN

com.sun.star.sheet.addin.Analysis.getImln

SANLOG10

com.sun.star.sheet.addin.Analysis.getImlog10

SANLOG2

com.sun.star.sheet.addin.Analysis.getImlog2

SANKUVVET

com.sun.star.sheet.addin.Analysis.getImpower

SANÇARP

com.sun.star.sheet.addin.Analysis.getImproduct

SANGERÇEK

com.sun.star.sheet.addin.Analysis.getImreal

SANSEC

com.sun.star.sheet.addin.Analysis.getImsec

SANSECH

com.sun.star.sheet.addin.Analysis.getImsech

SANSIN

com.sun.star.sheet.addin.Analysis.getImsin

SANSINH

com.sun.star.sheet.addin.Analysis.getImsinh

SANKAREKÖK

com.sun.star.sheet.addin.Analysis.getImsqrt

SANÇIKAR

com.sun.star.sheet.addin.Analysis.getImsub

SANTOPLA

com.sun.star.sheet.addin.Analysis.getImsum

SANTAN

com.sun.star.sheet.addin.Analysis.getImtan

FAİZORANI

com.sun.star.sheet.addin.Analysis.getIntrate

ÇİFTMİ

com.sun.star.sheet.addin.Analysis.getIseven

TEKMİ

com.sun.star.sheet.addin.Analysis.getIsodd

OKEK

com.sun.star.sheet.addin.Analysis.getLcm

MSÜRE

com.sun.star.sheet.addin.Analysis.getMduration

KYUVARLA

com.sun.star.sheet.addin.Analysis.getMround

ÇOKTERİMLİ

com.sun.star.sheet.addin.Analysis.getMultinomial

TAMİŞGÜNÜ

com.sun.star.sheet.addin.Analysis.getNetworkdays

NOMİNAL

com.sun.star.sheet.addin.Analysis.getNominal

OCT2BIN

com.sun.star.sheet.addin.Analysis.getOct2Bin

OCT2DEC

com.sun.star.sheet.addin.Analysis.getOct2Dec

OCT2HEX

com.sun.star.sheet.addin.Analysis.getOct2Hex

TEKYDEĞER

com.sun.star.sheet.addin.Analysis.getOddfprice

TEKYGETİRİ

com.sun.star.sheet.addin.Analysis.getOddfyield

TEKSDEĞER

com.sun.star.sheet.addin.Analysis.getOddlprice

TEKSGETİRİ

com.sun.star.sheet.addin.Analysis.getOddlyield

DEĞER

com.sun.star.sheet.addin.Analysis.getPrice

DEĞERİND

com.sun.star.sheet.addin.Analysis.getPricedisc

DEĞERVADE

com.sun.star.sheet.addin.Analysis.getPricemat

BÖLÜM

com.sun.star.sheet.addin.Analysis.getQuotient

RASTGELEARADA

com.sun.star.sheet.addin.Analysis.getRandbetween

GETİRİ

com.sun.star.sheet.addin.Analysis.getReceived

SERİTOPLA

com.sun.star.sheet.addin.Analysis.getSeriessum

KAREKÖKPİ

com.sun.star.sheet.addin.Analysis.getSqrtpi

HTAHEŞ

com.sun.star.sheet.addin.Analysis.getTbilleq

HTAHDEĞER

com.sun.star.sheet.addin.Analysis.getTbillprice

HTAHGETİRİ

com.sun.star.sheet.addin.Analysis.getTbillyield

HAFTASAY

com.sun.star.sheet.addin.Analysis.getWeeknum

İŞGÜNÜ

com.sun.star.sheet.addin.Analysis.getWorkday

AİÇVERİMORANI

com.sun.star.sheet.addin.Analysis.getXirr

ANBD

com.sun.star.sheet.addin.Analysis.getXnpv

YILORAN

com.sun.star.sheet.addin.Analysis.getYearfrac

ÖDEME

com.sun.star.sheet.addin.Analysis.getYield

ÖDEMEİND

com.sun.star.sheet.addin.Analysis.getYielddisc

GETİRİVADE

com.sun.star.sheet.addin.Analysis.getYieldmat


UNO Service Names for Date Add-In Functions

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

Calc Function name

UNO service name

AYDAKİGÜNLER

com.sun.star.sheet.addin.DateFunctions.getDaysInMonth

YILDAKİGÜNLER

com.sun.star.sheet.addin.DateFunctions.getDaysInMonth

AYLAR

com.sun.star.sheet.addin.DateFunctions.getDiffMonths

HAFTALAR

com.sun.star.sheet.addin.DateFunctions.getDiffWeeks

YILLAR

com.sun.star.sheet.addin.DateFunctions.getDiffYears

ROT13

com.sun.star.sheet.addin.DateFunctions.getRot13

YILDAKİHAFTALAR

com.sun.star.sheet.addin.DateFunctions.getWeeksInYear


UNO Service Names for Pricing Add-In Functions

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

Calc Function name

UNO service name

OPT_BARRIER

com.sun.star.sheet.addin.PrincingFunctions.getOptBarrier

OPT_PROB_HIT

com.sun.star.sheet.addin.PrincingFunctions.getOptProbHit

OPT_PROB_INMONEY

com.sun.star.sheet.addin.PrincingFunctions.getOptProbInMoney

OPT_TOUCH

com.sun.star.sheet.addin.PrincingFunctions.getOptTouch


Lütfen bizi destekleyin!