简体   繁体   English

如何在java中自定义excel公式

[英]How to customize excel formula in java

While writing excel code in java, I am currently looking for Standard Deviation Population formula in Apache Poi v4.1.1, which is not implemented hence exception is throwing, then appeared to have 2 solutions in my hand, #1) Implement custom formula #2) Tweak / Override existing formula 在java中编写excel代码时,我目前正在寻找Apache Poi v4.1.1中的标准偏差填充公式,该公式未实现,因此抛出异常,然后我手中似乎有2个解决方案,#1)实现自定义公式#2 )调整/覆盖现有公式

I am not sure how to override existing formula hence moved to solution 1, while doing this, I have some or the other issues 我不知道如何覆盖现有的公式,因此转移到解决方案1,而这样做,我有一些或其他问题

Problem: Let us say, in my excel, column B has 250 rows (dynamic no. of rows, in some cases 240 rows) and according to std dev formula, I need to first find the mean, so my query here is 问题:让我们说,在我的Excel中,B列有250行(动态行数,有些情况下是240行),根据std dev公式,我需要先找到均值,所以我的查询是

Q #1 ) how to know or select the non-empty values (column or rows) to write my own custom code.? Q#1 )如何知道或选择非空值(列或行)来编写我自己的自定义代码。

The formula can be added as a string. 公式可以作为字符串添加。

So it must not be implemented in Apache Poi, but must be implemented in the excel running your xlsx file. 所以它不能在Apache Poi中实现,但必须在运行xlsx文件的excel中实现。

You can simply add it as follow: 你可以简单地添加如下:

String strFormula= ...; // For example for a sum can be the string SUM(A1:A10)
cell.setCellType(HSSFCell.CELL_TYPE_FORMULA);
cell.setCellFormula(strFormula);

I found solution that, instead of implementing Standard deviation population formula, in Apache POI, there is a separate class available for Standard Deviation, we need to use it. 我找到的解决方案是,在Apache POI中,有一个单独的类可用于标准偏差,而不是实现标准偏差填充公式,我们需要使用它。

This link also useful Standard deviation with Apache Commons Math 此链接也可用于Apache Commons Math的标准偏差

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM