当前位置: 首页 > news >正文

EasyExcel 导入计算公式导出展示字符串问题(SUM)

导出自定义表单 结果遇到 SUM函数 时 没有算出结果,直接展示的函数字符串

处理思路 拦截公式字符串 :

将对应的cell 设置 setCellFormula  字符串公式

然后cell类型设置为   CellType.FORMULA

重新配置 这样就解决了问题。

注意先设置CellFormula  然后设置 CellType (我把顺序搞反了,调试了很久

3这里用的是evaluateFormulaCell 而不是evaluateInCell 

原因evaluateInCell 导出的结果没函数计算式  

evaluateFormulaCell 导出结果有函数式

结果如下:

这里顺便给出 一个获取列表行求和转化工具

/*** @author lj* @title: CellCode* @projectName cloud* @date 2024/8/21 002110:46*/
public class CellCodeUtil {/*** 行汇总求和   从1  开始* @param startIndex  开始的列表下标    从1  开始* @param endIndex  开始的结束列下标   从1  开始* @param row  行 从 1 开始* @return  =SUM(B5:D5)*/public static String getRowSUN(int startIndex,int endIndex,int row){StringBuffer data = new StringBuffer("SUM(");data.append(excelColIndexToStr(startIndex) + row + ":");data.append(excelColIndexToStr(endIndex) + row + ")");return data.toString();}public static void main(String[] args) {System.out.println(getRowSUN(2,26,5));System.out.println(getColumnSUN(5,16,2));}/*** 列 汇总 求和  从1  开始* @param startIndex* @param endIndex* @param columnIndex  列表* @return*/public static String getColumnSUN(int startIndex,int endIndex, int columnIndex){StringBuffer data = new StringBuffer("SUM(");data.append(excelColIndexToStr(columnIndex) + startIndex + ":");data.append(excelColIndexToStr(columnIndex) + endIndex + ")");return data.toString();}/*** 下标转列* @param columnIndex  从1 开始* @return*/public static String excelColIndexToStr(int columnIndex) {if (columnIndex <= 0) {return null;}String columnStr = "";columnIndex--;do {if (columnStr.length() > 0) {columnIndex--;}columnStr = ((char) (columnIndex % 26 + (int) 'A')) + columnStr;columnIndex = (int) ((columnIndex - columnIndex % 26) / 26);} while (columnIndex > 0);return columnStr;}
}

测试:


http://www.mrgr.cn/news/7150.html

相关文章:

  • vue3 多文件下载zip压缩包
  • 基于AT32F421的开源电调项目测试
  • 获取当前时间戳
  • Nginx配置负载均衡
  • 如何使用 Java 中的 API 更改 PDF 纸张大小
  • 『基础』线性代数-1行列式
  • 【吊打面试官系列-Memcached面试题】memcached 能接受的 key 的最大长度是多少?
  • 亚信科技转型持久战:扎根行业大模型,深耕行业数字化
  • 户用光伏项目如何操作?
  • 鸿蒙 点击获取电话号拨打电话 @ohos.telephony.call (拨打电话)
  • 【机器翻译方向】数据集合集!
  • 在JavaScript中,如何实现异步编程?
  • Linux驱动入门实验班——DAC模块驱动(附百问网视频链接)
  • [ACTF新生赛2020]music附赠支持多国语言Fuzz语音转录文本翻译软件下载安装使用简介
  • 【jvm】程序计数器的特征
  • 前端css溢出属性overflow
  • [sqlserver][sql]sqlserver跨主机访问 跨数据库访问 数据库链接
  • windows安全软件之火绒杀毒的密码忘记后处理
  • 什么是CUDA
  • 学习记录:js算法(十二):柱状图中最大的矩形