如何使用org.apache.poi.ss.formula.FormulaParser解析式? [英] How to use org.apache.poi.ss.formula.FormulaParser to parse the formula?

查看:557
本文介绍了如何使用org.apache.poi.ss.formula.FormulaParser解析式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用org.apache.poi.ss.formula.FormulaParserü可以给我简单的code snippt。

Can u give me the simple code snippt using org.apache.poi.ss.formula.FormulaParser.

有FormulaParser类中的方法解析(),但它返回PTG []。我不知道哪里是PTG类...

请指导我用formulaParse解析excel表公式...

FormulaParser class having the method parse().But it returns ptg[].i dont know where is the ptg class...
Please guide me to use formulaParse to parse the excel sheet formula...

Saravanan

Saravanan

推荐答案

PTG [] 是的标记从而重新$ p $阵列psents单元格中的公式。

Ptg[] is a array of tokens which represents the formula in the cell.

在我的excel表假设我有同一个公式单元格为

Suppose in my excel sheet I have as cell with a formula as

=D4+D6+D8-D11+D23+D29+D46-D49

通过FormulaParser运行这给了我,我都打印出来,如下图所示。

Running this through a FormulaParser gives me an array which I have printed out as shown below

HSSFEvaluationWorkbook hssfew = HSSFEvaluationWorkbook.create(workBook);

Ptg[] ptg = FormulaParser.parse(cell1.getCellFormula(), hssfew, FormulaType.NAMEDRANGE, 0);

for (int i=0;i<ptg.length;i++){
    System.out.println (ptg[i]);
}

结果

org.apache.poi.hssf.record.formula.RefPtg [D4] 
org.apache.poi.hssf.record.formula.RefPtg [D6] 
class org.apache.poi.hssf.record.formula.AddPtg 
org.apache.poi.hssf.record.formula.RefPtg [D8] 
class org.apache.poi.hssf.record.formula.AddPtg 
org.apache.poi.hssf.record.formula.RefPtg [D11] 
class org.apache.poi.hssf.record.formula.SubtractPtg
org.apache.poi.hssf.record.formula.RefPtg [D23]
class org.apache.poi.hssf.record.formula.AddPtg 
org.apache.poi.hssf.record.formula.RefPtg [D29] 
class org.apache.poi.hssf.record.formula.AddPtg 
org.apache.poi.hssf.record.formula.RefPtg [D46] 
class org.apache.poi.hssf.record.formula.AddPtg 
org.apache.poi.hssf.record.formula.RefPtg [D49] 
class org.apache.poi.hssf.record.formula.SubtractPtg

正如你可以看到这个公式中的每个元素分解到相应的单元格位置或操作员
AddPtg为 + 和SubtractPtg为 - 运营商

As you can see this breaks down each element in the formula into the respective cell location or operator AddPtg for + and SubtractPtg for - operator

这是一个简单的例子,你可以尝试更复杂的东西。

This is a simple example, you can try out more complex stuff

这篇关于如何使用org.apache.poi.ss.formula.FormulaParser解析式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆