Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2011
    Posts
    52
    Rep Power
    0

    Default How to find empty string from a cell.

    Hi All,

    I am using Excel file as input and i am trying to find if there is any space " " in the cell if it is blank cell.

    My requirement is if there is any cell which contains " " or null it should be highlighted.

  2. #2
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,008
    Rep Power
    20

    Default Re: How to find empty string from a cell.

    What do you mean by "highlighted"?
    Are these specific cells?
    If not, how do you determine which cells to check?
    What excel package are you using?
    JExcel, POI, something else?

  3. #3
    Join Date
    Mar 2011
    Posts
    52
    Rep Power
    0

    Default Re: How to find empty string from a cell.

    Thanks for reply,

    I am using Aspose.java.cells API.
    Java Code:
    Workbook workbook = new Workbook();
     workbook.open(filename);
    Worksheet worksheet = workbook.getWorksheets().getSheet(sheetno);
    Cells cells=worksheet.getCells();
    int num=cells.getMaxDataRow();
    for (int n1=0;n1<=num;n1++)
      {  Cell cell1=cells.getCell(n1,Colno);
         if(cell1.getValue()==null ||cell1.getValue().toString().length()==0)
          {Cell cell=cells.getCell(n1,Colno);
            Style style = cells.getCell( n1,Colno).getStyle();
            style.setColor(Color.TEAL);
            cell.setStyle(style);
    	  }
      }

  4. #4
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,008
    Rep Power
    20

    Default Re: How to find empty string from a cell.

    Unless Aspose works differently to other excel tools then it's possible this:
    Java Code:
    Cell cell1=cells.getCell(n1,Colno);
    could return null, as Excel does not necessarily store a cell for empty cells. So worth bearing in mind.

    After handling that, you could try trim()ing your toString() and then doing isEmpty() (rather than length() == 0)? It's a bit neater. That should cover space-only cells as well as empty ones.

Similar Threads

  1. find first empty cell?
    By truant420 in forum New To Java
    Replies: 5
    Last Post: 03-15-2011, 01:13 PM
  2. getting rid of empty space at the end of a string
    By BoomPony in forum New To Java
    Replies: 3
    Last Post: 02-14-2011, 09:40 PM
  3. Replies: 1
    Last Post: 11-04-2010, 06:53 PM
  4. How to find out if part of an array is empty
    By counterfox in forum New To Java
    Replies: 2
    Last Post: 10-13-2010, 06:09 PM
  5. JXL Empty cell problem
    By ironicending in forum New To Java
    Replies: 1
    Last Post: 01-26-2009, 03:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •