cancel
Showing results for 
Search instead for 
Did you mean: 

Read Excel (both xls and xlsx) cell in wdJava

Former Member
0 Kudos

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.

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

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.

junwu
Active Contributor
0 Kudos

you can use apache poi