Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使用docx4j合并两个docx文件?_Java_Docx4j - Fatal编程技术网

Java 如何使用docx4j合并两个docx文件?

Java 如何使用docx4j合并两个docx文件?,java,docx4j,Java,Docx4j,我有两个要合并的docx文件,我在docx4j中有以下代码,但有一些错误!这两个docx文件都用于跟踪更改。因此,输出文件应该包含这两个docx文件的详细信息 import java.io.File; import java.util.ArrayList; import java.util.List; import org.docx4j.openpackaging.exceptions.Docx4JException; import o

我有两个要合并的docx文件,我在docx4j中有以下代码,但有一些错误!这两个docx文件都用于跟踪更改。因此,输出文件应该包含这两个docx文件的详细信息

import java.io.File;    
import java.util.ArrayList;          
import java.util.List;             
import org.docx4j.openpackaging.exceptions.Docx4JException;   
import org.docx4j.openpackaging.io.SaveToZipFile;     
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;   
import com.plutext.merge.BlockRange;  
import com.plutext.merge.BlockRange.HfBehaviour;          
import com.plutext.merge.BlockRange.SectionBreakBefore;         
import com.plutext.merge.BlockRange.NumberingHandler;          
import com.plutext.merge.BlockRange.StyleHandler;        
import com.plutext.merge.DocumentBuilder;         
public class MergeWholeDocumentsUsingBlockRange                                                                                                                                
{
     public final static String DIR_IN = System.getProperty("user.dir")+ "/"; 
     public final static String DIR_OUT = System.getProperty("user.dir")+ "/"; 
     public static void main(String[] args) throws Exception { 
     String[] files = {"table.docx", "Table1.docx"}; 
     List blockRanges = new ArrayList(); 
     for (int i=0 ; i< files.length; i++) { 
     BlockRange block = new BlockRange(WordprocessingMLPackage.load(new File(DIR_IN + files[i]))); 
        blockRanges.add( block ); 
        block.setStyleHandler(StyleHandler.RENAME_RETAIN);
        block.setNumberingHandler(NumberingHandler.ADD_NEW_LIST);
        block.setRestartPageNumbering(false);
        block.setHeaderBehaviour(HfBehaviour.DEFAULT);
        block.setFooterBehaviour(HfBehaviour.DEFAULT);
        block.setSectionBreakBefore(SectionBreakBefore.NEXT_PAGE);
    } 
        // Perform the actual merge 
        DocumentBuilder documentBuilder = new DocumentBuilder(); 
        WordprocessingMLPackage output = documentBuilder.buildOpenDocument(blockRanges); 
       // Save the result 
       SaveToZipFile saver = new SaveToZipFile(output); 
       saver.save(DIR_OUT+"OUT_MergeWholeDocumentsUsingBlockRange.docx"); 
       } 
    } 
导入java.io.File;
导入java.util.ArrayList;
导入java.util.List;
导入org.docx4j.openpackaging.exceptions.docx4jeexception;
导入org.docx4j.openpackaging.io.SaveToZipFile;
导入org.docx4j.openpackaging.packages.WordprocessingMLPackage;
导入com.plutext.merge.BlockRange;
导入com.plutext.merge.BlockRange.hfbehavior;
导入com.plutext.merge.BlockRange.SectionBreakBefore;
导入com.plutext.merge.BlockRange.NumberingHandler;
导入com.plutext.merge.BlockRange.StyleHandler;
导入com.plutext.merge.DocumentBuilder;
使用BlockRange的公共类合并WholedDocuments
{
公共最终静态字符串DIR_IN=System.getProperty(“user.DIR”)+“/”;
公共最终静态字符串DIR_OUT=System.getProperty(“user.DIR”)+“/”;
公共静态void main(字符串[]args)引发异常{
字符串[]文件={“table.docx”,“Table1.docx”};
List blockRanges=new ArrayList();
对于(inti=0;i
此代码适用于小型docxIs。这是付费版本吗?是的,这是付费版本