通过DOCX4J编辑图表时,查找嵌入式XLSX文件的文件名

问题描述

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

解决方法

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

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();
           } 
        }
    }

我希望这对任何需要掌握此内容的人都有帮助...对此表示欢迎!