I'm working creating a docx file which needs to be readonly protected except in some fields. For those fields I have solved it with this:
pInit.getCTP().addNewPermStart();
...
pEnd.getCTP().addNewPermEnd();
But now I want to allow adding new rows to a XWPFTable, but this line:
document.enforceReadonlyProtection(wordLockedPass, HashAlgorithm.sha1);
block this functionality and I don't know what to do.
Thanks in advance!
If the table is in an editable region (between
PermStartandPermEnd) then it will be editable including adding rows.The
PermStartandPermEndcan be inserted in document body usingand
All body elements between this
PermStartandPermEndare editable in a protected document. That is true also for tables between thisPermStartandPermEnd.If only parts of tables shall be editable, then
PermStartandPermEndalso can be inserted within the table. For example if only the last row of a table shall be editable and new rows shall be insertable, then:Complete example:
This code is tested and works using
apache poi 5.2.2. It produces a Word document having two editable regions. The second is in a table after the title row. So that title row is protected. The last row is in that editable region. So this row is editable and new rows can be inserted above and below that row. All this tested inMicrosoft Word 2017andMicrosoft Word 365. Other text-processing applications, which are able to handle*.docxfiles, might not respect editable regions.