2011-02-17 81 views

回答

0

如果您知道如何在VBA中執行此操作,可以使用Com4J,爲Java生成JavaProxies,然後從Java調用相同的函數。

+0

我有VBA編碼附加的tenplates如下: – Bhuvana 2011-03-04 11:23:41

0

嘗試Apache POI,它提供了用於操作MS Office文檔的跨平臺純Java解決方案。

0

與docx4j:

// Create settings part, and init content 
    DocumentSettingsPart dsp = new DocumentSettingsPart(); 
    CTSettings settings = Context.getWmlObjectFactory().createCTSettings(); 
    dsp.setJaxbElement(settings); 
    wordMLPackage.getMainDocumentPart().addTargetPart(dsp); 

    // Create external rel 
    RelationshipsPart rp = RelationshipsPart.createRelationshipsPartForPart(dsp);  
    org.docx4j.relationships.Relationship rel = new org.docx4j.relationships.ObjectFactory().createRelationship(); 
    rel.setType("http://schemas.openxmlformats.org/officeDocument/2006/relationships/attachedTemplate" ); 
    rel.setTarget("file:///C:\\Users\\jsmith\\AppData\\Roaming\\Microsoft\\Templates\\yours.dotm"); 
    rel.setTargetMode("External");   
    rp.addRelationship(rel); // addRelationship sets the rel's @Id 

    settings.setAttachedTemplate(
      (CTRel)XmlUtils.unmarshalString("<w:attachedTemplate xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" r:id=\"" + rel.getId() + "\"/>", Context.jc, CTRel.class) 
      ); 

見org.docx4j.samples.TemplateAttach在docx4j svn的爲完整的例子。