相关文章推荐
礼貌的高山  ·  spring-boot +data ...·  11 月前    · 
豁达的熊猫  ·  JS跨域解决方案 - ...·  1 年前    · 
爱看球的伤疤  ·  vue.js - vuejs plugin ...·  1 年前    · 
害羞的海龟  ·  ORACLE基础知识2 - 知乎·  1 年前    · 
宽容的凉茶  ·  Android R ...·  1 年前    · 
* imgpath:图片存放路径 public static void doPPTtoImage(HttpServletRequest request,String filepath,String sourceid) throws TransformerException { String htmlname="exportPpt"+sourceid+".html"; String path =request.getSession().getServletContext().getRealPath("/view/ppt"); fileExists(path); String imgpath =request.getSession().getServletContext().getRealPath("/view/ppt/images"); fileExists(imgpath); String filename=request.getSession().getServletContext().getRealPath("/vod/mp4"); // 读入PPT文件 File file = new File(filename+"/"+filepath); boolean isppt = checkFile(file); if (!isppt) { System.out.println("The image you specify don't exit!"); try { FileInputStream is = new FileInputStream(file); SlideShow ppt = new SlideShow(is); is.close(); Dimension pgsize = ppt.getPageSize(); org.apache.poi.hslf.model.Slide[] slide = ppt.getSlides(); FileOutputStream out =null; String imghtml=""; for (int i = 0; i < slide.length; i++) { System.out.print("第" + i + "页。"); TextRun[] truns = slide[i].getTextRuns(); for ( int k=0;k



"; DOMSource domSource = new DOMSource(); StreamResult streamResult = new StreamResult(out); TransformerFactory tf = TransformerFactory.newInstance(); Transformer serializer = tf.newTransformer(); serializer.setOutputProperty(OutputKeys.ENCODING, "utf-8"); serializer.setOutputProperty(OutputKeys.INDENT, "yes"); serializer.setOutputProperty(OutputKeys.METHOD, "html"); serializer.transform(domSource, streamResult); out.close(); String ppthtml=""+imghtml+""; FileUtils.writeStringToFile(new File(path, htmlname), ppthtml, "utf-8"); } catch (FileNotFoundException e) { System.out.println(e); // System.out.println("Can't find the image!"); } catch (IOException e) { // function 检查文件是否为PPT public static boolean checkFile(File file) { boolean isppt = false; String filename = file.getName(); String suffixname = null; if (filename != null && filename.indexOf(".") != -1) { suffixname = filename.substring(filename.indexOf(".")); if (suffixname.equals(".ppt")||suffixname.equals(".pptx")) { isppt = true; return isppt; } else { return isppt; * ppt07转html * filename:要读取的文件所在文件夹 * filepath:文件名 * htmlname:生成html名称 * path:html存放路径 * imgpath:图片存放路径 public static void pptTohtml07(HttpServletRequest request,String filepath,String sourceid) throws IOException, TransformerException{ String htmlname="exportPpt"+sourceid+".html"; String path=request.getSession().getServletContext().getRealPath("/view/ppt"); fileExists(path); String imgpath =request.getSession().getServletContext().getRealPath("/view/ppt/images"); fileExists(imgpath); String filename=request.getSession().getServletContext().getRealPath("/vod/mp4"); File file = new File(filename+"/"+filepath); boolean isppt = checkFile(file); if (!isppt) { System.out.println("The image you specify don't exit!"); FileInputStream is = new FileInputStream(file); XMLSlideShow ppt = new XMLSlideShow(is); is.close(); Dimension pgsize = ppt.getPageSize(); System.out.println(pgsize.width+"--"+pgsize.height); XSLFSlide[] pptPageXSLFSLiseList=ppt.getSlides(); FileOutputStream out=null; String imghtml=""; for (int i = 0; i < pptPageXSLFSLiseList.length; i++) { try { for(XSLFShape shape : pptPageXSLFSLiseList[i].getShapes()){ if(shape instanceof XSLFTextShape) { XSLFTextShape tsh = (XSLFTextShape)shape; for(XSLFTextParagraph p : tsh){ for(XSLFTextRun r : p){ r.setFontFamily("宋体"); BufferedImage img = new BufferedImage(pgsize.width, pgsize.height, BufferedImage.TYPE_INT_RGB); Graphics2D graphics = img.createGraphics(); // clear the drawing area graphics.setPaint(Color.white); graphics.fill(new Rectangle2D.Float(0, 0, pgsize.width, pgsize.height)); // render pptPageXSLFSLiseList[i].draw(graphics); String Imgname = imgpath +"/"+ (i+1) + ".jpg"; out = new FileOutputStream(Imgname); javax.imageio.ImageIO.write(img, "jpg", out); //图片在html加载路径 String imgs="images/"+(i + 1) + ".jpg"; imghtml+="



"; } catch (Exception e) { System.out.println(e); System.out.println("第"+i+"张ppt转换出错"); System.out.println("7success"); DOMSource domSource = new DOMSource(); StreamResult streamResult = new StreamResult(out); TransformerFactory tf = TransformerFactory.newInstance(); Transformer serializer = tf.newTransformer(); serializer.setOutputProperty(OutputKeys.ENCODING, "utf-8"); serializer.setOutputProperty(OutputKeys.INDENT, "yes"); serializer.setOutputProperty(OutputKeys.METHOD, "html"); serializer.transform(domSource, streamResult); out.close(); String ppthtml=""+imghtml+""; FileUtils.writeStringToFile(new File(path, htmlname), ppthtml, "utf-8");
今天比较忙,就不贴结果图了。。。 poi操作ppt转html由于ppt都是由一页一页图片组成,所以ppt要先转成图片在放入html页面 /** * ppt03转html * filename:要读取的文件所在文件夹 * filepath:文件名 * htmlname:生成html名称 * path:html存放路径 * imgpath:图片存放路径
把jacob.jar加载到工程里。 在C:\WINDOWS\system32;C:\Program Files\ Java \jdk1.5.0_04\bin;C:\Program Files\ Java \jdk1.5.0_04\jre\bin;下添加jacob.dll文件。 OfficeToXML. java 文件是 实现 代码。 我自己工程用到的代码,现共享出来给大家!
心比天高,仗剑走天涯,保持热爱,奔赴向梦想!低调,谦虚,自律,反思,成长,还算是比较正能量的博主,公益免费传播……内心特别想在AI界做出一些可以推进历史进程影响力的东西(兴趣使然,有点小情怀,也有点使命感呀)…… 09-23 https://blog.csdn.net/yjclsx/article/details/51441632 https://blog.csdn.net/qq_369 03 131/article/details/82529676 直接上代码了: package com.allen.utils; import java .awt.Color; import java .awt... - -之 poi 实现 word、excel、 ppt html ###简介 java 实现 在线 预览 功能是一个大家在工作中也许会遇到的需求,如果公司有钱,直接使用付费的第三方软件或者云 在线 预览 服务就可以了,例如永中office、office web 365(http://www.officeweb365.com/)他们都有云 在线 预览 服务,就是要钱0.0 如果想要免费的,可以用openoffice,还需要借助其他的工具(例如swfTools、FlexPaper等)才行,可参考这篇文章http://
使用jacob时,把dll放到window/system32下就成,不需要注册  1、如果出现下面的错误     com.jacob.com.ComFailException: A COM exception has been encountered:     At Invoke of: Version     Description: An unknown COM error has o
PPT Html 5(带动画,自动发布Nginx,支持大文件拆分) 为什么要将 PPT Html 5 众所周知, PPT 常用于会议演示、教学演示等应用场景,常用的载体有office,wps等,这些基本可以满足我们日常工作需要。但对于有深层次需求的个人或企业,需要在自有平台上展示 PPT ,又需要保护 PPT 不被盗用,又需要保留 PPT 原有动画,这时候常规的office或wps就无法直接对接到平台。因此,需要通过编程的方式,将 PPT 转换 Html 5。 1、 java 环境 2、Python环境 3、Nginx环境
要在 Java 中使用Apache POI 将Excel 转换 HTML 并含图片,你可以使用Apache POI 和ApacheI-OOXML依赖项来完成此 操作 下面是一个简单的示例代码: import org.apache. poi .ss.usermodel.*; import org. poi .xssf.usermodel.XSSFWorkbook; import org.apache. poi .xssf.usermodel.XSSFPictureData; import java .io.*; import.util.Base64; public ExcelTo Html Converter { static void main(String[] args) try { //读取Excel文件 fileInputStream = new FileInputStream("input.xlsx"); Workbook workbook = new XSSFWorkbook(fileInputStream); Sheet sheet = workbook.getSheetAt(0); // 创建 HTML 输出流 FileOutputStream fileOutputStream = new FileOutputStream("output. html "); PrintWriter printWriter = new PrintWriter(fileOutputStream); // 输出 HTML 头部 printWriter.println("<!DOCTYPE html >"); printWriter.println("< html >"); printWriter.println("<head>"); printWriter.println("<title>Excel to HTML </title>"); printWriter.println("</head>"); printWriter.println("<body>"); // 遍历每行 for (Row row : sheet) { printWriter.println("<tr>"); // 遍历每个单元格 for (Cell cell : row) { printWriter.print("<td>"); // 获取单元格内容 CellType cellType = cell.getCellType(); if (cellType == CellType.STRING) { printWriter.print(cell.getStringCellValue()); } else if (cellType == CellType.NUMERIC) { printWriter.print(cell.getNumericCellValue()); } else if (cellType == CellType.BOOLEAN) { printWriter.print(cell.getBooleanCellValue()); // 检查单元格是否包含图片 if (cell instanceof XSSFSheet) { XSSFSheet xssfSheet = (XSSFSheet) sheet; for ( POI XMLDocumentPart part : xssfSheet.getRelations()) { if (part instanceof XSSFPictureData) { XSSFPictureData pictureData = (XSSFPictureData) part; String base64Image = Base64.getEncoder().encodeToString(pictureData.getData()); printWriter.print("<img src=\"data:image/png;base64," + base64Image + "\"/>"); printWriter.println("</td>"); printWriter.println("</tr>"); // 输出 HTML 尾部 printWriter.println("</body>"); printWriter.println("</ html >"); printWriter.close(); System.out.println("Excel 转换 HTML 成功!"); } catch (IOException e) { e.printStackTrace(); 此代码将读取名为input.xlsx的Excel文件,并将其 转换 为output. html HTML 文件。在 HTML 中,它将遍历每个单元格并将其内容输出为 HTML 表格。如果单元格包含图片,它将使用Base64编码将图片嵌入到 HTML 中。 请注意,此代码仅处理XLSX格式的Excel文件。如果你的文件是XLS格式,你需要使用HSSFWorkbook和HSSFPictureData来进行处理。 希望这可以帮助到你!
public static void getDataFromExcel(String filePath) throws IOException //String filePath = "E:\\123.xlsx"; //判断是否为excel类型文件 if(!filePath.endsWith(".xls")&&!filePath.endsWith(".xlsx")) System.out.println("文件不是excel类型"); FileInputStream fis =null; Workbook wookbook = null; Sheet sheet =null; //获取一个绝对地址的流 fis = new FileInputStream(filePath); catch(Exception e) e.printStackTrace(); //2003版本的excel,用.xls结尾 wookbook = new HSSFWorkbook(fis);//得到工作簿 catch (Exception ex) //ex.printStackTrace(); //2007版本的excel,用.xlsx结尾 fis = new FileInputStream(filePath); wookbook = new XSSFWorkbook(fis);//得到工作簿 } catch (IOException e) // TODO Auto-generated catch block e.printStackTrace(); Map<String, PictureData> maplist=null; sheet = wookbook.getSheetAt(0); // 判断用07还是03的方法获取图片 if (filePath.endsWith(".xls")) { maplist = getPictures1((HSSFSheet) sheet); } else if(filePath.endsWith(".xlsx")){ maplist = getPictures2((XSSFSheet) sheet); try { printImg(maplist); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); //得到一个工作表 //获得表头 Row rowHead = sheet.getRow(0); //判断表头是否正确 System.out.println(rowHead.getPhysicalNumberOfCells()); if(rowHead.getPhysicalNumberOfCells() != 5) System.out.println("表头的数量不对!"); //获得数据的总行数 int totalRowNum = sheet.getLastRowNum(); //要获得属性 int studentid=0; String studentname=""; String grade=""; String classes=""; String pic=""; //获得所有数据 for(int i = 1 ; i <= totalRowNum ; i++) //获得第i行对象 Row row = sheet.getRow(i); //获得获得第i行第0列的 String类型对象 Cell cell = row.getCell((short)0); studentid = (int) cell.getNumericCellValue(); //获得一个数字类型的数据 //studentname = (int) cell.getNumericCellValue(); cell = row.getCell((short)1); studentname =cell.getStringCellValue().toString(); cell = row.getCell((short)2); grade =cell.getStringCellValue().toString(); cell = row.getCell((short)3); classes =cell.getStringCellValue().toString(); cell = row.getCell((short)3); classes =cell.getStringCellValue().toString(); System.out.println("学号:"+studentid+",姓名:"+studentname+",年级:"+grade+",班级:"+classes+",证件照:"+pic); for (Entry<String, PictureData> entry : maplist.entrySet()) { System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue()); * 获取图片和位置 (xls) * @param sheet * @return * @throws IOException public static Map<String, PictureData> getPictures1 (HSSFSheet sheet) throws IOException { Map<String, PictureData> map = new HashMap<String, PictureData>(); List<HSSFShape> list = sheet.getDrawingPatriarch().getChildren(); for (HSSFShape shape : list) { if (shape instanceof HSSFPicture) { HSSFPicture picture = (HSSFPicture) shape; HSSFClientAnchor cAnchor = (HSSFClientAnchor) picture.getAnchor(); PictureData pdata = picture.getPictureData(); String key = cAnchor.getRow1() + "-" + cAnchor.getCol1(); // 行号-列号 map.put(key, pdata); return map; * 获取图片和位置 (xlsx) * @param sheet * @return * @throws IOException public static Map<String, PictureData> getPictures2 (XSSFSheet sheet) throws IOException { Map<String, PictureData> map = new HashMap<String, PictureData>(); List<POIXMLDocumentPart> list = sheet.getRelations(); for (POIXMLDocumentPart part : list) { if (part instanceof XSSFDrawing) { XSSFDrawing drawing = (XSSFDrawing) part; List<XSSFShape> shapes = drawing.getShapes(); for (XSSFShape shape : shapes) { XSSFPicture picture = (XSSFPicture) shape; XSSFClientAnchor anchor = picture.getPreferredSize(); CTMarker marker = anchor.getFrom(); String key = marker.getRow() + "-" + marker.getCol(); map.put(key, picture.getPictureData()); return map; //图片写出 public static void printImg(Map<String, PictureData> sheetList) throws IOException { //for (Map<String, PictureData> map : sheetList) { Object key[] = sheetList.keySet().toArray(); for (int i = 0; i < sheetList.size(); i++) { // 获取图片流 PictureData pic = sheetList.get(key[i]); // 获取图片索引 String picName = key[i].toString(); // 获取图片格式 String ext = pic.suggestFileExtension(); byte[] data = pic.getData(); //图片保存路径 FileOutputStream out = new FileOutputStream("D:\\img\\pic" + picName + "." + ext); out.write(data); out.close(); public static void main(String[] args) throws Exception { getDataFromExcel("E:"+ File.separator +"学生信息表.xlsx"); java 给一个开学日期,计算当天是开学第几周星期几或者开学第几周星期几为哪一天 hezejun123: 如果开学日期是周日呢 java--poi读取excel图片和内容(支持03,07版本) wy123123000: 我的博文里应该有word和pdf,好几年前做的了现在没研究了 java--poi读取excel图片和内容(支持03,07版本) wy123123000: 3.9吧好像是 java--poi读取excel图片和内容(支持03,07版本) a1670131049: 请问博主用的poi依赖是多少?