Aspose java 保存wps创建的docx文件时会丢失namespace

我有一个由wps创建的docx文件,将其改成rar格式并解压得到的/word/document.xml,其中的namespace包含一个wps特有的 xmlns:wpsCustomData="http://www.wps.cn/officeDocument/2013/wpsCustomData"
内容如下:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:document
    xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas"
    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:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing"
    xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"
    xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
    xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml"
    xmlns:w10="urn:schemas-microsoft-com:office:word"
    xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml"
    xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup"
    xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk"
    xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml"
    xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape"
    xmlns:wpsCustomData="http://www.wps.cn/officeDocument/2013/wpsCustomData" mc:Ignorable="w14 w15 wp14">
    <w:body>
        <w:p>
            <w:pPr>
                <w:rPr>
                    <w:rFonts w:hint="default" w:eastAsiaTheme="minorEastAsia"/>
                    <w:lang w:val="en-US" w:eastAsia="zh-CN"/>
                </w:rPr>
            </w:pPr>
            <w:bookmarkStart w:id="0" w:name="_GoBack"/>
            <w:r>
                <w:rPr>
                    <w:rFonts w:hint="eastAsia"/>
                    <w:lang w:val="en-US" w:eastAsia="zh-CN"/>
                </w:rPr>
                <w:t>wps创建</w:t>
            </w:r>
        </w:p>
        <w:bookmarkEnd w:id="0"/>
        <w:sectPr>
            <w:pgSz w:w="11906" w:h="16838"/>
            <w:pgMar w:top="1440" w:right="1800" w:bottom="1440" w:left="1800" w:header="851" w:footer="992" w:gutter="0"/>
            <w:cols w:space="425" w:num="1"/>
            <w:docGrid w:type="lines" w:linePitch="312" w:charSpace="0"/>
        </w:sectPr>
    </w:body>
</w:document>

在使用java aspose word进行保存操作后,新生成的docx文件进行同样的解压操作。document.xml中丢失了 xmlns:wpsCustomData="http://www.wps.cn/officeDocument/2013/wpsCustomData"

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<w:document
    xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas"
    xmlns:cx="http://schemas.microsoft.com/office/drawing/2014/chartex"
    xmlns:cx1="http://schemas.microsoft.com/office/drawing/2015/9/8/chartex"
    xmlns:cx2="http://schemas.microsoft.com/office/drawing/2015/10/21/chartex"
    xmlns:cx3="http://schemas.microsoft.com/office/drawing/2016/5/9/chartex"
    xmlns:cx4="http://schemas.microsoft.com/office/drawing/2016/5/10/chartex"
    xmlns:cx5="http://schemas.microsoft.com/office/drawing/2016/5/11/chartex"
    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:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing"
    xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"
    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:w15="http://schemas.microsoft.com/office/word/2012/wordml"
    xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml"
    xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup"
    xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk"
    xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" mc:Ignorable="w14 w15 wp14">
    <!-- Generated by Aspose.Words for Java 23.6.0 -->
    <w:body>
        <w:p>
            <w:r>
                <w:rPr>
                    <w:b />
                    <w:color w:val="FF0000" />
                    <w:sz w:val="24" />
                </w:rPr>
                <w:t>Evaluation Only. Created with Aspose.Words. Copyright 2003-2023 Aspose Pty Ltd.</w:t>
            </w:r>
        </w:p>
        <w:p>
            <w:pPr>
                <w:rPr>
                    <w:rFonts w:eastAsiaTheme="minorEastAsia" w:hint="default" />
                    <w:lang w:val="en-US" w:eastAsia="zh-CN" />
                </w:rPr>
            </w:pPr>
            <w:bookmarkStart w:id="0" w:name="_GoBack" />
            <w:r>
                <w:rPr>
                    <w:rFonts w:hint="eastAsia" />
                    <w:lang w:val="en-US" w:eastAsia="zh-CN" />
                </w:rPr>
                <w:t>wps创建</w:t>
            </w:r>
        </w:p>
        <w:bookmarkEnd w:id="0" />
        <w:sectPr>
            <w:headerReference w:type="default" r:id="rId4" />
            <w:footerReference w:type="default" r:id="rId5" />
            <w:pgSz w:w="11906" w:h="16838" />
            <w:pgMar w:top="1440" w:right="1800" w:bottom="1440" w:left="1800" w:header="851" w:footer="992" w:gutter="0" />
            <w:cols w:num="1" w:space="425" />
            <w:docGrid w:type="lines" w:linePitch="312" w:charSpace="0" />
        </w:sectPr>
    </w:body>
</w:document>

wps创建.docx (9.8 KB)
wps创建aspose修改.docx (19.5 KB)

@Stan9333 实际上,文档中没有使用 wpsCustomData 命名空间,因此不需要它。 如果您使用 MS Word 打开/保存文档,命名空间也将被删除。 Aspose.Words不保留原始XML,在加载整个文档时将其加载到Aspose.Words DOM中,并且在保存文档时,文档结构是从DOM构建的。

那aspose有什么api或者配置能增加我想要的namespace吗

@Stan9333 不,不幸的是,没有这样的选择。 命名空间是按需添加的。 但是,我们的缺陷数据库中有一个支持 wpsCustomData 字段的功能请求。 我已将此主题链接到适当的问题。

1 Like