我正在尝试合并两个文档让我们说文档 1:Merger1.doc 文档 2:Merger2.doc
我想将它存储到一个新文件 doc2.docx 中。
我已经使用这段代码来做到这一点,但它抛出了一些错误。
代码:
import java.io.*;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.usermodel.CharacterRun;
import org.apache.poi.hwpf.usermodel.Range;
public class MergerFiles {
public static void main (String[] args) throws Exception {
// POI apparently can't create a document from scratch,
// so we need an existing empty dummy document
HWPFDocument doc = new HWPFDocument(new FileInputStream("C:\\Users\\pallavi123\\Desktop\\Merger1.docx"));
Range range = doc.getRange();
//I can get the entire Document and insert it in the tmp.doc
//However any formatting in my word document is lost.
HWPFDocument …Run Code Online (Sandbox Code Playgroud)