Java导出PPT过程


业务场景根据PPT模板填充数据后导出。

1.前台通过axiso发送导出请求。

2.导入java-poi相关依赖的jar包

3.读取resource下的ppt模板

4.将读取的ppt模板文件输入流,通过POI转换为ppt对象,并且动态创建幻灯片。

5.根据ppt模板填充业务数据。

6.导出ppt文件(注意响应类型)。

7.前台利用blob对象对响应转为具体文件。(参考链接:https://my.oschina.net/u/4348174/blog/3564571

// 导出ppt,axiso前台
exportPPT(){
    axios({
        url: '',
        method: 'post',
        data: {},
        responseType: 'blob'
      }).then(response => {
        const blob = new Blob([response.data])
        const fileName = this.fileName+ '.ppt'
        if ('download' in document.createElement('a')) { // 非IE下载
          const elink = document.createElement('a')
          elink.download = fileName
          elink.style.display = 'none'
          elink.href = URL.createObjectURL(blob)
          document.body.appendChild(elink)
          elink.click()
          URL.revokeObjectURL(elink.href) // 释放URL 对象
          document.body.removeChild(elink)
          this.disable = false
        } else { // IE10+下载
          navigator.msSaveBlob(blob, fileName)
          this.disable = false
        }
      })  
}
// 获取配置文件的方法
// 方法一:示例获取src目录下config目录中application.properties配置文件
ResourceBundle resource = ResourceBundle.getBundle("config/application");
String key = resource.getString("port"); 

// 方法二:示例获取src获取resource下application.properties
InputStream inStream = TestProperties.class.getClassLoader().getResourceAsStream("application.properties");  
Properties prop = new Properties();  
prop.load(inStream);  
String key = prop.getProperty("port");  
// 这种方式,也可以读取其他类型的文件,eg:ppt文件
InputStream inStream = TestProperties.class.getClassLoader().getResourceAsStream("PPT文件");  
// java,poi相关对象和接口
XMLSlideShow ppt = new XMLSlideShow(); // PPT
XSLFSlide slide = ppt.createSlide(); // 幻灯片


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM