summaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/com/mavlushechka/quiz/App.java41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/main/java/com/mavlushechka/quiz/App.java b/src/main/java/com/mavlushechka/quiz/App.java
new file mode 100644
index 0000000..d83d810
--- /dev/null
+++ b/src/main/java/com/mavlushechka/quiz/App.java
@@ -0,0 +1,41 @@
+package com.mavlushechka.quiz;
+
+import java.io.FileInputStream;
+import java.io.FileWriter;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.poi.openxml4j.opc.OPCPackage;
+import org.apache.poi.xwpf.usermodel.IBodyElement;
+import org.apache.poi.xwpf.usermodel.XWPFDocument;
+import org.apache.poi.xwpf.usermodel.XWPFTable;
+
+public class App {
+ public static void main(String[] args) throws Exception {
+ FileInputStream fis = new FileInputStream("src/main/resources/test.docx");
+ FileWriter fw = new FileWriter("src/main/resources/test.txt", false);
+ XWPFDocument xdoc = new XWPFDocument(OPCPackage.open(fis));
+ Iterator<IBodyElement> bodyElementIterator = xdoc.getBodyElementsIterator();
+
+ while (bodyElementIterator.hasNext()) {
+ IBodyElement element = bodyElementIterator.next();
+
+ if ("TABLE".equalsIgnoreCase(element.getElementType().name())) {
+ List<XWPFTable> tableList = element.getBody().getTables();
+
+ for (XWPFTable table : tableList) {
+ for (int i = 0; i < table.getRows().size(); i++) {
+ if (i > 0 && i < 5) {
+ fw.write((char) (64 + i) + ". ");
+ }
+ for (int j = 0; j < table.getRow(i).getTableCells().size(); j++) {
+ fw.write(table.getRow(i).getCell(j).getText());
+ }
+ fw.write(i == 0 ? "?\n" : "\n");
+ }
+ fw.write("ANSWER: A\n\n");
+ }
+ }
+ }
+ }
+}