on 06-25-2012 7:36 PM
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.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
you can use apache poi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
89 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.