couldn't get/set checkbox value in Word document (.doc) with Apache POI

谁说胖子不能爱 提交于 2019-12-11 03:18:02

问题


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.



来源:https://stackoverflow.com/questions/29518025/couldnt-get-set-checkbox-value-in-word-document-doc-with-apache-poi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!