Hi ,
 I wrote the below code but doesnot read the BlankCell(empty cell).Please
give me reply.


 <%@ page import="java.sql.*" %>
 <%@ page import="java.io.*" %>
 <%@ page import="java.util.*" %>

<%@ page language="java" %>
 <%@ page import="java.text.SimpleDateFormat"%>
 <%@ page import="org.apache.poi.ss.usermodel.Workbook"%>
 <%@ page import="org.apache.poi.ss.usermodel.DateUtil"%>
  <%@ page import="org.apache.poi.ss.usermodel.Sheet"%>
  <%@ page import="org.apache.poi.ss.usermodel.Cell"%>
<%@ page import="org.apache.poi.ss.usermodel.Row"%>
<%@ page import="java.util.Iterator"%>
<%@ page import ="org.apache.poi.ss.usermodel.WorkbookFactory"%>
<%@ page
import="org.apache.poi.openxml4j.exceptions.InvalidFormatException"%>
<%@page language="java" session="true" %>

       <%!

       String cellValue="";

       %>
                 <% String file="d:/seenu1/TestEx2.xlsx";
                      FileInputStream fis = new FileInputStream(file);

                  Workbook workbook = WorkbookFactory.create(fis);
                  Sheet sheet = workbook.getSheetAt(0);
                  Iterator rows = sheet.rowIterator();
                  int number=sheet.getLastRowNum();

                  System.out.println(" number of rows"+ number);
                  int j=0;
                  int n=1;

                  while (rows.hasNext())
                   {
                     Row row = ((Row) rows.next());
                     Iterator cells = row.cellIterator();
                     while(cells.hasNext())
                      {
                         Cell cell = (Cell) cells.next();
                         switch (cell.getCellType()) {

                         case Cell.CELL_TYPE_STRING:
                         cellValue = cell.getStringCellValue();
                         System.out.print(cellValue+"\t");
                         break;

                         case Cell.CELL_TYPE_FORMULA:
                         cellValue = cell.getCellFormula();
                         System.out.print(cellValue+"\t");
                         break;

                        case Cell.CELL_TYPE_NUMERIC:
                        if (DateUtil.isCellDateFormatted(cell)) {
                                SimpleDateFormat dateFormat = new
SimpleDateFormat(
                                        "dd/MM/yyyy");
                                cellValue =
dateFormat.format(cell.getDateCellValue());
                                System.out.print(cellValue+"\t");
                            } else {
                           System.out.print(cell.getNumericCellValue()+"\t");
                            }
                        break;

                         case Cell.CELL_TYPE_BLANK:
                         cellValue = "hi";
                         System.out.print(cellValue+"\t");
                         break;

                         case Cell.CELL_TYPE_BOOLEAN:
                         cellValue =
Boolean.toString(cell.getBooleanCellValue());
                         System.out.print(cellValue+"\t");

                       }
                    j++;
                      }
                   System.out.println();

                  } n++;
                %>

thanks in advance.........................

Reply via email to