20211220

阅读: 评论:0

20211220

20211220

读取word文档中的文字

  • 代码

代码


import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.usermodel.CharacterRun;
import org.apache.poi.hwpf.usermodel.Paragraph;
import org.apache.poi.hwpf.usermodel.Range;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.actor.XWPFWordExtractor;
import org.apache.poi.xwpf.usermodel.XWPFDocument;import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.*;
import Matcher;
import Pattern;
import java.util.stream.Collectors;public class Duilie {public static void main(String[] args) {try {//文件输入流InputStream is = new FileInputStream(new File("D:\文件\工作记录.docx"));//创建一个文本XWPFDocument xwpfDocument = new XWPFDocument(is);//从OOXML读取数据XWPFWordExtractor xwpfWordExtractor = new XWPFWordExtractor(xwpfDocument);//从文档中读出字符串String text = Text();//只匹配文章中的汉字String regEx = "[\u4E00-\u9FA5\uf900-\ufa2d]";Pattern compile = Patternpile(regEx);Matcher matcher = compile.matcher(text);List<String> list = new ArrayList<>();//每个字符写到集合中while(matcher.find()){String group = up();list.add(group);}//统计每个字出现的次数HashMap<String,Integer>  map = new HashMap<>();for(String str : list){ainsKey(str)){Integer integer = (str);integer = integer+1;map.put(str,integer);}else{map.put(str,1);}}//给出现的个数排序List<Node> nodeList = new ArrayList<>();for(Map.Entry<String,Integer> entry : Set()){String key = Key();Integer value = Value();Node node = new Node(value,key);nodeList.add(node);}List<Node> sortList = nodeList.stream().sorted(Comparatorparing(Node::getCount)).List());List<List<Object>> content = new ArrayList<>();for(Node node : sortList){List<Object> collist = new ArrayList<>();collist.Str()+":"&#Count());content.add(collist);System.out.Str()+":"&#Count());}Excel(content,"字符统计");} catch (Exception e) {e.printStackTrace();}}}

本文发布于:2024-01-31 09:11:16,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170666347927439.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23