couldn't get/set checkbox value in Word docume

2019-02-26 21:52发布

问题:

I'm trying to get/set checkbox value in Word document (.doc) with Apache POI.

I looked HWPFDocument API at poi.apache.org, but haven't found anything suitable... Maybe somebody have a solution?

Thank You!

回答1:

Unfortunately, this is currently not supported by POI. What does work is to read out (not set) dropdown lists via CharacterRun.getDropDownListValues() and CharacterRun.getDropDownListDefaultItemIndex().

Technically those dropdown lists are closely related to checkboxes, though. So it should not be too difficult to add the respective functionality to POI, if desired. Your entry point is a NilPICFAndBinData structure (handled by this class in POI), which leads you to some FFData (maps to this class in POI). Inside that you will find FFDataBits. These eventually contain an iRes value which encodes the status of that checkbox. - This is exactly the same behavior as for dropdown lists, only that the iType of FFDataBits will be iTypeChck instead of iTypeDrop and has to be interpreted in a slightly different way.



回答2:

I had the same problem. Had to write a VBA macro that gets the value of the checkboxs, stores it in a portable database and I get it from there.