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個單元格)內。 –