|
@@ -0,0 +1,62 @@
|
|
|
+package com.wzkj.zhai.contact;
|
|
|
+import com.spire.doc.Document;
|
|
|
+import com.spire.doc.FileFormat;
|
|
|
+import org.apache.commons.io.FilenameUtils;
|
|
|
+import org.apache.commons.cli.*;
|
|
|
+
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.nio.file.Paths;
|
|
|
+
|
|
|
+
|
|
|
+public class Application {
|
|
|
+ public static void main(String[] args) {
|
|
|
+ System.out.println(args[0]);
|
|
|
+// getAllFiles("docx");
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void parseParams(String[] args) {
|
|
|
+ Options options = new Options();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void merge(String dir, String filename) {
|
|
|
+ String ext = FilenameUtils.getExtension(filename);
|
|
|
+ String answerDoc = filename.replace( "." + ext, "-y."+ext);
|
|
|
+ String resultDoc = filename.replace( "." + ext, "-r."+ext);
|
|
|
+
|
|
|
+ //获取第一个文档的路径
|
|
|
+ String filePath1 = Paths.get(dir, filename).toString();
|
|
|
+ //获取第二个文档的路径
|
|
|
+ String filePath2 = Paths.get(dir, answerDoc).toString();
|
|
|
+ String resultPath = Paths.get(dir, resultDoc).toString();
|
|
|
+
|
|
|
+ //加载第一个文档
|
|
|
+ Document document = new Document(filePath1);
|
|
|
+
|
|
|
+ //使用insertTextFromFile方法将第二个文档的内容插入到第一个文档
|
|
|
+ document.insertTextFromFile(filePath2, FileFormat.Docx_2013);
|
|
|
+
|
|
|
+ //保存文档
|
|
|
+ document.saveToFile(resultPath, FileFormat.Docx_2013);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void getAllFiles(String dir) {
|
|
|
+ File dirFile = new File(dir);
|
|
|
+ File[] files = dirFile.listFiles();
|
|
|
+ if (null == files) {
|
|
|
+ System.out.printf("获取目录(%s)为空", dir);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (File file : files) {
|
|
|
+ if (file.isDirectory()) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (file.getName().contains("-y") || file.getName().contains("-r")) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ merge(dir, file.getName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|