java xlsx转html

 

       poi-scratchpad  包中提供了ExcelToHtmlConverter工具类可以实现xls文件转换为html的功能,但是无法实现xlsx转html。

       本代码重写了一遍ExcelToHtmlConverter,实现了xlsx转html。入口类为XssfExcelToHtmlConverter

 可以直接使用这个类中的main方法进行测试。源码在附件中,只要修改相应的包名即可,还要引入poi-scratchpad 和poi包。

 

 public static void main( String[] args )throws IOException, ParserConfigurationException, TransformerException{
        
    	String inputPath="/Users/xuwenfeng/Desktop/testexcel.xlsx";
        String outputPath="/Users/xuwenfeng/Desktop/testexcel.html";
    	
        args=new String[]{inputPath,outputPath};
        
    	if ( args.length < 2 )
        {
            System.err.println( "Usage: ExcelToHtmlConverter <inputFile.xls> <saveTo.html>" );
            return;
        }

        System.out.println( "Converting " + args[0] );
        System.out.println( "Saving output to " + args[1] );

        Document doc = XssfExcelToHtmlConverter.process( new File( args[0] ) );

        DOMSource domSource = new DOMSource( doc );
        StreamResult streamResult = new StreamResult( new File(args[1]) );

        TransformerFactory tf = TransformerFactory.newInstance();
        Transformer serializer = tf.newTransformer();
        // TODO set encoding from a command argument
        serializer.setOutputProperty( OutputKeys.ENCODING, "UTF-8" );
        serializer.setOutputProperty( OutputKeys.INDENT, "no" );
        serializer.setOutputProperty( OutputKeys.METHOD, "html" );
        serializer.transform( domSource, streamResult );
    }

 

 

 


有任何问题请联系微信 

如果您觉得我的文章给了您帮助,请为我买一杯饮料吧!以下是我的支付宝,意思一下我将非常感激!
  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值