java poi读取word中附件_Java POI导入word, 带图片

1.导入文件示例,word中简历表格模板

2.代码示例分两部分,一部分读取图片

/**

* 导入word(基本信息,word格式)

* @param staffId

* @param baseInfoFile

*/

void importStaffInfo(Integer staffId, MultipartFile file);

-- 读取图片

InputStream inputStream =baseInfoFile.getInputStream();

XWPFDocument doc= newXWPFDocument(inputStream);//一:读取word中的照片 docx,把得到的data写入你要写入的文件

List allPictures =doc.getAllPictures();for(XWPFPictureData picture : allPictures) {byte[] data =picture.getData();

String oriFileName=picture.getFileName();

// 自己定义需要写入的文件地址

String targetPath= ymlConfig.getHeadImagePath() + staffId + oriFileName.substring(oriFileName.lastIndexOf("."));

File targetFile= newFile(targetPath);if (!targetFile.exists()) {if (!targetFile.getParentFile().exists()) {

targetFile.getParentFile().mkdirs();

}

targetFile.createNewFile();

}

FileOutputStream out= newFileOutputStream(targetFile);

out.write(data);

out.close();}

-- 读取表格信息

Iterator it = doc.getTablesIterator();

// 过滤前面不需要的表格

if (it.hasNext()) {

it.next();

}

// 得到需要的第二个表格,业务数据

if (it.hasNext()) {

XWPFTable xwpfTable = it.next();

// 读取每一行

for (int i = 0; i < xwpfTable.getRows().size(); i++) {

XWPFTableRow row = xwpfTable.getRow(i);

if (row != null) {

//根据模板读取需要的数据单元格,从第二列开始读取

for (int j = 1; j < row.getTableCells().size(); j++) {

XWPFTableCell cell = row.getCell(j);

if (cell != null) {

String cellText = cell.getText();

System.out.println();

}

}

}

}

}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/441751.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

如何将文件拷贝服务器上,如何将文件复制到云服务器上

如何将文件复制到云服务器上 内容精选换一换将文件上传至Windows云服务器一般会采用MSTSC远程桌面连接的方式。本节为您介绍本地Windows计算机通过远程桌面连接&#xff0c;上传文件至Windows云服务器的操作方法。Windows云服务器可以访问公网。在本地Windows计算机上&#xff…

mysql5.7解压版错误_mysql 5.7 解压版 安装net start mysql 发生系统错误 2

1.配置环境变量 用户变量path 添加 mysql 安装目录2.新建my.ini文件 放到E:\mysql-5.7.24-winx64安装目录下[mysqld]port 3306basedirC:/software/mysql-5.7.21-winx64datadirC:/software/mysql-5.7.21-winx64/datamax_connections200character-set-serverutf8default-storage…

【HDU - 2553】N皇后问题 (dfs经典问题,回溯,搜索)

题干&#xff1a; 在N*N的方格棋盘放置了N个皇后&#xff0c;使得它们不相互攻击&#xff08;即任意2个皇后不允许处在同一排&#xff0c;同一列&#xff0c;也不允许处在与棋盘边框成45角的斜线上。 你的任务是&#xff0c;对于给定的N&#xff0c;求出有多少种合法的放置方…

浪潮服务器建立虚拟驱动器,像《十二时辰》一样去建立标准! 浪潮这款服务器做到了...

原标题&#xff1a;像《十二时辰》一样去建立标准&#xff01; 浪潮这款服务器做到了这个夏天&#xff0c;《长安十二时辰》制霸屏幕开画至今豆瓣评分达到8.8分现已成功“出海”在Amazon、Youtube、Viki付费上线成为唐风古韵的又一风向标现如今&#xff0c;越洋的标准可不止悠悠…

【HDU - 5918 】Sequence I (数组(字符串)匹配问题,可选KMP)

题干&#xff1a; Mr. Frog has two sequences a1,a2,⋯,ana1,a2,⋯,an and b1,b2,⋯,bmb1,b2,⋯,bm and a number p. He wants to know the number of positions q such that sequence b1,b2,⋯,bmb1,b2,⋯,bm is exactly the sequence aq,aqp,aq2p,⋯,aq(m−1)paq,aqp,aq2p,…

mysql_fetch_bit_mysql_fetch_array()

mysql_fetch_array()(PHP 4, PHP 5)从结果集中取得一行作为关联数组&#xff0c;或数字数组&#xff0c;或二者兼有说明mysql_fetch_array(resource$result[,int$ result_type]):array返回根据从结果集取得的行生成的数组&#xff0c;如果没有更多行则返回FALSE。mysql_fetch_a…

【HDU - 5916】Harmonic Value Description (构造,思维,SJ题)

题干&#xff1a; The harmonic value of the permutation p1,p2,⋯pnp1,p2,⋯pn is ∑i1n−1gcd(pi.pi1)∑i1n−1gcd(pi.pi1) Mr. Frog is wondering about the permutation whose harmonic value is the strictly k-th smallest among all the permutations of [n]. Inpu…

在python中、对于函数定义代码的理解_python中如何理解装饰器代码?

长文预警&#xff0c;【最浅显易懂的装饰器讲解】能不能专业地复制题目&#xff1f;配上代码&#xff0c;问题分段。我来给提主配上问题的代码。正式回答&#xff1a;1&#xff1a;如何理解return一个函数&#xff0c;它与return一个值得用法区别在哪&#xff1f;敲黑板&#x…

【AtCoder - 2554】Choose Integers (找规律,或枚举)

题干&#xff1a; Problem Statement We ask you to select some number of positive integers, and calculate the sum of them. It is allowed to select as many integers as you like, and as large integers as you wish. You have to follow these, however: each sele…

1m带宽可以做mysql数据库吗_服务器的1M带宽够用吗?1M网速是多少?

1M是什么&#xff1f;通常&#xff0c;在计算机中1M表示的是计算机的内存容量&#xff0c;即1M1024KB。但有不同的含义&#xff0c;云服务器中1M表示服务器的带宽&#xff0c;即1M带宽。在服务器中1M带宽够用吗&#xff1f;云服务器的1兆网速是多少&#xff1f;首先把云服务器带…

【POJ - 2318】TOYS(计算几何,叉积判断点与直线位置关系,二分)

题干&#xff1a; Calculate the number of toys that land in each bin of a partitioned toy box. Mom and dad have a problem - their child John never puts his toys away when he is finished playing with them. They gave John a rectangular box to put his toys i…

esp32 micropython spiffs_spiffs 文件系统在esp32中的应用

spiffs 介绍SPIFFS 是一个开源文件系统&#xff0c;用于 SPI NOR flash 设备的嵌入式文件系统&#xff0c;支持磨损均衡、文件系统一致性检查等功能。spiffs 源码地址​github.comspiffs 特点而我们知道乐鑫的esp32的大部分存储都依赖于SPI flash &#xff0c;spiffs可以说对于…

【HDU - 1968】【UVA - 12096】The SetStack Computer (模拟,集合求交集并集操作,STL实现)

题干&#xff1a; Background from Wikipedia: 揝et theory is a branch of mathematics created principally by the German mathematician Georg Cantor at the end of the 19th century. Initially controversial, set theory has come to play the role of a foundational…

info testing mysql_SQLMASQLMAP中文说明(linux版本)

这个东西&#xff0c;是mickey整理的&#xff0c;不多说了&#xff0c;尊重一下原作者&#xff0c;转载注明mickey整理就好了更新svn checkout https://svn.sqlmap.org/sqlmap/trunk/sqlmap sqlmap-devsqlmap.py -u "http://www.islamichina.com/hotelinchina.asp?cityid…

关于C++里面使用set_union,set_intersections、set_merge、set_difference、set_symmetric_difference等函数的使用总结

set里面有set_intersection&#xff08;取集合交集&#xff09;、set_union&#xff08;取集合并集&#xff09;、set_difference&#xff08;取集合差集&#xff09;、set_symmetric_difference&#xff08;取集合对称差集&#xff09;等函数。其中&#xff0c;关于函数的五个…

java mouseenter_关于事件mouseover ,mouseout ,mouseenter,mouseleave的区别

最近在做的在线考试和课程商城都遇到这样的问题&#xff1a;就是鼠标滑过的时候出现一个层&#xff0c;当鼠标滑到当前层的话mouseover和mouseout在低版本的浏览器会出现闪动的现象&#xff0c;解决这个现象的办法有许多&#xff0c;不过我觉得有一种是最简单的那就是把mouseov…

【HDU - 1465 】不容易系列之一 (组合数学,错排)

题干&#xff1a; 大家常常感慨&#xff0c;要做好一件事情真的不容易&#xff0c;确实&#xff0c;失败比成功容易多了&#xff01; 做好“一件”事情尚且不易&#xff0c;若想永远成功而总从不失败&#xff0c;那更是难上加难了&#xff0c;就像花钱总是比挣钱容易的道理一…

java gc回收机制种类_JAVA的垃圾回收机制(GC)

1.什么是垃圾回收&#xff1f;垃圾回收(Garbage Collection)是Java虚拟机(JVM)垃圾回收器提供的一种用于在空闲时间不定时回收无任何对象引用的对象占据的内存空间的一种机制。2.什么时候垃圾回收&#xff1f;System.gc()Runtime.getRuntime().gc()上面的方法调用时用于显式通知…

【HDU - 4217 】Data Structure? (线段树求第k小数)

题干&#xff1a; Data structure is one of the basic skills for Computer Science students, which is a particular way of storing and organizing data in a computer so that it can be used efficiently. Today let me introduce a data-structure-like problem for y…

java redis 重连_突破Java面试(23-4) - Redis 复制原理

全是干货的技术号&#xff1a;本文已收录在github&#xff0c;欢迎 star/fork&#xff1a;在Redis复制的基础上(不包括Redis Cluster或Redis Sentinel作为附加层提供的高可用功能)&#xff0c;使用和配置主从复制非常简单&#xff0c;能使得从 Redis 服务器(下文称 slave)能精确…