赞
踩
excel转pdf
用到了以下jar,License写在了文中。
<!-- excel工具 -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>5.2.2</version>
</dependency>
<dependency>
<groupId>aspose</groupId>
<artifactId>cells</artifactId>
<version>8.5.2</version>
</dependency>
下面上代码
package com.admin.util; import java.io.ByteArrayInputStream; import com.aspose.cells.SaveFormat; import com.aspose.cells.Workbook; import java.io.FileOutputStream; import java.io.File; /** * Excel转PDF */ public class ExcelToPdf { /** * 获取license */ public static boolean isWordLicense() { boolean result = false; try { String s = "<License>" + "<Data>" + "<Products>" + "<Product>Aspose.Total for Java</Product>" + "<Product>Aspose.Words for Java</Product>" + "</Products>" + "<EditionType>Enterprise</EditionType>" + "<SubscriptionExpiry>20991231</SubscriptionExpiry>" + "<LicenseExpiry>20991231</LicenseExpiry>" + "<SerialNumber>8bfe198c-7f0c-4ef8-8ff0-acc3237bf0d7</SerialNumber>" + "</Data>" + "<Signature>sNLLKGMUdF0r8O1kKilWAGdgfs2BvJb/2Xp8p5iuDVfZXmhppo+d0Ran1P9TKdjV4ABwAgKXxJ3jcQTqE/2IRfqwnPf8itN8aFZlV3TJPYeD3yWE7IT55Gz6EijUpC7aKeoohTb4w2fpox58wWoF3SNp6sK6jDfiAUGEHYJ9pjU=</Signature>" + "</License>"; ByteArrayInputStream inputStream = new ByteArrayInputStream(s.getBytes()); com.aspose.words.License license = new com.aspose.words.License(); license.setLicense(inputStream); result = true; } catch (Exception e) { e.printStackTrace(); } return result; } public static boolean ExcelToPdf(String Epath, String Opath) { boolean flag = false; // 验证License if (!isWordLicense()) { return false; } try { long start = System.currentTimeMillis(); Workbook wb = new Workbook(Epath);// 原始excel路径 File pdfFile = new File(Opath);// 输出路径 FileOutputStream fileOS = new FileOutputStream(pdfFile); wb.save(fileOS, SaveFormat.PDF); long now = System.currentTimeMillis(); System.out.println("共耗时:" + ((now - start) / 1000.0) + "秒"); flag = true; } catch (Exception e) { e.printStackTrace(); } return flag; } //测试方法 public static void main(String[] args) { ExcelToPdf.ExcelToPdf("D:\\1.xls","D:\\x111.pdf"); } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。