首页 Java Java Aspose.cells Excel(.xls,.xlsx)文件转成csv文件和html文件

Java Aspose.cells Excel(.xls,.xlsx)文件转成csv文件和html文件

1、Aspose组件下载

Aspose下载地址:https://products.aspose.com/cells/java

破解版下载地址:https://download.csdn.net/download/phl657880020/10489382

官方文档地址:https://docs.aspose.com/display/cellsjava/Home

官方Demo代码:https://github.com/aspose-cells/Aspose.Cells-for-Java

2、Excel转csv和html代码

package com.demo;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;

import com.aspose.cells.License;
import com.aspose.cells.SaveFormat;
import com.aspose.cells.Workbook;

/**
 * 
 * 由于ASPOSE比较吃内存,操作大一点的文件就会堆溢出,所以请先设置好java虚拟机参数:-Xms512m -Xmx512m(参考值)<br>
 * 
 *
 */
public >Test {

    /**
     * 获取license
     * 
     * @return
     */
    public static boolean getLicense() {
        boolean result = false;
        try {
            InputStream is = Test.>"\\license.xml");
            License aposeLic = new License();
            aposeLic.setLicense(is);
            result = true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 支持DOC, DOCX, OOXML, RTF, HTML, OpenDocument, PDF, EPUB, XPS, SWF等相互转换<br>
     * 
     * @param args
     */
    public static void main(String[] args) {
        // 验证License
        if (!getLicense()) {
            return;
        }
        try {
            long old = System.currentTimeMillis();
            ExcelConvertToCSV("/home/11.xlsx", "/home/csv.csv");
            ExcelConvertToHtml("/home/11.xlsx", "/home/excel/11.html");
            long now = System.currentTimeMillis();
            System.out.println("共耗时:" + ((now - old) / 1000.0) + "秒");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public static void ExcelConvertToCSV(String sourceFilePath, String csvFilePath)
			throws Exception {
		com.aspose.cells.Workbook excel = null;
		excel = new com.aspose.cells.Workbook(sourceFilePath);
		excel.save(csvFilePath, com.aspose.cells.SaveFormat.CSV);
	}
       public static void ExcelConvertToHtml(String sourceFilePath, String htmlFilePath)
			throws Exception {
		com.aspose.cells.LoadOptions loadOption = null;
		com.aspose.cells.Workbook excel = null;
		if (sourceFilePath != null
				&& !sourceFilePath.isEmpty()
				&& sourceFilePath
						.substring(sourceFilePath.lastIndexOf("."))
						.toLowerCase() == ".csv") {
			loadOption = new com.aspose.cells.TxtLoadOptions(
					com.aspose.cells.LoadFormat.AUTO);
		}
		if (loadOption != null) {
			excel = new com.aspose.cells.Workbook(sourceFilePath, loadOption);
		} else {
			excel = new com.aspose.cells.Workbook(sourceFilePath);
		}
		excel.save(htmlFilePath, com.aspose.cells.SaveFormat.HTML);
	}
}

3、本文项目代码下载

下载地址:https://www.cjavapy.com/download/5c1620d6dc72d915fc31068a/

特别声明:本站部分内容收集于互联网是出于更直观传递信息的目的。该内容版权归原作者所有,并不代表本站赞同其观点和对其真实性负责。如该内容涉及任何第三方合法权利,请及时与824310991@qq.com联系,我们会及时反馈并处理完毕。