-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathCompare.java
38 lines (35 loc) · 1.21 KB
/
Compare.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package compare;
import java.io.File;
import java.time.LocalDateTime;
import com.syncfusion.docio.*;
public class Compare {
public static void main(String[] args) throws Exception {
//Load the original document.
WordDocument originalDocument = new WordDocument(getDataDir("OriginalDocument.docx"), FormatType.Docx);
//Load the revised document.
WordDocument revisedDocument = new WordDocument(getDataDir("RevisedDocument.docx"), FormatType.Docx);
//Compare the original document with the revised document.
originalDocument.compare(revisedDocument, "Nancy Davolio", LocalDateTime.now().minusDays(1));
//Save the word document.
originalDocument.save("Sample.docx");
//Close the word documents.
originalDocument.close();
revisedDocument.close();
System.out.println("Word document generated successfully.");
}
/**
* Get the file path
*
* @param path specifies the file path
*/
public static String getDataDir(String path) {
File dir = new File(System.getProperty("user.dir"));
if (!(dir.toString().endsWith("samples")))
dir = dir.getParentFile();
dir = new File(dir, "resources");
dir = new File(dir, path);
if (dir.isDirectory() == false)
dir.mkdir();
return dir.toString();
}
}