1)我试图从appliation的网表读出的值,并将其写入到excel表逐个写入由每行中的一个。撷取值和excel工作表一个在一个循环中
2)有需要被写入到Excel表单的网表的每一行中的4个值,但也有我使用以下代码忽略BU每行中的一些图像。
text.length()>2
3)在webtable中会有200-300行需要被提取并写入excel表单。
这是我试过的代码。但我不知道如何将它写入Excel表格的每一行。在这方面请帮助我。
//get the table
\t \t WebElement statusTable = browser.findElement(By.id("projectstatus"));
\t \t
\t \t //Get all the rows in the table
\t \t List<WebElement> allRows = statusTable.findElements(By.tagName("tr"));
\t \t
\t \t //Get the size(row no) of allRows
\t \t int rowSize = allRows.size();
\t \t System.out.println(rowSize);
\t
\t \t
\t \t for (WebElement row : allRows) {
\t \t \t
\t \t \t //Get all cell values in each row
\t \t \t List<WebElement> allCells = row.findElements(By.tagName("td"));
\t \t \t //System.out.println(allCells.size());
\t \t \t
\t \t \t if(allCells.size() > 1){
\t \t \t \t for (WebElement cell : allCells) {
\t \t \t \t \t
\t \t \t \t \t
\t \t \t \t \t String text = cell.getText();
\t \t \t \t \t if(text.length()>2){
\t \t \t \t \t \t
\t \t \t \t String value = cell.getText();
\t \t \t \t \t \t
\t \t \t \t \t } \t \t \t \t \t
\t \t \t \t }
\t \t \t }
\t \t \t
// locate the test xl file \t \t \t \t
File file = new File("e:\\Testing_emi.xls"); \t \t \t \t
// create input stream \t \t \t \t
FileInputStream fis = new FileInputStream(file); \t \t \t \t
// create workbook \t \t \t \t
HSSFWorkbook wb = new HSSFWorkbook(fis); \t \t \t \t
// get sheet \t \t \t \t
HSSFSheet sheet1 = wb.getSheet("Sheet1"); \t \t \t \t
// get rows \t \t \t \t
\t \t \t
HSSFRow row = sheet1.getRow(1); \t \t \t \t
\t \t \t \t \t
HSSFCell cellEx = row.getCell(0); \t \t \t \t
if (cellEx == null) { \t \t \t \t
cellEx = row.createCell(0); \t \t \t \t
} \t \t \t \t
cellEx.setCellValue(value);
首先,所有的代码,你正试图将值写入电子表格应该是你的for循环中。 –
你可以在将excel写入代码移到循环内部之后再进一步解释下一步应该做什么。因为有四(4)个值必须写入Excel工作表的每行(4个单元格)内。 –