当前位置: 首页 > news >正文

做婚纱摄影网站价格wordpress 文章翻页

做婚纱摄影网站价格,wordpress 文章翻页,重庆做网站团队,网站建设创业基础ppt模板apache poi_5.2.5 实现对表格单元格的自定义变量名进行图片替换 实现思路 1.首先定位到自定义变量名 2.然后先清除自定义变量名#xff0c;可利用setText(null,0)来清除 3.在自定义变量名的位置添加图片#xff0c;使用下面的代码 4.对于图片布局有要求的#xff0c;利用C…apache poi_5.2.5 实现对表格单元格的自定义变量名进行图片替换 实现思路 1.首先定位到自定义变量名 2.然后先清除自定义变量名可利用setText(null,0)来清除 3.在自定义变量名的位置添加图片使用下面的代码 4.对于图片布局有要求的利用CTAnchor进行实现 addNewWrapNone;//根据setBehindDoc来确定浮于文字上方还是下方 addNewWrapSquare;//四周型布局 【注默认是嵌入型文字会遮挡部分图片。】 依赖包 dependencygroupIdorg.apache.poi/groupIdartifactIdpoi/artifactIdversion5.2.5/version/dependencydependencygroupIdorg.apache.poi/groupIdartifactIdpoi-ooxml/artifactIdversion5.2.5/version/dependencydependencygroupIdorg.apache.poi/groupIdartifactIdpoi-scratchpad/artifactIdversion5.2.5/version/dependency代码实现 public static void main(String[] args) throws Exception {String wenshuUrl D:\\demo1.docx;File file new File(wenshuUrl);byte[] bytes Files.readAllBytes(Paths.get(file.toURI()));ByteArrayInputStream in new ByteArrayInputStream(bytes);XWPFDocument doc new XWPFDocument(in);String pic D:\\demo1.png;File file2 new File(pic);byte[] bytes2 Files.readAllBytes(Paths.get(file2.toURI()));ByteArrayInputStream bis2 new ByteArrayInputStream(bytes2);for (int i 0; i doc.getTables().size(); i) {for (int rowIndex 0; rowIndex doc.getTables().get(i).getRows().size(); rowIndex) {XWPFTableRow row doc.getTables().get(i).getRow(rowIndex);row.getTableCells().stream().forEach(cell - {for (XWPFParagraph paragraph : cell.getParagraphs()) {ListXWPFRun runs paragraph.getRuns();for (XWPFRun run : runs) {try {addPicture(run, bis2,pic,500,400);} catch (InvalidFormatException e) {throw new RuntimeException(e);} catch (IOException e) {throw new RuntimeException(e);} catch (SAXException e) {throw new RuntimeException(e);} catch (XmlException e) {throw new RuntimeException(e);}}}});}}OutputStream output new FileOutputStream(D:\\afteradd1.doc);doc.write(output);output.close();}/*** 添加图片布局环绕模式* param run* param stream 图片流* param filename 文件路径* param width 图片的宽度* param height 图片的高度*/private static void addPicture(XWPFRun run, InputStream stream, String filename, int width, int height ) throws InvalidFormatException, IOException, SAXException, XmlException {run.addPicture(stream, getPictureTypeByFileName(filename), filename, Units.toEMU(width), Units.toEMU(height));CTDrawing drawing run.getCTR().getDrawingArray(0);CTGraphicalObject graphicalObject drawing.getInlineArray(0).getGraphic();//这个是relationId即图片位置的idlong id drawing.getInlineArray(0).getDocPr().getId();//设置一个浮动模式CTAnchor anchor drawing.addNewAnchor();//创建一个包含浮动模式的xml字符串String xml a:graphic xmlns:a\ CTGraphicalObject.type.getName().getNamespaceURI() \a:graphicData uri\ CTPicture.type.getName().getNamespaceURI() \pic:pic xmlns:pic\ CTPicture.type.getName().getNamespaceURI() \ //a:graphicData/a:graphic;//将xml字符串转换为InputSource对象InputSource is new InputSource(new StringReader(xml));//生成Document对象用于将Document doc DocumentHelper.readDocument(is);anchor.set(XmlToken.Factory.parse(doc.getDocumentElement(),DEFAULT_XML_OPTIONS));//设置浮动位置0表示紧贴文字anchor.setDistT(0L);anchor.setDistR(0L);anchor.setDistB(0L);anchor.setDistL(0L);anchor.setLocked(false);anchor.setLayoutInCell(true);anchor.setSimplePos2(false);anchor.setAllowOverlap(true);anchor.setRelativeHeight(0);//图片的布局环绕模式anchor.addNewWrapSquare();CTPosH ctPosH anchor.addNewPositionH();//STRelFromH 水平方向的位置相对于谁进行调整 character文字ctPosH.setRelativeFrom(STRelFromH.CHARACTER);//调整水平方向的位置从左往右递增0代表紧贴文字ctPosH.setPosOffset( Units.toEMU(0));CTPosV ctPosV anchor.addNewPositionV();//STRelFromV 垂直方向的位置相对于谁进行调整 PARAGRAPH字段ctPosV.setRelativeFrom(STRelFromV.PARAGRAPH);//调整垂直方向的位置从上往下数值递增ctPosV.setPosOffset( Units.toEMU(-10));CTPoint2D ctPoint2D anchor.addNewSimplePos();ctPoint2D.setX(0);ctPoint2D.setY(0);anchor.addNewCNvGraphicFramePr();CTNonVisualDrawingProps docPr anchor.addNewDocPr();docPr.setId(id);docPr.setName(Drawing id);docPr.setDescr(filename);CTPositiveSize2D extent anchor.addNewExtent();extent.setCx(Units.toEMU(width));extent.setCy(Units.toEMU(height));anchor.setGraphic(graphicalObject);//添加浮动属性drawing.setAnchorArray(new CTAnchor[]{anchor});//删除行内属性drawing.removeInline(0);}public static int getPictureTypeByFileName(String fileName) {if (StringUtils.isEmpty(fileName)) {throw new RuntimeException(文件名称不能为空);}String suffix fileName.substring(fileName.lastIndexOf(.));switch (suffix) {case .jpg:case .jpeg:return XWPFDocument.PICTURE_TYPE_JPEG;case .wmf:return XWPFDocument.PICTURE_TYPE_WMF;case .png:case .PNG:return XWPFDocument.PICTURE_TYPE_PNG;case .gif:return XWPFDocument.PICTURE_TYPE_GIF;case .tiff:return XWPFDocument.PICTURE_TYPE_TIFF;case .bmp:return XWPFDocument.PICTURE_TYPE_BMP;default:throw new RuntimeException(不支持的文件类型 suffix);}}
http://www.yutouwan.com/news/177684/

相关文章:

  • 德阳建设局网站wordpress虚拟币接口
  • 做健身推广网站站酷设计网站官
  • 第一百四十七章 做视频网站笑话网站开发
  • 家庭宽带怎么做网站小微企业注册流程及费用
  • 网站开发用到的技术注册深圳公司代理记账报税
  • 做影片的网站描述程序界面设计
  • 营销型网站可以吗网站建设费用推荐网络专业
  • 宣城网站开发专业制重庆房地产新闻
  • 网站开发 技术问题南沙滩做网站公司
  • 网页网站开发公司怎样加入装修接单网站
  • 专业网站建设公司哪个公司好聊天软件哪个最火
  • 网站建设创业经历百度搜索网站
  • 河北省建设厅网站老版大连seo排名优化
  • php做网站导购模板哪些网站有友情链接
  • 网站全屏宽度是多少合适性价比最高网站建设
  • 哈尔滨网站建设哪个好动画视频制作软件app
  • 平乡网站建设外贸网站建设模版
  • 网站域名绑定破解网站建设启动大会
  • 门户网站建设管理工作方案网站建设对于企业发展的优势
  • 域名cn是个什么网站永久免费不收费的软件app
  • 网站做可信认证多少钱北京天仪建设工程质量检测所网站6
  • 网站建设1993seo网站的网页设计毕业设计
  • 郑州网站推广优化报价网站建设文献综述知乎
  • 汉阴县住房和城乡建设局网站wordpress能放几个域名
  • 北京营销网站制作wordpress利用视频引流
  • 如何建立网站管理系统六安先锋网
  • 比特币交易网站可以做空吗甘肃省城乡与住房建设厅网站
  • jsp制作网站wordpress调用电话
  • 做两个网站 之间超链接wordpress the_tag
  • 天水网站制作公司wordpress搬家到本地