在Excel中的Excel公式

任何人都可以告诉我这个MS Excelfunction背后的math。 我在PHP中编写代码,我无法使用Excel来计算这些,但我仍然需要相同的结果。

CUMIPMT(rate,nper,pv,start_period,end_period,type) Returns the cumulative interest paid on a loan between start_period and end_period. 

我的Excelfunction –

 =IF($C$33<0,CUMIPMT($C$36/12,$C$35,-$C$33,$C$34,$C$34+11,0),-CUMIPMT($C$36/12,$C$35,$C$33,$C$34,$C$34+11,0)) 

还有一个问题 – 我使用(=E11-E12)但它并没有减less,它增加了两个值,我不明白为什么?

先谢谢你

我没有使用它,但你可能想看看PHPExcel库 。 Excel和PHP是不同的,你可能需要使用一个类似于我链接到的函数库,或者编写函数来手动完成所有这些math运算。 在你的情况下,似乎处理Excel文件可能是实现你的目标的最简单的方法。

IF( condition, [value_if_true], [value_if_false] )

条件是你想testing的价值。

value_if_true是可选的。 如果条件评估为TRUE,则返回值。

value_if_false是可选的。 如果条件评估为FALSE,则返回值。

所以基本上是这样说的

 if ($C$33 < 0) { // if the condition is TRUE return CUMIPMT($C$36 / 12, $C$35, -$C$33, $C$34, $C$34 + 11, 0); } else { // if the condition is FALSE return -CUMIPMT($C$36 / 12, $C$35, $C$33, $C$34, $C$34 + 11, 0); } 

关于你的(=E11-E12)问题。 尝试将其更改为=E11-E12 。 如果E12是一个负数,你必须记得减号将分配。

编辑:关于您的评论,我希望这个链接帮助

http://www.excelforum.com/excel-programming-vba-macros/515109-need-longhand-formulas-for-cumipmt-and-cumprinc-functions-in-excel.html

我知道这个线程是旧的,但我正在将Excel电子表格转换为objective-c,并且还需要一个答案。 这是我最终写的解决scheme:

 double cumipmt(double rate, int nper, double pv, int start_period, int end_period, BOOL type) { double cumipmt = 0; double thePmt = pmt(rate, nper, pv, 0, type); double endValue = pv; if (type==0) { for (int i=1; i<=end_period; i++) { double beginning = endValue; double interest = beginning * rate; endValue = beginning + interest + thePmt; if (i>=start_period) { cumipmt += interest; } } } else { for (int i=1; i<end_period; i++) { double beginning = endValue + thePmt; double interest = beginning * rate; endValue = beginning + interest + thePmt; if (i>=start_period) { cumipmt += interest; } } } return cumipmt; } double pvFactor(double rate, int nper) { return (1 / fvFactor(rate, nper)); } double fvFactor(double rate, int nper) { return pow(1+rate,nper); } double annuityPvFactor(double rate, int nper, bool type) { if (rate == 0) { return nper; } else { return (1 + rate * type) * (1 - pvFactor(rate, nper)) / rate; } } double pmt(double rate, int nper, double pv, double fv, bool type) { return (-1 * (pv + fv + pvFactor(rate, nper))) / (annuityPvFactor(rate, nper, type)); } 

我知道这不是在PHP中,但它应该是一个简单的任务转换。