温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

怎么将SAP Document Builder的word控件设置成只读模式

发布时间:2021-12-29 19:29:14 来源:亿速云 阅读:140 作者:柒染 栏目:互联网科技

这篇文章将为大家详细讲解有关怎么将SAP Document Builder的word控件设置成只读模式,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。

最近我正在从事一个客户项目,客户的一个要求是他们不希望word文档在word控件中可编辑。

这意味着工具栏中的所有按钮和菜单都应该被禁用。

怎么将SAP Document Builder的word控件设置成只读模式

image

The first idea comes to my mind is the flag “enableReadWrite“.

怎么将SAP Document Builder的word控件设置成只读模式

image

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.

怎么将SAP Document Builder的word控件设置成只读模式

然后我推测,如果上传的文档是只读的,那么工具栏肯定会被禁用。因此,问题变成了如何在上传过程中将文档标记为只读。

自word 2007以来,MS office的格式遵循所谓的“Open office”协议,其规范可在此处找到。

如果将文件类型扩展名从更改为。docx到。使用WinRAR压缩并打开它,您会发现该文档实际上是由多个单个文件组成的包(在SAP internal中称为文档部分)。可编辑性由文件设置控制。xml。

怎么将SAP Document Builder的word控件设置成只读模式

如果你不知道确切的语法,就用谷歌搜索。我在谷歌的解释中使用了:

现在任务非常简单,只需在文档源代码中添加必要的xml标记即可。您不需要手动解析文档源代码,因为SAP已经完成了这项工作。您可以重用标准类CL_DOCX_文档。

由于我需要在“设置”节点中插入文档保护节点,因此为此编写了一个简单的转换。魔术在第18行和第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:

怎么将SAP Document Builder的word控件设置成只读模式

image

The word control before upload document looks like below, buttons and menus available:

怎么将SAP Document Builder的word控件设置成只读模式

image

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.

怎么将SAP Document Builder的word控件设置成只读模式

当然,此解决方案不适用于较低版本的MS word,如word2003。幸运的是,我的客户有足够的钱,他们已经在使用Office 2013,所以我不必为此担心。

关于怎么将SAP Document Builder的word控件设置成只读模式就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI