如何使用java清除excel表中列的内容

时间:2016-11-25 04:59:58

标签: java apache-poi

我想在执行我的selenium脚本之前使用java清除excel表(.xlsx文件)中3列的内容。我正在使用XSSFWorkbook(Apache poi)读取和写入数据到Excel工作表。在excel工作表中有5列。我想清除3列内容,剩下的列内容应该像以前一样。

请帮助我如何实现这一目标?

1 个答案:

答案 0 :(得分:0)

FileInputStream objFileInputStream = new FileInputStream(new File(
                    Xlsx_File_path.xlsx));
XSSFWorkbook objWorkbook = new XSSFWorkbook(objFileInputStream);
XSSFSheet objSheet = objWorkbook.getSheetAt(0);
Cell cell = null;
int row=[start of row]
int cell=[your cell]


//iterate the below code as you want
//code
  cell = objSheet.getRow(rows).getCell(cell);
  cell.setCellValue("")
//code

objFileInputStream.close();
FileOutputStream output_file = new FileOutputStream(new File(
                    finalXlsx.xlsx));
    objWorkbook.write(output_file);
            output_file.close();