dimanche 1 mars 2015

How to overwrite in my previous excel file using JXL?

I want to set the status of executing test but whenever I execute the code it create new workbook by using this line:



wwbCopy = Workbook.createWorkbook(new File(testSuitePath));


Now can anyone please let me know how I can set the status of executing test case.


For this I am using JXL lib. and in keydriven framework.


Below are the code of write in excel:



public class WritableData {

Workbook wbook;
WritableWorkbook wwbCopy;
String ExecutedTestCasesSheet;
WritableSheet shSheet;

public WritableData(String testSuitePath, String string) {
// TODO Auto-generated constructor stub

try {
wbook = Workbook.getWorkbook(new File(testSuitePath));
wwbCopy = Workbook.createWorkbook(new File(testSuitePath));
// shSheet=wwbCopy.getSheet(1);
shSheet = wwbCopy.createSheet("Login", 1);
} catch (Exception e) {
// TODO: handle exception
System.out.println("Exception message" + e.getMessage());
e.printStackTrace();
}
}

public void shSheet(String strSheetName, int iColumnNumber, int iRowNumber,
String strData) throws WriteException {
// TODO Auto-generated method stub

WritableSheet wshTemp = wwbCopy.getSheet(strSheetName);
WritableFont cellFont = null;
WritableCellFormat cellFormat = null;

if (strData.equalsIgnoreCase("PASS")) {
cellFont = new WritableFont(WritableFont.TIMES, 12);
cellFont.setColour(Colour.GREEN);
cellFont.setBoldStyle(WritableFont.BOLD);

cellFormat = new WritableCellFormat(cellFont);
cellFormat.setBorder(Border.ALL, BorderLineStyle.THIN);
}

else if (strData.equalsIgnoreCase("FAIL")) {
cellFont = new WritableFont(WritableFont.TIMES, 12);
cellFont.setColour(Colour.RED);
cellFont.setBoldStyle(WritableFont.BOLD);

cellFormat = new WritableCellFormat(cellFont);
cellFormat.setBorder(Border.ALL, BorderLineStyle.THIN);
}

else {
cellFont = new WritableFont(WritableFont.TIMES, 12);
cellFont.setColour(Colour.BLACK);

cellFormat = new WritableCellFormat(cellFont);
cellFormat.setBorder(Border.ALL, BorderLineStyle.THIN);
cellFormat.setWrap(true);
}

Label labTemp = new Label(iColumnNumber, iRowNumber, strData,
cellFormat);
try {
wshTemp.addCell(labTemp);
System.out.println("writableSheet---->" +wshTemp);
} catch (Exception e) {
e.printStackTrace();
}

}

public void closeFile() {
try {
// write the value in work book
wwbCopy.write();
// wwbCopy.close();

// Closing the original work book
wbook.close();
} catch (Exception e) {
e.printStackTrace();

}
}

}

Aucun commentaire:

Enregistrer un commentaire