2016-11-25 182 views
0

我想在執行我的selenium腳本之前使用java清除Excel表格(.xlsx文件)中3列的內容。我正在使用XSSFWorkbook(Apache poi)讀取和寫入excel表格的數據。excel表格中有5列。我想清除3列內容,剩下的列內容應該像以前一樣。如何使用java清除excel表格中的列的內容

請幫助我如何實現這一目標?

回答

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(); 
+0

感謝@ Kishan..I認爲這將需要更多的時間,如果我將清除3列數百data.Because的在我的情況1column有200+ data.Is有任何內置methos在POI到? –

+0

OOXML格式將內容存儲在行中,因此對列的任何操作往往都很昂貴,因爲您必須迭代所有行。內置的方法不會更有效率。同時決定是否要將文本設置爲空字符串,或者您想要完全刪除單元格。 – IceArdor

相關問題