【发布时间】:2015-04-23 16:52:38
【问题描述】:
我想编写 excel 表并为此编写代码,但是当我的程序在对象 WritableSheet 中执行时,它会收到以下警告。 我可以知道我哪里出错了吗??另外,我正在使用键驱动框架来编写工作表。
Warning: Sheet name D:\eclipse-jee-kepler-SR1-win32\Workspace\AutomationFramework\configuration\GmailTestSuite.xls too long - truncating
Warning: : is not a valid character within a sheet name - replacing
Warning: \ is not a valid character within a sheet name - replacing
我用来写表格的代码:
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(testSuitePath, 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);
} 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();
}
}
}
【问题讨论】:
标签: java excel selenium-webdriver frameworks jxl