java文档格式转换工具类源码

本文介绍了使用Java将word、excel、ppt、mht和pdf等文件转换为html源码的步骤。首先确保源文件编码与项目一致,然后引入jacob.jar包,通过ActiveXComponent和Dispatch处理转换,以Word为例展示转换过程。作者提供了源码支持。
摘要由CSDN通过智能技术生成

word,excel,ppt,mht,pdf等文件如何转成html源码

作者:楚天龙-zhangqingbiao

第一步:需要检查你的源文件是什么编码格式。尽量保证和你的项目编码格式一直,否则很容易出行IE正常访问,但是其他浏览器不能正常访问。
第二步:不说太多,直接上干货,详细操作流程如下:
第三步:引入jacob.jar包,如果找不到jar包,这个jar包是本人自己重新改造的jar包,有需要的,可以私信我。

    <dependency>
        <groupId>com.jacob</groupId>
        <artifactId>jacob</artifactId>
        <version>1.2.0</version>
    </dependency>

第四步;核心代码,编写一个HtmlUtills类,里面针对各种文档格式转html,下面以word为例子:
public boolean WordtoHtml(String orignFileStr, String destinationFileStr) {
ComThread.InitSTA();
ActiveXComponent activexcomponent = new ActiveXComponent(
“Word.Application”);
boolean flag = false;
try {
a

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
package com.hexiang.utils; import java.io.*; /** * FileUtil. Simple file operation class. * * @author BeanSoft * */ public class FileUtil { /** * The buffer. */ protected static byte buf[] = new byte[1024]; /** * Read content from local file. FIXME How to judge UTF-8 and GBK, the * correct code should be: FileReader fr = new FileReader(new * InputStreamReader(fileName, "ENCODING")); Might let the user select the * encoding would be a better idea. While reading UTF-8 files, the content * is bad when saved out. * * @param fileName - * local file name to read * @return * @throws Exception */ public static String readFileAsString(String fileName) throws Exception { String content = new String(readFileBinary(fileName)); return content; } /** * 读取文件并返回为给定字符集的字符串. * @param fileName * @param encoding * @return * @throws Exception */ public static String readFileAsString(String fileName, String encoding) throws Exception { String content = new String(readFileBinary(fileName), encoding); return content; } /** * 读取文件并返回为给定字符集的字符串. * @param fileName * @param encoding * @return * @throws Exception */ public static String readFileAsString(InputStream in) throws Exception { String content = new String(readFileBinary(in)); return content; } /** * Read content from local file to binary byte array. * * @param fileName - * local file name to read * @return * @throws Exception */ public static byte[] readFileBinary(String fileName) throws Exception { FileInputStream fin = new FileInputStream(fileName); return readFileBinary(fin); } /** * 从输入流读取数据为二进制字节数组. * @param streamIn * @return * @throws IOException */ public static byte[] readFileBinary(InputStream streamIn) throws IOException { BufferedInputStream in = new BufferedInputStream(streamIn); ByteArrayOutputStream out = new ByteArrayOutputStream(10240); int len; while ((len
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值