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 here. 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.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w10="urn:schemas-microsoft-com:office:word"
xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:sl="http://schemas.openxmlformats.org/schemaLibrary/2006/main" mc:Ignorable="w14" version="1.0">
<xsl:output encoding="UTF-8" indent="no" method="xml" omit-xml-declaration="no" version="1.0"/>
<!-- Match everything all nodes and attributes -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="w:settings">
<xsl:element name="w:settings">
<xsl:for-each select="@*">
<xsl:copy/>
</xsl:for-each>
<xsl:element name="w:documentProtection">
<xsl:attribute name="w:edit">readOnly</xsl:attribute>
<xsl:attribute name="w:enforcement">1</xsl:attribute>
</xsl:element>
<xsl:copy-of select="./*"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
and find a proper place to call the transformation:
DATA: lr_element TYPE REF TO if_wd_context_element,
lv_file_data TYPE xstring,
lv_ret TYPE i,
lx_temp TYPE xstring,
lv_msg TYPE string,
lt_parms TYPE /ipro/tt_key_value_pair,
ls_parm LIKE LINE OF lt_parms.
lr_element = me->wd_context->get_element( ).
CHECK lr_element IS NOT INITIAL.
lr_element->get_attribute( EXPORTING name = 'BINARY' IMPORTING value = lv_file_data ).
DATA(lo_docx) = cl_docx_document=>load_document( lv_file_data ).
DATA(lo_main_part) = lo_docx->get_maindocumentpart( ).
DATA(lo_docx_settings) = lo_main_part->get_documentsettingspart( ).
DATA(lx_settings) = lo_docx_settings->get_data( ).
/ipro/cl_docx_utilities=>transform( EXPORTING iv_input_xstring = lx_settings
iv_transform_name = '/IPRO/DOCXCC_PROTECT'
it_parameters = lt_parms
IMPORTING ev_result = lx_temp
ev_ret = lv_ret
ev_message = lv_msg ).
lo_docx_settings->feed_data( lx_temp ).
DATA(lx_docx_package) = lo_docx->get_package_data( ).
lr_element->set_attribute( EXPORTING name = 'BINARY' value = lx_docx_package ).
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.
要获取更多Jerry的原创文章,请关注公众号"汪子熙":
相关推荐
SAP Powerbuilder 12.6 (4081)无限时学习破解文件,解压后覆盖即可!
6. 安装与集成:在解压文件后,开发者需要按照提供的文档指示将控件库导入到PowerBuilder环境中,并在项目中进行适当的配置。这可能涉及到修改PB的环境设置、添加控件到工具箱,以及编写必要的代码来利用新的界面...
根据提供的文件信息,本文将详细介绍SAP Document Library Release 4.6C的相关知识点,包括其下载、安装配置方法以及在SAP系统中的应用。 ### SAP Document Library 4.6C 简介 SAP Document Library是SAP系统中一...
根据给定的文件信息,我们可以深入探讨SAP CRM(Customer Relationship Management)中间件文档的关键知识点。这份文档似乎涉及SAP CRM 7.0版本,发布于2010年9月,由SAP AG出版,版权注明为SAP AG所有,并强调了其...
在实际应用中,SAP .NET Proxy Builder常用于企业信息化系统集成,例如将SAP的库存管理、订单处理等功能与企业内部的其他系统(如CRM、ERP等)进行无缝对接。通过这样的集成,企业可以优化业务流程,提高数据的一致...
SAP和Java 语言的接口组件,可以通过她来开发java程序
标题与描述均提到了"SAP .NET Connector Document",这指向了一个特定的文档,即SAP为Microsoft .NET环境开发的连接器的官方文档。这个文档版本为2.0,发布于2005年3月,版权归属于SAP AG。 ### SAP .NET Connector...
PowerBuilder是Sybase公司(现被SAP收购)推出的一种面向对象的快速应用开发工具,尤其在数据库应用程序开发领域有着广泛的应用。这款图片浏览器并没有依赖任何数据库,而是直接处理文件系统中的图像资源,使得用户...
SAP GUI个性化设置秘籍 SAP GUI个性化设置秘籍是指在SAP GUI系统中对界面和功能的自定义设置,以满足用户的个性化需求。该秘籍主要介绍了如何在SAP GUI系统中实现品牌化设置,包括注册表编辑、品牌图片设置等步骤。...
本文将深入探讨"SAP自定义纸张打印设置技巧",包括如何进行SAP打印机自定义纸张设置、本地打印机配置、解决打印池满的问题以及在SMARTFORMS中调整超大字体大小。 首先,SAP打印机自定义纸张设置是确保企业能够根据...
### Word-Processing in the SAPscript Editor #### 概述 SAPscript编辑器是一种用于创建、编辑和格式化文档的强大工具,尤其适用于SAP环境下的报告和文档制作工作。通过SAPscript,用户可以轻松地处理文本内容,...
本文将详细讲解如何使用PB(PowerBuilder)结合QRMaker.ocx控件来生成二维码。 首先,我们需要理解PB(PowerBuilder)是什么。PB是一款由SAP公司开发的可视化、面向对象的软件开发工具,主要用于构建数据库应用系统...
有关SAP系统中物料帐自动科目设置的学习资料!
sap Document Library Release 4.6C CD 下载地址,经测试在SAP 4.71中配置成功。 1.光盘安装 2.在SAP中用SR13配置即可。具体参见:http://blog.csdn.net/kehq2008/archive/2009/08/12/4440004.aspx
本文将详细解析SAP多国语言设置的相关知识点,包括系统语言设置、安装语言设置以及数据库编码设置等方面。 ### 一、系统语言设置 SAP系统的多国语言支持首先体现在系统语言的设置上。系统语言是指SAP系统默认的...
标题“UI5 FIORI SEGW SAP Gateway Service Builder”涉及到几个关键的技术领域:UI5(也称SAPUI5或OpenUI5)、FIORI、SEGW以及SAP Gateway。本段将详细解释上述技术概念以及它们在构建SAP企业级应用时的作用。 UI5...
PDF转Word工具是一种常见的软件应用,它允许用户将 Portable Document Format (PDF) 文件转换成 Microsoft Word 文档(.doc 或 .docx 格式)。在技术层面上,这个过程涉及到解析PDF文件的内容,包括文本、图像、表格...
PowerBuilder是一款强大的可视化数据库应用开发工具,由Sybase公司(后被SAP收购)开发,主要用于构建企业级的数据库应用程序。在这个“PowerBuilder安装包及教程大礼包”中,您将找到PB9.0的安装程序以及一系列辅助...
.NET Connector 3.0是微软和SAP合作开发的组件,它基于.NET Framework,提供了一种高效、安全的与SAP NetWeaver应用服务器交互的方式。NCO3.0支持ABAP和Java两种SAP应用服务器,同时兼容多种SAP接口技术,如RFC...
本教程将聚焦于SAP中的一个特定领域——如何设置打印格式,尤其是涉及到二维条码的生成与打印。通过提供的资料,我们可以深入理解SAP中的Smartforms工具以及它在条码打印中的应用。 首先,我们要了解SAP Smartforms...