3

I have the following code to read from a test file and print it on console but it's not printing any thing, I don't know how to chech the error its generating. I am using java, selenium, ie 10, win 8.

public class Rowcount {
    public static void main(String[] args) throws BiffException, IOException {
        FileInputStream exo=new FileInputStream("E:\\Test filee.xlsx");
        Workbook wbo=Workbook.getWorkbook(exo);
        Sheet wso=wbo.getSheet(0);
        int lastrownum;
        lastrownum= wso.getRows();
        System.out.println(lastrownum);
    }
}
3
  • ""E:\\Test filee.xlsx"" quotes twice... Is it compiling??. Are you getting any exception?? Commented Dec 13, 2013 at 13:45
  • Sure that is correct? ""E:\\Test filee.xlsx"" Commented Dec 13, 2013 at 13:46
  • sorry, i edited this one in code before compiling. Commented Dec 16, 2013 at 5:09

3 Answers 3

1

Are you using JExcelApi? If so, I don't think it supports Excel 2007 and above. You might consider looking into Apache POI.

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

Comments

1

jxl didnt work for xlsx. try to implement using apache poi instead

and this code is misquoted

FileInputStream exo=new FileInputStream(""E:\\Test filee.xlsx"");

you would need to remove the extra quote

Comments

0

the following code worked for me:

import java.io.File;
import java.io.IOException;

import jxl.Cell;
import jxl.CellType;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

public class ReadExcell {
public static void main(String[] args) {
ReadExcell.ExcelFile("D:\\rptViewer.xls");
}

/*
* Read excel file using j excel file
*/
public static String ExcelFile(String path){
StringBuilder excelContent = new StringBuilder();

try
{
Workbook workbook = Workbook.getWorkbook(new File(path));
Sheet sheet = workbook.getSheet(0);

excelContent = new StringBuffer();

for(int rows = 0 ; rows < sheet.getRows() ; rows++){
StringBuffer row = new StringBuffer();
for(int colums = 0 ; colums < sheet.getColumns() ;colums++){
  Cell cell = sheet.getCell(colums, rows);
if(cell.getType() == CellType.LABEL){
row.append(cell.getContents()+ ",");
}else
if(cell.getType() == CellType.NUMBER){
row.append(cell.getContents()+ ",");
}
}

excelContent.append(row.toString());
System.out.println(row.toString());
}

} catch (BiffException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}    

return excelContent.toString();
}
}    

Comments

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.