2014-11-13 20 views
0

的Apache POI保存錯誤消息我有我讀的測試參數Excel文件。 我想保存在同一個Excel文件中測試期間顯示的錯誤消息。我在Excel中創建了名爲「status」的列。我的一個錯誤消息的代碼示例 :硒在Excel

if((Konfiguration.get("some excel parametr").equalsIgnoreCase("metro"))) { 
    throw new RuntimeException("My error messages"); 
} 

我如何保存在列Excel文件,該錯誤信息名爲「狀態」

回答

0

寫入到您的Excel文件中的特定列。

  1. 獲取列和行,你需要寫
  2. 寫入數據所獲得的列。

如果你的行值是2並且列是5,那麼使用apache poi打開你的excel並遍歷你的特定單元格並寫下你的消息。

 FileInputStream file = new FileInputStream(new File(File_path)); 

     HSSFWorkbook yourworkbook = new HSSFWorkbook(file); 

     HSSFSheet sheet1 = yourworkbook.getSheetAt(0); 

     Row row = sheet1.getRow(2); 
     Cell column = row.getCell(5); 
     column.setCellValue(your_error_message); 

您還可以使用指針來跟蹤上次寫入時寫入的列。