Free Spire.XLS for Java (免费版)
IntelliJ IDEA
通过e-iceblue官网下载包,并解压将lib文件夹下的jar文件导入java程序;或者通过maven仓库下载导入,maven仓库配置路径和依赖可参考https://www.e-iceblue.cn/licensing/install-spirepdf-for-java-from-maven-repository.htmljar文件导入效果如下:
import com.spire.xls.*; import java.awt.*; public class FindAndReplaceData { public static void main(String[] args) { //加载文档 Workbook wb= new Workbook(); wb.loadFromFile('test.xlsx'); //获取第一个工作表 Worksheet worksheet = wb.getWorksheets().get(0); //查找指定数据 CellRange[] ranges = worksheet.findAllString('测试', true, true); //创建单元格样式 CellStyle style = wb.getStyles().addStyle('Style'); style.getFont().setSize(12f); style.getFont().setColor(new Color(30,144,255)); style.getFont().isBold(true); style.setHorizontalAlignment(HorizontalAlignType.Center); //遍历单元格,替换数据 for (CellRange range : ranges) { //替换为新的数据 range.setText('Test'); //应用样式 range.setStyle(style); } //保存文档 wb.saveToFile('ReplaceData.xlsx', ExcelVersion.Version2010); wb.dispose(); } }
数据查找替换结果: