本文主要是介绍java poi该表excel单元格内容,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
添加依赖
<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();}}
}
这篇关于java poi该表excel单元格内容的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!