0

我有一个包含至少 8 个图表的 Word 文档 (docx)。这些图表中的每一个都需要自动更新。我能够更改文档中的数据,但仍然需要找到一种编辑嵌入式 xlsx 文件的方法。如何为每个图表找到嵌入文件的相应文件名?

4

1 回答 1

1

我找到了一个解决方案,但我不知道这是否防水......

private void findEmbeddedXlsx(Chart chart) {
    RelationshipsPart rp = chart.getRelationshipsPart();
    for ( Relationship r : rp.getRelationships().getRelationship() ) {
       if (r.getType().equals(Namespaces.EMBEDDED_PKG)) {
           try {
               //tgt is the filename of the embedded file
               String tgt = r.getTarget();
               //... whatever you need to do with the embedded file
           } catch (Docx4JException e) {
                e.printStackTrace();
           } 
        }
    }

我希望这可以帮助任何需要掌握这一点的人......非常欢迎对此发表评论!

于 2020-10-19T15:29:00.593 回答