Recently I am working on a customer project and one customer requirement is they do not want to the word document be editable in the word control.
That means all buttons and menus in toolbar should be disabled.
The first idea comes to my mind is the flag “enableReadWrite“.
As documented in
sap help，it can fulfill my help but unfortunately it is deprecated. Regardless of this warning I have a try and found it does not work indeed.
Then I am speculating that if the document uploaded is read only, it is for sure that the toolbar will be disabled. So the issue turns to that how could I mark the document to be read only on the fly during uploading.
Since word 2007 the format of MS office follows the so called “Open office” protocol whose specification could be found
If you change the file type extension from .docx to .zip and open it with WinRAR, you will find the document is actually a bundle of several single files ( called document part in SAP internal ). The editability is controlled within the file settings.xml.
If you don’t know the exact syntax, just google it. I use the explanation from
this one in google:
Now the task is quite easy, just add the necessary xml tag into the document source code. You do not need to manually parse the document source code since SAP has already done this job. You can just reuse standard class CL_DOCX_DOCUMENT.
Since I need to insert the document protection node in “settings” node, a simple transformation is written for this. The magic is between line 18 and 21.
and find a proper place to call the transformation:
after that the tag will be there in settings.xml:
The word control before upload document looks like below, buttons and menus available:
After upload, menu and button are disabled. If you try to edit the document, there will be notifications in the right pane to give you a hint that is not possible.
Of course this solution does not work for lower version of MS word like word2003. Fortunately my customer has enough money and they are already using Office 2013 so I do not need to worry about it.
来自 “ ITPUB博客 ” ，链接：http://blog.itpub.net/24475491/viewspace-2708659/，如需转载，请注明出处，否则将追究法律责任。