Fetching Option or Radio Button worksheet form control from an excel file using POI

December 8, 2010

I was recently working on a task where I wanted to read an excel file that had some radio button (also know as Option button in excel terminology). I was using Apache’s POI framework. The objective of the task was to read/write the state of a radio button (state meaning if radio button is selected or deselected). Since I was new to POI, I went through the documentation but couldn’t find any useful stuff on how to deal with Worksheet form controls (Option buttons are type of form control). Googling on this issue wasn’t so helpful. All I could gather was that, POI does provide a Class that represents Option button, but does not provide any API to interact with it. I am using POI version 3.6, and the class that represents this Option button is called as CommonObjectDataSubRecord . This class is sub-class of SubRecord .

Unfortunately I couldn’t find any sample code that parses and excel file and fetches the Option button, so I have to hand-craft it (was bit painful, but looking at error stack traces  on various POI forums and reading actual POI source code helped me). So it here goes…might be helpful for others

 

 

 

Hope this helps you

About these ads

3 Responses to “Fetching Option or Radio Button worksheet form control from an excel file using POI”

  1. Andreas Says:

    Hi,

    Thanks a lot for sharing this! I’m struggling with the same thing (having to determine which option button is selected) and found your post to be by far the most helpful all over the place.

    One thing is still not clear to me:

    My Excel-Sheet is having a group of three option buttons. Using the code you provided, for each button I’m getting an output like:

    [ftCmo]
    .objectType = 0x000C (12 )
    .objectId = 0x000000C4 (196 )
    .option = 0×0011 (17 )
    .locked = true
    .printable = true
    .autofill = false
    .autoline = false
    .reserved1 = 0x04A2DE80 (77782656 )
    .reserved2 = 0x04A29720 (77764384 )
    .reserved3 = 0×00000000 (0 )
    [/ftCmo]

    But how can I figure out whether the button is selected or not? I couldn’t find a proper method like i.e.”isSelected()” nor could I recognize certain patterns in the data above when a button is selected or not.

    Thanks! Your help is much appreciated.

  2. amwebexpert Says:

    I have the same problem: figure out whether the button is selected or not… Any hint?

  3. jeg Says:

    Any answer for how to get the value of option button?


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: