von Axel Richter » Do, 05.07.2012 22:39
Hallo,
Migesius hat geschrieben:Nun müsste ich für Matrix1 noch das Argument ="AEB" und bei Matrix2 das Argument =2012.06 mitgeben,
Hm, nein. SUMPRODUCT erwartet als Parameter Matrixen. Dass die Angabe A2:A9="AEB" in eine {TRUE;FALSE;...} Matrix umgewandelt wird, das managed CALC *vor* dem Aufruf der Funktion. Die Funktion sieht am Ende nur die Matrix.
Willst Du also die Funktion entsprechend aufrufen, musst Du das vorher managen.
Bsp1:
Code: Alles auswählen
Sub Main1
oS = ThisComponent.sheets(0)
sMA = "AEB"
nPer = 2012.06
FuncInst = createUnoService( "com.sun.star.sheet.FunctionAccess" )
Matrix1 = oS.getCellRangeByPosition(0,1,0,8).DataArray
for i = lbound(Matrix1) to ubound(Matrix1)
zeile = Matrix1(i)
for j = lbound(zeile) to ubound(zeile)
zeile(j) = (zeile(j) = sMa)*-1
next j
Matrix1(i) = zeile
next i
Matrix2 = oS.getCellRangeByPosition(1,1,1,8).DataArray
for i = lbound(Matrix2) to ubound(Matrix2)
zeile = Matrix2(i)
for j = lbound(zeile) to ubound(zeile)
zeile(j) = (zeile(j) = nPer)*-1
next j
Matrix2(i) = zeile
next i
Matrix3 = oS.getCellRangeByPosition(2,1,2,8).DataArray
lMonTotal = FuncInst.callFunction("sumproduct",array(Matrix1,Matrix2,Matrix3))
msgbox lMonTotal
End Sub
oder mit einem temporären Sheet:
Code: Alles auswählen
sub Main2
oS = ThisComponent.sheets(0)
sMA = "AEB"
nPer = 2012.06
FuncInst = createUnoService( "com.sun.star.sheet.FunctionAccess" )
tempSheet = ThisComponent.createInstance("com.sun.star.sheet.Spreadsheet")
ThisComponent.Sheets.insertByName("tempSheet", tempSheet)
Matrix1 = oS.getCellRangeByPosition(0,1,0,8).DataArray
tempSheet.getCellRangeByPosition(0,1,0,8).DataArray = Matrix1
tempSheet.getCellRangeByPosition(1,1,1,8).ArrayFormula = "A2:A9=""AEB"""
Matrix1 = tempSheet.getCellRangeByPosition(1,1,1,8).DataArray
Matrix2 = oS.getCellRangeByPosition(1,1,1,8).DataArray
tempSheet.getCellRangeByPosition(1,1,1,8).DataArray = Matrix2
tempSheet.getCellRangeByPosition(2,1,2,8).ArrayFormula = "B2:B9=2012.06"
Matrix2 = tempSheet.getCellRangeByPosition(2,1,2,8).DataArray
ThisComponent.Sheets.removeByName("tempSheet")
Matrix3 = oS.getCellRangeByPosition(2,1,2,8).DataArray
lMonTotal = FuncInst.callFunction("sumproduct",array(Matrix1,Matrix2,Matrix3))
msgbox lMonTotal
end sub
viele Grüße
Axel
Hallo,
[quote="Migesius"]Nun müsste ich für Matrix1 noch das Argument ="AEB" und bei Matrix2 das Argument =2012.06 mitgeben,[/quote]
Hm, nein. SUMPRODUCT erwartet als Parameter Matrixen. Dass die Angabe A2:A9="AEB" in eine {TRUE;FALSE;...} Matrix umgewandelt wird, das managed CALC *vor* dem Aufruf der Funktion. Die Funktion sieht am Ende nur die Matrix.
Willst Du also die Funktion entsprechend aufrufen, musst Du das vorher managen.
Bsp1:
[code]
Sub Main1
oS = ThisComponent.sheets(0)
sMA = "AEB"
nPer = 2012.06
FuncInst = createUnoService( "com.sun.star.sheet.FunctionAccess" )
Matrix1 = oS.getCellRangeByPosition(0,1,0,8).DataArray
for i = lbound(Matrix1) to ubound(Matrix1)
zeile = Matrix1(i)
for j = lbound(zeile) to ubound(zeile)
zeile(j) = (zeile(j) = sMa)*-1
next j
Matrix1(i) = zeile
next i
Matrix2 = oS.getCellRangeByPosition(1,1,1,8).DataArray
for i = lbound(Matrix2) to ubound(Matrix2)
zeile = Matrix2(i)
for j = lbound(zeile) to ubound(zeile)
zeile(j) = (zeile(j) = nPer)*-1
next j
Matrix2(i) = zeile
next i
Matrix3 = oS.getCellRangeByPosition(2,1,2,8).DataArray
lMonTotal = FuncInst.callFunction("sumproduct",array(Matrix1,Matrix2,Matrix3))
msgbox lMonTotal
End Sub
[/code]
oder mit einem temporären Sheet:
[code]
sub Main2
oS = ThisComponent.sheets(0)
sMA = "AEB"
nPer = 2012.06
FuncInst = createUnoService( "com.sun.star.sheet.FunctionAccess" )
tempSheet = ThisComponent.createInstance("com.sun.star.sheet.Spreadsheet")
ThisComponent.Sheets.insertByName("tempSheet", tempSheet)
Matrix1 = oS.getCellRangeByPosition(0,1,0,8).DataArray
tempSheet.getCellRangeByPosition(0,1,0,8).DataArray = Matrix1
tempSheet.getCellRangeByPosition(1,1,1,8).ArrayFormula = "A2:A9=""AEB"""
Matrix1 = tempSheet.getCellRangeByPosition(1,1,1,8).DataArray
Matrix2 = oS.getCellRangeByPosition(1,1,1,8).DataArray
tempSheet.getCellRangeByPosition(1,1,1,8).DataArray = Matrix2
tempSheet.getCellRangeByPosition(2,1,2,8).ArrayFormula = "B2:B9=2012.06"
Matrix2 = tempSheet.getCellRangeByPosition(2,1,2,8).DataArray
ThisComponent.Sheets.removeByName("tempSheet")
Matrix3 = oS.getCellRangeByPosition(2,1,2,8).DataArray
lMonTotal = FuncInst.callFunction("sumproduct",array(Matrix1,Matrix2,Matrix3))
msgbox lMonTotal
end sub
[/code]
viele Grüße
Axel