POI cellIterator ignores empty cells.  How to catch?

For the experienced:

I have never dealt with Microsoft Excel files using java and have just started using the POI library to read data from Excel files. In the .xls file I get, there are cells that are found to be empty, although they aren't supposed to. So I have to catch these empty cells and treat them accordingly.

To learn how to catch these empty cells, I created a spreadsheet of Excel a line test and wrote the following class to try to catch empty cells.

The one line in the sheet has 5 columns as shown below. I entered < tt > ' 0934 < /tt > in column D with an apostrophe leader to make sure that it is stored as text.
A     B        C      D     E
----  -------  -----  ----  ---------
John  (BLANK)  123.4  0923  4/21/2011
And here is the test class to examine these cells. Sorry that it is quick and dirty for the test and I don't use a try/catch and I simply leave the date column be printed as a number:
public class ExcelTest {
    public static void main(String[] args) throws IOException {
        // The one-row test file:
        String inputFilename = "c:\\test_data\\test_sheet.xls";
        FileInputStream fis = new FileInputStream(inputFilename);

        HSSFWorkbook workbook = new HSSFWorkbook(fis);
        HSSFSheet worksheet = workbook.getSheetAt(0);

        // Get the one row
        HSSFRow theRow = worksheet.getRow(0);
        // and create an iterator
        Iterator cells = theRow.cellIterator();

        int columnNo = 0;
        
        // Go through the cells in the row:
        while (cells.hasNext()) {
            // Get the next cell:
            HSSFCell cell = (HSSFCell)cells.next();
            
            int cellType = cell.getCellType();
            String cellTypeDesc = null;
            String cellValue = null;
            
            switch (cellType) {
            case 0:
                cellTypeDesc = "NUMERIC";
                Double doubleValue = cell.getNumericCellValue();
                cellValue = doubleValue.toString();
                break;
            case 1:
                cellTypeDesc = "STRING";
                cellValue = cell.getStringCellValue();
                break;
            case 2:
                cellTypeDesc = "FORMULA";
                cellValue = cell.getCellFormula();
                break;
            case 3:
                cellTypeDesc = "BLANK";
                cellValue = "BLANK";
                break;
            case 4:
                cellTypeDesc = "BOOLEAN";
                boolean booleanValue = cell.getBooleanCellValue();
                cellValue = ""+booleanValue;
                break;
            case 5:
                cellTypeDesc = "ERROR";
                byte byteValue = cell.getErrorCellValue();
                cellValue = ""+byteValue;
                break;
            }
            System.out.println("Column " + ++columnNo + " has value " + cellValue + " of type " + cellTypeDesc);
        }
    }
}
I expect that the class could give me some clues on the empty cell. But it turns out that the program returned only 4 columns, and the empty cell is omitted altogether as there were not any. That's what the program returned:
Column 1 has value John of type STRING
Column 2 has value 123.4 of type NUMERIC
Column 3 has value 0923 of type STRING
Column 4 has value 40654.0 of type NUMERIC
Is it possible to catch empty cells?

Thank you very much for help!


Newman

Looking through the javadocs POI, because cellIterator() does not return empty cells, you can use the getCellNum() method to determine the position of the cell in the row. You should be able to use it to determine when a cell is ignored because being blank.

Tags: Java

Similar Questions

  • How to add the first non-empty cell (text) in a row

    I have a table of several lines of contact details (phone, cell phone, fax and email) of people. I'm using these data to a data merge using an exported csv file and must include only the text (phone numbers and/or email) that is not empty.

    Column A - phone

    Column B - cell phone

    Column C - Fax

    Column D - Email

    Column E - first non-empty cell (between A1:D:1, A2:D:2, A3:D3, etc.)

    Column F - second non-empty cell (between A1:D:1, A2:D:2, A3:D3, etc.)

    Column G - third non-empty cell (between A1:D:1, A2:D:2, A3:D3, etc.)

    I tried to use some varieties of INDEX MATCH, but I don't do it just because its does not work properly.

    Any help would be appreciated. Thank you!

    You can try something like this:

    E2 = IF (ISBLANK (A2), "", MAX($D2:D2) + 1).

    This is a shortcut for, select cell E2, and type (or copy and paste it here) the formula:

    = IF (ISBLANK (A2), "", MAX($D2:D2) + 1).

    Select cell E2, copy

    Select cells E2 through H2, dough

    I2 = SIERREUR (OFFSET ($A2, 0, IFERROR (MATCH (COLUMN (−8), $E2: $H2, 0), ' ') −1), ' ')

    Select the cell I2, copy

    Select cells I2 thru K2, dough

    Select cells E2 K2 thru copy

    Select cells E2 at the end of the K column, paste

    You can hide the columns e to H what you like

  • Find the first empty cell

    OK so I use numbers to design a "schedule" for lack of a better word for a flight instructor course. On the summary page, I need to be able to identify the next sequence of flight for each student. I have a sheet that contains all flights that each student must perform and the date which they filled. So what I need on the summary page is someway to watch flight logs and determine what the next flight is to find the first empty cell under each name of students. I have no idea how to go about that though, so if you have any ideas I would be grateful

    Hello j,

    Here are two possibilities, both illustrate below. They are independent of each other and can be used alone or together.

    If students all sequences in chronological order, and the dates in columns are values of Date and real time, you should be able to locate the first empty line using MATCH and MAX.

    Because all dates entered will be 'today' or 'before today', a conditional highlighting rule could be used to color the background of the cell to a cell where a date has been entered.

    Table 1 gives the master record. Table 2 shows the following sequence for the student and the line of table 1, which the sequence is listed.

    Two formulas are used:

    Table 2::B3 and filled with right: = MATCH (MAX (table 1: B), Table 1: B, 0) + 1

    Table 2::B2 and filled with right: = OFFSET (table 1: $A$ 1, B3-1, 0)

    This method is based on the sequences being completed in the order listed, as it seems the most recent (that is to say date the "bigger").

    The rule of conditional formatting applied to all cells in columns B, C and D of table 1 fills every cell that contains a date before the next day with yellow, giving a visual indication of where all the next vacant cell.

    This indicator is independent of the order of the sequences, because it depends on only that there is a date or before 'today' in each cell to be highlighted.

    Kind regards

    Barry

  • the search for empty cells by using the query designer

    Hello

    I'm trying to exclude empty cells in a field (by using the Query Builder), and I did:

    xDocumentSource < match > "CDL".

    < AND >

    < NOT > (xRelatedMsgid < match > "" "")

    but it does not work. I tried "NULL", but it does not work either. Could someone tell me how to do it (or where I can find examples of queries).

    Kind regards

    Iwona

    https://blogs.Oracle.com/Kyle/entry/searching_for_null_values_ucm

  • I accidentally put my pictures folder in the bin and emptied. How to make a comeback?

    II accidentally put my pictures folder in the bin and emptied!  How to make a comeback?

    If they are not in your Recycle Bin, restore it from your backup.

    If you do not have backups, then you will need to use the specialist recovery software (search the Web) yourself or get a professional company to do it for you at great expense. The most important thing to remember here is that after you have deleted your files, they still exist, but are considered as a free space on your hard drive and can so be replaced by your PC at any time - use your PC only so much it is necessary to recover the files. The more you use your PC more the chances of your files become corrupted and unrecoverable.

    Some people recommend

    http://www.Piriform.com/Recuva

    recovery software. However, I have not used, so I can't personally recommend.

    For later use, if anything either on your PC is valuable or irreplaceable, you must save it to a separate drive. Hard drives are mechanical devices with very fast moving parts that can fail without warning at any time. There are many other ways to lose too much data.

  • When I open the control panel and select system maintenance folder is empty. How to restore this file?

    Original title: maintenance missing system file

    When I open the control panel and select system maintenance folder is empty. How to restore this file? My support is also empty.

    Hello

    1. Were changes made to the software or hardware of the computer before the show?
    2. What backup you are referring to?

    Method 1:
    Visit the link below and run the Fixit.
    Difficulty of broken desktop shortcuts and common system maintenance tasks
     
    Method 2:
    Do a system restore and check. System restore allows you to use the computer from the date when it was working fine. Visit the link below.
    System Restore: frequently asked questions
    http://Windows.Microsoft.com/en-us/Windows-Vista/system-restore-frequently-asked-questions
     
    Method 3:
    Run the System File Checker, visit the link below and follow the steps.
    How to use the System File Checker tool to fix the system files missing or corrupted on Windows Vista or Windows 7
     
    After running the System File Checker visit the below mentioned link to analyze the logs.
    How to analyze the entries in the log file generating the program Checker (SFC.exe) resources of Microsoft Windows in Windows Vista

     
  • BBM how to retrieve BBM be hacked or how to catch the pirate?

    Hello everyone, I have a few requests here as member of my family comes from live be hacked:
    -can I know if we provide BBN, PIN, could we know email ID used to register?
    -How to retrieve the BBM be hacked?
    -How to catch the pirate?
    Thanks in advance!

    Most likely you allowed someone to get your credentials BBID, or you have been deceived into giving them upward.

    This is the management of Blackberry users who have their BBID diversion...

    -------------
    In these scenarios, the user must email\contact our office of privacy protection
     
    http://CA.BlackBerry.com/legal/privacy-policy.html
     
     
    10. questions or concerns? How to contact us
    BlackBerry welcomes your questions or comments about this privacy policy and the way in which we treat your personal information. If you have any questions, concerns, or you want to request access to your personal information under the privacy or data protection laws, please communicate with BlackBerry, either by e-mail or in writing and we will use commercially reasonable efforts to respond:
    email: [email protected], or
    write to one of the following offices of the nearest BlackBerry you:
    BlackBerry Privacy Office c/o BlackBerry (attention Legal Department), 2200 University Avenue East, Waterloo, Ontario, Canada N2K 0 to 7
    BlackBerry Privacy Office c/o BlackBerry (attention Legal Department), 200 Bath Road, Slough, Berkshire, United Kingdom SL1 3XE
    BlackBerry Privacy Office c/o BlackBerry (attention Legal Department), 1 International Business Park, The Synergy Building, 2nd Floor, Singapore 609917
    ------------

  • How to catch the event storm rotation?

    Hi all

    As the title,

    I want to know how to catch the rotation on the device of the storm?

    Y at - it samples which I can draw?

    Thank you

    You can use the method getOrientation() class net.rim.device.api.ui.Display

    Press the button Bravo thank the user who has helped you.

    If your problem has been resolved then please mark the thread as "accepted Solution".

  • I filled out a form on the page 8 and he saved several times along the way, and now when I open this file, the form is empty?  How can I save my work so I can open the form later and it contains all my data?

    I filled out a form on the page 8 and he saved several times along the way, and now when I open this file, the form is empty?  How can I save my work so I can open the form later and it contains all my data?

    Hi Eileen97933052,

    The PDF form must be extended drive in order to have this feature to save & print the form data.

    Please confirm by the PDF Creator is the PDF reader or not extended.

    Otherwise, if you have Acrobat installed on your system, you can reader extend PDF form yourself.

    Kind regards

    Nicos

  • Open a document in illustrator cs6 and my swatch Panel is empty.  How can I access the default swatch Panel?

    I just open a document in illustrator cs6 and my swatch Panel is empty.  How can I access the default swatch Panel?

    Thank you

    lil bib

    Probably, you have opened a file image (raster). Try to make a new document and use the file > place to insert the image.

  • drop-down menu is empty. How do I review my apps and updates?

    I have a mac and when I click on the icon above to update the menu applications drop-down is empty. How do I review my apps and updates

    If applications do not appear: not all applications displayed for download.

    If the application displays a spinning wheel of progress or a white screen empty, or otherwise does not open, try these solutions:

    Does not open App | Wheels of progress turn continuously

  • When I have a pdf file open, I used to be able to click on the "Bookmarks" tab on the left side and allow me to click on every page and delete if I had to.  Now when I click on the Bookmarks tab, this section is empty.  How can I show him each

    When I have a pdf file open, I used to be able to click on the "Bookmarks" tab on the left side and allow me to click on every page and delete if I had to.  Now when I click on the Bookmarks tab, this section is empty.  How can I show him each page once again?

    Hi chrismarks1,

    I think you can be confused bookmarks with thumbnails. If you click on the miniatures Page icon (the one above the bookmarks icon), you can delete a page by clicking on its thumbnail, clicking the delete page (icon of the Recycle Bin). Just make sure that you see the PDF file in Acrobat (rather than Acrobat Reader), you cannot remove the drive pages.

    Best,

    Sara

  • Remove the spaces of empty cells

    Hello

    In most of the paintings there was an empty cells. In this cell there was whitespace and non breaking spaces are occurs. I need to remove all these spaces for all tables.

    Can I have any script.

    Kind regards

    Vinatier

    Try this,

    for (s=0; s
    

    Vandy

  • How to catch exceptions in PowerCLI when the cmdlet PowerCLI

    Hello

    I count just one problem when catch exception throw by powercli cmdlet.

    I use the 'trap' to catch the exception like below:

    -


    Get-VMhost 192.168.43.110

    Trap {}

    "Exception when get-vmhost.

    }

    -


    I want to do this: when the 192.168.43.110 host did not exist or can not connect, I have to catch the error and give a friendly advice!

    but unfortunately the code in the block 'trap' has not run, and the error message will appear:

    -


    Get-VMHost: 2010-11-29 15:20:14 VMHost Get-VMHost with the name "192.168."

    .43.110' not found, using the specified filters.

    On line: 1 char: 11

    + Get-VMHost < < < < 192.168.43.110

    + CategoryInfo: ObjectNotFound: ( , VimException)

    + FullyQualifiedErrorId: Core_OutputHelper_WriteNotFoundError, VMware.VimA

    utomation.ViCore.Cmdlets.Commands.GetVMHost

    -


    Your idea will be a great help for me!

    Thanks in advance!

    Hello

    The reason you're trap code is not executed because the trap block intercepts only the errors, but the error you get is non-terminating. You can set the world

    $ErrorActionPreference = "Stop"
    

    or the cmdlet the ErrorAction parameter:

    Get-VMhost 192.168.43.110 -ErrorAction:Stop
    trap {
    "Exception when get-vmhost"
    }
    

    You can take a look at this thread Re: how to catch the VimExceptions correctly? also

    Kind regards

    Yasen Kalchev

    PowerCLI Dev Team

  • Enter data into the empty cell inserts the invalid main character

    When I enter data in an empty cell, for example 1 in a column, and then click validation I get the error ORA-01722: invalid number. Although I do not see the character in front of the 1 I use RIGHT twice after reaching HOME in this cell to get the cursor to the right of the 1, if a character appeared in front of the 1. Hit the BACKSPACE deletes the invisible character, and now I can commit the data entered.

    The same thing seems to happen when you remove a date using backspace in a date column. The use of return back once led to an error "ORA-01858: a non-digit character was found here where was waiting for a digital". I have to use the BACKSPACE again to get the empty cell.
    And the same thing happens in a varchar column too, although sometimes when he gets that space seems to be inserted in front of the text I entered, but this space is visible only when the cursor is not in the cell.

    What causes this? Bug in the developer SQL, SQL Developer settings, settings of the keyboard, something else?

    (Oracle SQL developer 3.1.0.7 64bits)

    This is a bug and has been fixed for the next version.

    Brian Jeffries
    SQL development team

Maybe you are looking for

  • I have a need to run FF 3.6, but also want to use 5 FF. I have both?

    I need to set up a web page. Comcast, my internet provider, free offers 3 web page, but it can only be created with FF 3.6 or lower or Explorer 8. I now use and FF5. I want to select the version I want to use. My op system is Windows 7 (64)

  • do not display the iPhoto images

    My iPhoto library says I 24 518 images, but these images are not displayed - I see only gray boxes surrounded by dotted lines. However, by clicking on the individual boxes will reveal an image in mode full-screen (this is of course a random exercise

  • How to install memory in my computer, a Dell Dimension E510?

    I just bought 2 GB memory to upgrade my computer.  Now, I need to know how to install them?  I have a Dell Dimension E510.   First of all, what is the proper way to remove the case on the computer without damaging it, & then I need to know how to rem

  • Cisco close timeout

    Hi all When a proximity of Cisco device (customer request) left the room where a Cisco Telepresence device, It seems to take 5 minutes to do this unplug/timeout Is there a setting within the Cisco Telepresence/application system that reduce this time

  • BlackBerry smartphones accidentally deleted file recovery possible?

    I accidentally deleted a folder that I created in my images.  The folder contained images more.  Is it possible possible to recover a deleted folder?  Like, is there a place where deleted things light up in the phone like a trash can on a computer, o