修改标题获取
This commit is contained in:
@@ -462,7 +462,22 @@ public class BookServiceImpl extends ServiceImpl<BookDao, BookEntity> implements
|
|||||||
BookEntity bookEntity = this.getBaseMapper().selectById(bookId);
|
BookEntity bookEntity = this.getBaseMapper().selectById(bookId);
|
||||||
String novel = bookEntity.getNovel();
|
String novel = bookEntity.getNovel();
|
||||||
InputStream inputStream = FileDownloadUtil.getInputStream(novel);
|
InputStream inputStream = FileDownloadUtil.getInputStream(novel);
|
||||||
XWPFDocument document = new XWPFDocument(inputStream);
|
InputStream inputStreamCopy = FileDownloadUtil.getInputStream(novel);
|
||||||
|
List heading1Llist = new ArrayList();
|
||||||
|
List heading2Llist = new ArrayList();
|
||||||
|
Document doc = new Document(inputStream);
|
||||||
|
for (int i = 0; i < doc.getSections().getCount(); i++) {
|
||||||
|
Section section = doc.getSections().get(i);
|
||||||
|
for (int j = 0; j < section.getParagraphs().getCount() - 1; j++) {
|
||||||
|
Paragraph paragraph = section.getParagraphs().get(j);
|
||||||
|
if (StringUtils.isNotBlank(paragraph.getText())&¶graph.getStyleName().equals("Heading1")) {
|
||||||
|
heading1Llist.add(paragraph.getText());
|
||||||
|
}else if (StringUtils.isNotBlank(paragraph.getText())&¶graph.getStyleName().equals("Heading2")){
|
||||||
|
heading2Llist.add(paragraph.getText());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
XWPFDocument document = new XWPFDocument(inputStreamCopy);
|
||||||
// 遍历文档中的所有元素(段落和表格)
|
// 遍历文档中的所有元素(段落和表格)
|
||||||
List<IBodyElement> bodyElements = document.getBodyElements();
|
List<IBodyElement> bodyElements = document.getBodyElements();
|
||||||
String chapterName = "";
|
String chapterName = "";
|
||||||
@@ -474,7 +489,7 @@ public class BookServiceImpl extends ServiceImpl<BookDao, BookEntity> implements
|
|||||||
XWPFParagraph paragraph = (XWPFParagraph) element;
|
XWPFParagraph paragraph = (XWPFParagraph) element;
|
||||||
String text = paragraph.getText();
|
String text = paragraph.getText();
|
||||||
if (text != null && !text.isEmpty()) {//处理段落或正文
|
if (text != null && !text.isEmpty()) {//处理段落或正文
|
||||||
if (paragraph.getRuns().get(0).getFontSize()>=topText){//判断是否是顶级标题
|
if (heading1Llist.contains(text)||paragraph.getRuns().get(0).getFontSize()>=topText){//判断是否是顶级标题
|
||||||
chapterName = text;
|
chapterName = text;
|
||||||
BookChapterEntity bookChapter = new BookChapterEntity();
|
BookChapterEntity bookChapter = new BookChapterEntity();
|
||||||
bookChapter.setBookId(bookId);
|
bookChapter.setBookId(bookId);
|
||||||
@@ -493,7 +508,7 @@ public class BookServiceImpl extends ServiceImpl<BookDao, BookEntity> implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else if (paragraph.getRuns().get(0).getFontSize()>=secText){//判断是否是二级标题
|
}else if (heading2Llist.contains(text)||paragraph.getRuns().get(0).getFontSize()>=secText){//判断是否是二级标题
|
||||||
if (StringUtils.isNotBlank(chapterName)){
|
if (StringUtils.isNotBlank(chapterName)){
|
||||||
BookChapterEntity bookChapter = new BookChapterEntity();
|
BookChapterEntity bookChapter = new BookChapterEntity();
|
||||||
bookChapter.setBookId(bookId);
|
bookChapter.setBookId(bookId);
|
||||||
|
|||||||
Reference in New Issue
Block a user