java excel添加公式_Java添加、读取Excel公式
import com.spire.xls.*;public classAddFormula {public static voidmain(String[] args) {//创建Workbook对象
Workbook wb = newWorkbook();//获取第一个工作表
Worksheet sheet = wb.getWorksheets().get(0);//声明两个变量
int currentRow = 1;
String currentFormula= null;//设置列宽
sheet.setColumnWidth(1, 32);
sheet.setColumnWidth(2, 16);//写入用于测试的数据到单元格
sheet.getCellRange(currentRow,1).setValue("测试数据:");
sheet.getCellRange(currentRow,2).setNumberValue(1);
sheet.getCellRange(currentRow,3).setNumberValue(2);
sheet.getCellRange(currentRow,4).setNumberValue(3);
sheet.getCellRange(currentRow,5).setNumberValue(4);
sheet.getCellRange(currentRow,6).setNumberValue(5);//写入文本
currentRow += 2;
sheet.getCellRange(currentRow,1).setValue("公式:") ; ;
sheet.getCellRange(currentRow,2).setValue("结果:");//设置单元格格式
CellRange range = sheet.getCellRange(currentRow,1,currentRow,2);
range.getStyle().getFont().isBold(true);
range.getStyle().setKnownColor(ExcelColors.LightGreen1);
range.getStyle().setFillPattern(ExcelPatternType.Solid);
range.getStyle().getBorders().getByBordersLineType(BordersLineType.EdgeBottom).setLineStyle(LineStyleType.Medium);//算数运算
currentFormula = "=1/2+3*4";
sheet.getCellRange(++currentRow,1).setText(currentFormula);
sheet.getCellRange(currentRow,2).setFormula(currentFormula);//日期函数
currentFormula = "=TODAY()";
sheet.getCellRange(++currentRow,1).setText(currentFormula);
sheet.getCellRange(currentRow,2).setFormula(currentFormula);
sheet.getCellRange(currentRow,2).getStyle().setNumberFormat("YYYY/MM/DD");//时间函数
currentFormula = "=NOW()";
sheet.getCellRange(++currentRow,1).setText(currentFormula);
sheet.getCellRange(currentRow,2).setFormula(currentFormula);
sheet.getCellRange(currentRow,2).getStyle().setNumberFormat("H:MM AM/PM");//IF函数
currentFormula = "=IF(B1=5,"Yes","No")";
sheet.getCellRange(++currentRow,1).setText(currentFormula);
sheet.getCellRange(currentRow,2).setFormula(currentFormula);//PI函数
currentFormula = "=PI()";
sheet.getCellRange(++currentRow,1).setText(currentFormula);
sheet.getCellRange(currentRow,2).setFormula(currentFormula);//三角函数
currentFormula = "=SIN(PI()/6)";
sheet.getCellRange(++currentRow,1).setText(currentFormula);
sheet.getCellRange(currentRow,2).setFormula(currentFormula);//计数函数
currentFormula = "=Count(B1:F1)";
sheet.getCellRange(++currentRow,1).setText(currentFormula);
sheet.getCellRange(currentRow,2).setFormula(currentFormula);//最大值函数
currentFormula = "=MAX(B1:F1)";
sheet.getCellRange(++currentRow,1).setText(currentFormula);
sheet.getCellRange(currentRow,2).setFormula(currentFormula);//平均值函数
currentFormula = "=AVERAGE(B1:F1)";
sheet.getCellRange(++currentRow,1).setText(currentFormula);
sheet.getCellRange(currentRow,2).setFormula(currentFormula);//求和函数
currentFormula = "=SUM(B1:F1)";
sheet.getCellRange(++currentRow,1).setText(currentFormula);
sheet.getCellRange(currentRow,2).setFormula(currentFormula);//保存文档
wb.saveToFile("AddFormulas.xlsx",FileFormat.Version2013);
wb.dispose();
}
}
java excel添加公式_Java添加、读取Excel公式相关推荐
- java excel 中文乱码_java中读取excel文件中字符串乱码问题解决方法
以前的时候发现直接java读取一个excel文件输出里面的字符串会乱码,中文字符不会乱码,但是遇到英文的时候输出会乱码.这个问题太奇怪了. 我的表格名字为Shirley.xls. 我曾经直接读取exc ...
- java解析excel公式_Java 添加、读取Excel公式
Excel是办公室自动化中非常重要的一款软件,具有强大的数据分析和处理功能.其中,Excel公式(包括函数)起了非常重要的作用.因此,掌握处理公式的能力有利于提高对Excel的应用水平,进而提高工作效 ...
- java 读取excel模板_java如何读取excel表格的信息,java读取excel模板
java如何读取excel表格的信息Java如何读取excel表格的信息,用java读取excel表格信息的方法:1.pass [workbook.getworkbook(新文件(' e ://exc ...
- python excel 内容写入html,PYTHON读取EXCEL内容再转变成HTML添加到OUTLOOK中
需求 读取excel里的表格里的内容,然后打开本机的outlook.把excel里的内容添加到正文里,注意.这里是要添加到正文!正文!正文!而不是添加到附件里 设计思路 1.excel处理 打开exc ...
- java 分析excel模板_java如何读取Excel简单模板
场景:对于经常需要导入excel模板或数据来解析后加以应用的,使用频率非常之高,做了一个比较稳定的版本,体现在这些地方 工具:org.apache.poi 使用前必须了解这些: 1.要解析,那肯定先判 ...
- java读取excel数据的方法是_java怎么读取excel文件里的数据
展开全部 下面是一个简单的读取例子,如果报"java.io.IOException: Invalid header signature; read 4503608217567241, exp ...
- java excel导入前台_java上传excel表格并读取数据返回到前台
如果你对里面的代码不熟悉不知道的话,建议先浏览一遍代码再拿去用, 这里我介绍一下这个过程的思路: 1.定义变量那些就不说了 , 2.首先是上传文件并保存的代码 3.根据excel表的路径来读取文件,之 ...
- java poi excel 导入数据库_java POI 处理excel表格数据并导入数据库示例
java操作Excel最常用的开源组件有poi与jxl.jxl是韩国人开发的,发行较早,但是更新的很慢,目前似乎还不支持excel2007. poi是apache下的一个子项目,poi应该是处理ms的 ...
- java 动态导入excel_javaweb之动态读取 excel,导入excel
因为项目需求用到excel导入功能,技术有限花了很多时间终于弄出来了.借鉴了别人的方法,分享给有需要的人. 之前在搜索后看了很多人的方法,但是和我实际的需求不符合. 有什么问题或者改良 可以联系我qq ...
- easyexcel 检查表头是否匹配_Java EasyExcel读取Excel表头数据的方法及示例代码
1、读取表头数据代码/** * 读取表头数据 * * * 1. 创建excel对应的实体对象 参照{@link DemoData} * * 2. 由于默认异步读取excel,所以需要创建excel一行 ...
最新文章
- 机器学习算法推导的较好例子
- 华为云AIOps实践全面解析
- newInstance() 方法
- 通过JAVA对HDFS进行操作管理插件
- JavaScript自动生成博文目录导航/TOP按钮
- 2018 ICPC Asia Jakarta Regional Contest
- 在ADF实体PK属性中使用MySQL自动增量PK列
- VI操作--跳到最后一行和跳到最后一行的最后一个字符
- 【数据库系统】数据库体系结构
- HDOJ 1021-1025
- Python :h5py 如何对dataset进行重新赋值?
- Linux-v10-01天-授课
- python下的一个好用的日历库,支持农历和公历互转,是一个很好用的日期包
- Python中的类、实例以及方法,MRO继承解析顺序以及Mixin类
- 【我的区块链之路】- 谈一谈IPFS原理及玩法
- 剑指 Offer 52—— 两个链表的第一个公共节点
- [C#]Unicode与汉字互转
- .NET-房贷计算器
- qq音乐播放按钮设计测试方案和qq登陆测试
- Win7下制作Mac安装U盘,Windows下制作Mac启动盘
热门文章
- [ASP.NET MVC]让Html.RenderAction支持Lamda表达式
- 面向过程与面向对象 程序设计
- C++中的long long和__int64类型(转载)
- linux系统如何创建python文件_Linux搭建python环境详解
- 有个内含单词的超大文本文件_如果你家有个大阳台,你会选择封阳台吗?
- java lang jar_在运行时,Java jar返回java.lang.NoClassDefFoundError
- openwrt patch文件怎么用_openwrt 打补丁方式修改内核源码
- python一个函数调用另一个函数的返回值_python-调用另一个函数后立即从函数返回...
- 壁纸控、视觉控少不了高图网解决图片需求问题
- 极简潮流!最新海报欣赏给你设计灵感