Skip to Content
avatar image
Former Member

Read Excel (both xls and xlsx) cell in wdJava

Hi All,

Our requirement is to read a few cells from an input excel file into wd java application. The input file can be either xls or xlsx format.

I can read cells from xls files using jxl.jar, but i would like to know how to read cells from xlsx files.

Also it would be helpful if you can suggest a method that works for both types of files.

Thnaks in advance,

Sattam.

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

2 Answers

  • Jun 25, 2012 at 07:09 PM

    you can use apache poi

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jun 26, 2012 at 01:39 PM

    Hi Sattam,

    Please add the below jar files and use below code.

    1. dom4j-1.6.1

    2. poi-3.7-20101029

    3. poi-ooxml-3.7-20101029

    4. poi-ooxml-schemas-3.7-20101029

    5. xmlbeans-2.3.0

    if(fileName != null && fileName.endsWith(".xls")) {

    // 97 to 2003 format use HSSF class

    HSSFWorkbook wb = new HSSFWorkbook(templateInputStream);

    HSSFSheet sheet = wb.getSheetAt(0); // get first sheet

    iRowNum = sheet.getPhysicalNumberOfRows();

    HSSFRow row = null;

    HSSFCell cell = null;

    for(int i = 1;i <iRowNum ; i++) {

    //your code to access the 2003 excel file.

    } else{

    // 2007 or 2010 format

    XSSFWorkbook wb = (XSSFWorkbook) WorkbookFactory.create(templateInputStream);

    XSSFSheet sheet = wb.getSheetAt(0);

    iRowNum = sheet.getPhysicalNumberOfRows();

    XSSFRow row = null;

    XSSFCell cell = null;

    for(int i = 1;i <iRowNum ; i++) {

    //code to access the 2007 or 2010 excel file

    }

    }

    With Regards,

    Ramesh G.

    Add comment
    10|10000 characters needed characters exceeded