当我运行下面的代码时,它会给我" java.lang.NullPointerException"错误。我是Selenium数据驱动测试的新手,想在excel表的副本中写出我的通过/失败结果。请帮助我并指导我创建Excel工作表副本并在该副本表中写入。 目前它正在创建excel表的副本但是当" wshTemp.addCell(labTemp);"得到执行它给出上述错误。提前谢谢你。
import java.io.File;
import jxl.Workbook;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.Label;
import jxl.write.WriteException;
public class dataSheet {
static Workbook wbook;
static WritableWorkbook wwbCopy;
static String ExecutedTestCasesSheet;
static WritableSheet shSheet;
public void readExcel()
{
try{
wbook = Workbook.getWorkbook(new File("path\\testSampleData.xls"));
wwbCopy = Workbook.createWorkbook(new File("path\\testSampleDataCopy.xls"), wbook);
shSheet = wwbCopy.getSheet(0);
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void setValueIntoCell(String strSheetName,int iColumnNumber, int iRowNumber,String strData) throws WriteException
{
WritableSheet wshTemp = wwbCopy.getSheet(strSheetName);
Label labTemp = new Label(iColumnNumber, iRowNumber, strData);
try {
wshTemp.addCell(labTemp);
}
catch (Exception e)
{
e.printStackTrace();
}
}
public void closeFile()
{
try {
// Closing the writable work book
wwbCopy.write();
wwbCopy.close();
// Closing the original work book
wbook.close();
} catch (Exception e)
{
e.printStackTrace();
}
}
public static void main(String[] args) throws WriteException
{
dataSheet ds = new dataSheet();
ds.readExcel();
ds.setValueIntoCell("sheet1", 5, 1, "PASS");
ds.setValueIntoCell("sheet1", 5, 2, "FAIL");
ds.setValueIntoCell("sheet1", 5, 3, "PASS");
ds.closeFile();
}
}