0

Ok - so I realized that after writing some code and figuring out stuff, that jxl does not support xlsx, only POI (XSSF). Ok fine. What I am trying to do is search for a cell with a string value "Result" in a specified column. Once I find that, then as a test passes or fails, it writes "Pass" or "Fail" in the cell that is blank. And it will continue to do that until the test set has finished. Here is the code I wrote using jxl.

WritableWorkbook wb = Workbook.createWorkbook(new File(testData), workbook);
        WritableSheet ws = wb.getSheet("OrderCreateQA3");
        int colCount = ws.getColumns();
        for(int j=0; j<colCount; j++){
            Cell cell = ws.getCell(j,0);
            if(cell.getContents().contains("Result")){
                Cell[] cells = ws.getColumn(j);
                int len = cells.length;
                Label label = new Label(j,len, "Fail", getCellFormat(Colour.RED));
                ws.addCell(label);
                break;
            }
        }

        wb.write();
        wb.close();

The above was pretty straightforward, I find the string, then get that column name and write pass or fail given the length. Any ideas on how to do it using POI?

1

1 Answer 1

1

That's pretty straightforward, too. Simply replace jxl classes/methods with their POI counterparts:

POI has an XSSFWorkbook with an XSSFWorkbook(java.io.File file) constructor and an XSSFSheet getSheet(java.lang.String name) method.

XSSFSheet has an XSSFRow getRow(int rownum) method (loop until getLastRowNum() for instance).

XSSFRow has an XSSFCell getCell(int cellnum, ...) method.

XSSFCell has appropriate getters/setters.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes I was able to replace using XSSF(Workbook & Sheet) easily. Seems it will be an extra step or two since POI does not have a method to grab the cell length of a column.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.