添加依赖
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-base</artifactId>
<version>4.0.0</version>
</dependency>
示例:
public class ExcelTest {
//实现功能将当前目录下test.xlsx表中包含"$"符号的单元格内容替换成"hello"
public static void main(String[] args) {
try{
String value= "hello";
String fileName = "test.xlsx";
String fileOutName = "test_out.xlsx";
XSSFWorkbook xwb = new XSSFWorkbook(new FileInputStream(fileName));
XSSFSheet xSheet = xwb.getSheetAt(0);
for (int i = 0; i <= xSheet.getLastRowNum(); i++) {
if(xSheet.getRow(i) == null) {
continue;
}
for(int j = 0; j <= xSheet.getRow(i).getPhysicalNumberOfCells(); j++) {
if (xSheet.getRow(i).getCell(j) == null) {
continue;
}
XSSFCell xCell = xSheet.getRow(i).getCell(j);
System.out.println(xCell.toString());
if (xCell.toString().contains("$")) {
xCell.setCellValue(value);
}
}
}
FileOutputStream out = new FileOutputStream(fileOutName);
xwb.write(out);
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
1万+



被折叠的 条评论
为什么被折叠?



