使用apace POI操作excel

  1. pom依赖

    <dependency>
    	<groupId>org.apache.poi</groupId>
    		<artifactId>poi</artifactId>
    	<version>3.8</version>
    </dependency>
    
  2. 部分java 代码

    //部分代码
    FileSystemView fsv = FileSystemView.getFileSystemView();
    String desktop = fsv.getHomeDirectory().getPath();
    String filePath = desktop + "/在线申报地址.xls";
    FileInputStream fileInputStream = new FileInputStream(filePath);
    BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream);
    POIFSFileSystem fileSystem = new POIFSFileSystem(bufferedInputStream);
    HSSFWorkbook workbook = new HSSFWorkbook(fileSystem);
    HSSFSheet sheet = workbook.getSheet("法人");
    int lastRowIndex = sheet.getLastRowNum();
    for (int i=0; i<lastRowIndex; i++){
    HSSFRow row = sheet.getRow(i);
    if (row == null) { break; }
    String cellValue = row.getCell(0).getStringCellValue();
    System.out.println(cellValue);
    String afterBase64Url = Base64Util.urltoBase64(prefix2+Base64Util.toBase64(cellValue));
    System.out.println(afterBase64Url);
    row.createCell(3);
    row.getCell(3).setCellValue(preFix+afterBase64Url);
    FileOutputStream fileOutputStream = new FileOutputStream(filePath);
    workbook.write(fileOutputStream);
    fileOutputStream.flush();
    fileOutputStream.close();
    }
    fileInputStream.close();
    bufferedInputStream.close();