main
黄海 8 months ago
parent b938d72d0b
commit c8ba0ff5cb

@ -1,6 +1,7 @@
package com.dsideal.base.Test;
import cn.hutool.core.io.FileUtil;
import com.jfinal.kit.StrKit;
import org.apache.commons.io.FileUtils;
import org.dom4j.Document;
import org.dom4j.DocumentException;
@ -61,25 +62,39 @@ public class ReadWordTOC {
for (Element child : children) {
if (child.getName().equals("p")) {
// if (child.element("pPr") == null) continue;
// if (child.element("pPr").element("rPr") == null) continue;
// if (child.element("pPr").element("rPr").element("rFonts") == null) continue;
//
// String font = child.element("pPr").element("rPr").element("rFonts").attribute("ascii").getValue();
// //子元素需要继续处理
// if (font.equals("方正仿宋简体")) continue;
// if (font.equals("华文楷体")) continue;
//
// if (child.element("pPr").element("rPr").element("sz") != null) {
// int fontSize = Integer.parseInt(child.element("pPr").element("rPr").element("sz").attribute("val").getValue());
// if (fontSize != 32) continue;
// }
List<Element> pChildren = child.elements();
boolean isBookmark = false;
String content = "";
for (Element pChild : pChildren) {
if (pChild.getName().equals("bookmarkStart")) {
isBookmark = true;
}
if (isBookmark && !pChild.getName().equals("bookmarkStart") && !pChild.getName().equals("bookmarkEnd")) {
if (!pChild.getName().equals("pPr")) {
if (pChild.getName().equals("r")) {
for (Element t : pChild.elements("t")) {
//此元素的字体与字号,同受它同级上面<rPr>的<rFonts>属性ascii控制
String font = pChild.element("rPr").element("rFonts").attribute("ascii").getValue();
if (font.equals("方正仿宋简体")) continue;
if (font.equals("华文楷体")) continue;
int fontSize = Integer.parseInt(pChild.element("rPr").element("sz").attribute("val").getValue());
if (fontSize != 32) continue;
content = content + t.getText();
}
}
}
if (pChild.getName().equals("bookmarkEnd")) {
isBookmark = false;
System.out.println(content);
}
}
if (!StrKit.isBlank(content))
System.out.println(content);
}
}
}

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save