I have a requirement to take the test data from Excel sheet and write test result as Pass/Fail in another Excel sheet.
I am using SeleniumRC+Java+Eclipse+Junit.
How can i change font color of text while writing to Excel sheet using Java.
I am doing with the help of Label, WorkBook, WrittableWorkbook, WrittableSheet, Sheet.
Here is my sample code..
import jxl.Sheet;
import jxl.Workbook;
import jxl.WorkbookSettings;
import jxl.read.biff.BiffException;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
public class FinalTestSuite extends TestCase
{
public static File file = new File("C:/Selenium/selenium-remote-control-1.0.3/TestingResult.xls");
public static File sourceFile = new File("C:/Selenium/selenium-remote-control-1.0.3/Portland.xls");
public static WorkbookSettings ws;
public static WritableWorkbook workbook;
public static WritableSheet wSheet1, wSheet2;
public static Sheet sh1, sh2;
public static Sheet sheetFinal;
public static Workbook sourceWorkbook;
public static Label label;
}
public void getTestResult(String passOrfail) throws IOException,BiffException, WriteException
{
try
{
FinalTestSuite.file = new File("C:/Selenium/selenium-remote-control-1.0.3/TestingResult.xls");
FinalTestSuite.sourceFile = new File("C:/Selenium/selenium-remote-control-1.0.3/TestDetails.xls");
FinalTestSuite.ws = new WorkbookSettings();
FinalTestSuite.workbook = Workbook.createWorkbook(FinalTestSuite.file, FinalTestSuite.ws);
FinalTestSuite.sourceWorkbook=Workbook.getWorkbook(FinalTestSuite.sourceFile);
FinalTestSuite.sh1 = FinalTestSuite.sourceWorkbook.getSheet(0);
FinalTestSuite.sh2= FinalTestSuite.sourceWorkbook.getSheet(1);
FinalTestSuite.wSheet1 = FinalTestSuite.workbook.importSheet("Begin", 0 , FinalTestSuite.sh1);
FinalTestSuite.wSheet2 = FinalTestSuite.workbook.importSheet("Reports", 0 , FinalTestSuite.sh2);
colCount = FinalTestSuite.wSheet2.getColumns();
rowCount = FinalTestSuite.wSheet2.getRows();
for(col=1;col<=colCount;col++)
{
for(row = 1;row<=rowCount;row++)
{
jxl.Cell dataCell = FinalTestSuite.wSheet2.getCell(col, 0);
if(clientName.equals(client))
{
FinalTestSuite.label = new Label(col, row, passOrfail);
FinalTestSuite.wSheet2.addCell(FinalTestSuite.label);
break;
}
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
Please anybody tell me how can i modify it to get Test result with font color as red and green…
Make use of
WritableFont.setColour(Colour colour)when formatting the cell you’re writing to. See this tutorial for the basics. The API should be sufficient to know how to add a colour to the formatting examples available.