|
@@ -697,11 +697,13 @@ public final class DocxProcessUtil {
|
|
out.flush();
|
|
out.flush();
|
|
IOUtils.closeQuietly(out);
|
|
IOUtils.closeQuietly(out);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 导出wordnew
|
|
* 导出wordnew
|
|
- * @param dataMap
|
|
|
|
- * @param fileName
|
|
|
|
|
|
+ * @param dataModel
|
|
|
|
+ * @param outFile
|
|
|
|
+ * @param template
|
|
|
|
+ * @throws Exception
|
|
*/
|
|
*/
|
|
public static void exportWordNew(Object dataModel, File outFile,Template template)throws Exception {
|
|
public static void exportWordNew(Object dataModel, File outFile,Template template)throws Exception {
|
|
Writer out = null;
|
|
Writer out = null;
|
|
@@ -984,67 +986,60 @@ public final class DocxProcessUtil {
|
|
return -1;
|
|
return -1;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
- public static byte[] getWordBytesByQuestion(WordprocessingMLPackage wordMLPackage,List<String> wordXmls) throws Exception{
|
|
|
|
- try {
|
|
|
|
- RelationshipsPart mainRelationshipsPart = wordMLPackage.getMainDocumentPart().getRelationshipsPart();
|
|
|
|
- // 获取总的资源文件存储
|
|
|
|
- ZipPartStore partStore = (ZipPartStore) wordMLPackage.getSourcePartStore();
|
|
|
|
- //创建子Word
|
|
|
|
- WordprocessingMLPackage subWordPackage = WordprocessingMLPackage.createPackage();
|
|
|
|
- MainDocumentPart subMainDocumentPart = subWordPackage.getMainDocumentPart();
|
|
|
|
- //向子Word中添加内容
|
|
|
|
- for(String wordXml:wordXmls){
|
|
|
|
- wordXml = "<myElement>"+wordXml+"</myElement>";
|
|
|
|
- Document document = DocumentHelper.parseText(wordXml);
|
|
|
|
- org.dom4j.Element rootElement = document.getRootElement();
|
|
|
|
- List<org.dom4j.Element> nodes = rootElement.elements();
|
|
|
|
- for(org.dom4j.Element element:nodes){
|
|
|
|
- Object obj = XmlUtils.unmarshalString(element.asXML());
|
|
|
|
- subMainDocumentPart.addObject(obj);
|
|
|
|
|
|
+
|
|
|
|
+ public static byte[] getWordBytesByQuestion(WordprocessingMLPackage wordMLPackage, List<String> wordXmls) throws Exception {
|
|
|
|
+ RelationshipsPart mainRelationshipsPart = wordMLPackage.getMainDocumentPart().getRelationshipsPart();
|
|
|
|
+ // 获取总的资源文件存储
|
|
|
|
+ ZipPartStore partStore = (ZipPartStore) wordMLPackage.getSourcePartStore();
|
|
|
|
+ //创建子Word
|
|
|
|
+ WordprocessingMLPackage subWordPackage = WordprocessingMLPackage.createPackage();
|
|
|
|
+ MainDocumentPart subMainDocumentPart = subWordPackage.getMainDocumentPart();
|
|
|
|
+ //向子Word中添加内容
|
|
|
|
+ for (String wordXml : wordXmls) {
|
|
|
|
+ wordXml = "<myElement>" + wordXml + "</myElement>";
|
|
|
|
+ Document document = DocumentHelper.parseText(wordXml);
|
|
|
|
+ org.dom4j.Element rootElement = document.getRootElement();
|
|
|
|
+ List<org.dom4j.Element> nodes = rootElement.elements();
|
|
|
|
+ for (org.dom4j.Element element : nodes) {
|
|
|
|
+ Object obj = XmlUtils.unmarshalString(element.asXML());
|
|
|
|
+ subMainDocumentPart.addObject(obj);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //向子Word中添加图片的关联关系
|
|
|
|
+ RelationshipsPart subRelationshipsPart = subMainDocumentPart.getRelationshipsPart();
|
|
|
|
+ List<Relationship> subRelationships = subRelationshipsPart.getRelationshipsByType(Namespaces.IMAGE);
|
|
|
|
+ List<Object> blips = subMainDocumentPart.getJAXBNodesViaXPath("//a:blip", false);
|
|
|
|
+ for (Object blip : blips) {
|
|
|
|
+ if (blip.getClass().equals(CTBlip.class)) {
|
|
|
|
+ CTBlip cTBlip = (CTBlip) blip;
|
|
|
|
+ Relationship relationship = mainRelationshipsPart.getRelationshipByID(cTBlip.getEmbed());
|
|
|
|
+ if (relationship != null) {
|
|
|
|
+ subRelationships.add(relationship);
|
|
}
|
|
}
|
|
- }
|
|
|
|
- //向子Word中添加图片的关联关系
|
|
|
|
- RelationshipsPart subRelationshipsPart = subMainDocumentPart.getRelationshipsPart();
|
|
|
|
- List<Relationship> subRelationships = subRelationshipsPart.getRelationshipsByType(Namespaces.IMAGE);
|
|
|
|
- List<Object> blips = subMainDocumentPart.getJAXBNodesViaXPath("//a:blip",false);
|
|
|
|
- for(Object blip:blips){
|
|
|
|
- if (blip.getClass().equals(CTBlip.class)) {
|
|
|
|
- CTBlip cTBlip = (CTBlip)blip;
|
|
|
|
- Relationship relationship = mainRelationshipsPart.getRelationshipByID(cTBlip.getEmbed());
|
|
|
|
- if(relationship!=null){
|
|
|
|
- subRelationships.add(relationship);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- //向子Word中添加资源
|
|
|
|
- List<Part> parts = new ArrayList<Part>();
|
|
|
|
- for (Relationship relationship : subRelationships) {
|
|
|
|
- if(mainRelationshipsPart.getPart(relationship)!=null){
|
|
|
|
- parts.add(mainRelationshipsPart.getPart(relationship));
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
- for (Part p : parts) {
|
|
|
|
- if(p.getSourceRelationships()!=null&&
|
|
|
|
- p.getSourceRelationships().size()>0){
|
|
|
|
- String relId = p.getSourceRelationships().get(0).getId();
|
|
|
|
- if(mainRelationshipsPart.isRelIdOccupied(relId)){
|
|
|
|
- DocxProcessUtil.copyImage(subWordPackage,partStore,p,relId);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
+ //向子Word中添加资源
|
|
|
|
+ List<Part> parts = new ArrayList<Part>();
|
|
|
|
+ for (Relationship relationship : subRelationships) {
|
|
|
|
+ if (mainRelationshipsPart.getPart(relationship) != null) {
|
|
|
|
+ parts.add(mainRelationshipsPart.getPart(relationship));
|
|
}
|
|
}
|
|
- subWordPackage = DocxProcessUtil.getTmpPackage(subWordPackage);
|
|
|
|
- return DocxProcessUtil.getPkgByte(subWordPackage);
|
|
|
|
- } catch (Docx4JException e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
- } catch (FileNotFoundException e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
- } catch (IOException e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
- }
|
|
|
|
- return null;
|
|
|
|
|
|
+ }
|
|
|
|
+ for (Part p : parts) {
|
|
|
|
+ if (p.getSourceRelationships() != null &&
|
|
|
|
+ p.getSourceRelationships().size() > 0) {
|
|
|
|
+ String relId = p.getSourceRelationships().get(0).getId();
|
|
|
|
+ if (mainRelationshipsPart.isRelIdOccupied(relId)) {
|
|
|
|
+ DocxProcessUtil.copyImage(subWordPackage, partStore, p, relId);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ initTmpPackage(subWordPackage);
|
|
|
|
+ byte[] writeByte = getPkgByte(subWordPackage);
|
|
|
|
+ subWordPackage = null;
|
|
|
|
+ wordXmls.clear();
|
|
|
|
+ wordXmls = null;
|
|
|
|
+ return writeByte;
|
|
}
|
|
}
|
|
|
|
|
|
public static int getOptionNum(String wordText){
|
|
public static int getOptionNum(String wordText){
|