Results 1 to 6 of 6
  1. #1
    ChandanK is offline Member
    Join Date
    Mar 2014
    Posts
    3
    Rep Power
    0

    Default How to read value of a checkbox using Apache.POI. (Help please!)

    I am using apache POI for the first time.I am trying to read the value of a check-box from a word document(fixed template). But i am not getting the proper values(0 or 1) for unchecked and checked boxes respectively. Could anyone please help me with this? The code that I am using is as follows:

    import java.io.File;
    import java.io.FileInputStream;

    import org.apache.poi.hwpf.HWPFDocument;
    import org.apache.poi.hwpf.extractor.WordExtractor;

    public class DocReader {

    public void readDocFile()
    {
    File docFile = null;
    WordExtractor docExtractor = null ;
    WordExtractor exprExtractor = null ;
    try
    {
    docFile = new File("c:\\Temp.doc");

    FileInputStream fis=new FileInputStream(docFile.getAbsolutePath());

    HWPFDocument doc=new HWPFDocument(fis);

    docExtractor = new WordExtractor(doc);
    }
    catch(Exception exep)
    {
    System.out.println(exep.getMessage());
    }


    String docArray[] = docExtractor.getParagraphText();

    for(int i=116;i<118;i++)
    {
    if(docArray[i] != null)
    System.out.println(docArray[i].trim());
    }
    }

    public static void main(String[] args) {
    DocReader reader = new DocReader();
    reader.readDocFile();
    }
    }
    ---------------------------------------
    The output is:

    FORMCHECKBOX  Option1
    FORMCHECKBOX  Option2

    ----------------------------------------

    I simply copied the check boxes from the word file and pasted them to a text file and I am getting:

    1 Option1
    0 Option2

    where Option1 is the checked check-box and Option2 is unchecked.
    I was hoping to see something similar as the output of my java code.
    Could anyone please help?

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default Re: How to read value of a checkbox using Apache.POI. (Help please!)

    Be warned that the Word element of POI is only somewhat functional, and hasn't had anyone working on it properly for quite some time. I don't think it's ever come out of the sandbox.

    To quote from the Apache POI docs for it:
    "
    Both HWPF and XWPF could be described as "moderately functional". For some use cases, especially around text extraction, support is very strong. For others, support may be limited or incomplete, and it may be necessary to dig down into low-level code. Error checking may be missing in places, so it may be possible to accidently generate invalid files. Enhancements to fix such things are generally very well received!
    "
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    ChandanK is offline Member
    Join Date
    Mar 2014
    Posts
    3
    Rep Power
    0

    Default Re: How to read value of a checkbox using Apache.POI. (Help please!)

    Thanks for your reply.
    I am aware of apache poi's limitations. But i only require the value of the checkbox so i dont want to learn and then use docx4j. Besides docx4j supports only (.docx). BUt I need my application to read both .doc and .docx.
    Could you suggest any other alternative?

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default Re: How to read value of a checkbox using Apache.POI. (Help please!)

    Afraid not, as I've only ever needed POI for Excel documents.
    Never had the "pleasure" of having to parse a Word document.

    Note, I'm not saying POI can't handle this, but it does have a lot of holes in what it can handle.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,029
    Rep Power
    6

    Default Re: How to read value of a checkbox using Apache.POI. (Help please!)

    OpenOffice can be setup as a server which you can then connect with from your software to instruct it to do things and stuff with documents; and OpenOffice has full support for loading office documents. That is going to be a huge leap to research and setup, but if you MUST do this with Java (not the right tool for this job IMO), then it might be the most stable option.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  6. #6
    ChandanK is offline Member
    Join Date
    Mar 2014
    Posts
    3
    Rep Power
    0

    Default Re: How to read value of a checkbox using Apache.POI. (Help please!)

    Thanks again.
    Lets see what can be done about it.

Similar Threads

  1. Read/write to same excel file using Apache POI
    By anji2010 in forum Apache POI
    Replies: 4
    Last Post: 01-17-2014, 10:57 AM
  2. Replies: 0
    Last Post: 01-15-2014, 07:27 AM
  3. Read Bookmarks from a word document using apache POI
    By anuskesh in forum Advanced Java
    Replies: 0
    Last Post: 07-28-2010, 04:36 AM
  4. Replies: 3
    Last Post: 07-27-2010, 09:52 AM
  5. Replies: 0
    Last Post: 11-15-2008, 07:29 AM

Posting Permissions

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