Aspose,excel转pdf

package com.reemoon.controller.common;

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

import javax.servlet.http.HttpServletResponse;

import com.aspose.cells.*;

public class ExcelToPdfUtil {

    public static boolean getLicense() {
        boolean result = false;
        try {
            InputStream is = ExcelToPdfUtil.class.getClassLoader().getResourceAsStream("xlsxlicense.xml"); // license.xml应放在..\WebRoot\WEB-INF\classes路径下
            License aposeLic = new License();
            aposeLic.setLicense(is);
            result = true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    /**
     * excel转pdf
     * @param workbook
     * @param out
     * @param response
     */
    public static void excelToPdf(InputStream workbook, OutputStream out, HttpServletResponse response) {

        if (!getLicense()) { // 验证License 若不验证则转化出的pdf文档会有水印产生
            return;
        }
        try {
            Workbook wb = new Workbook(workbook);
            /*********关闭网格线start***********/
            WorksheetCollection worksheets = wb.getWorksheets();
            Worksheet worksheet = worksheets.get(0);
            worksheet.getPageSetup().setPrintGridlines(false);
            /*********关闭网格线end***********/
            wb.save(out, SaveFormat.PDF);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * excel转pdf
     * @param Address
     */
    public static void excelToPdf(String Address) {
        if (!getLicense()) { // 验证License 若不验证则转化出的pdf文档会有水印产生
            return;
        }
        try {
            // 输出路径
            File pdfFile = new File("F:\\aa.pdf");
            // 原始excel路径
            Workbook wb = new Workbook(Address);
            /*********关闭网格线start***********/
            WorksheetCollection worksheets = wb.getWorksheets();
            Worksheet worksheet = worksheets.get(0);
            worksheet.getPageSetup().setPrintGridlines(false);
            /*********关闭网格线end***********/
            FileOutputStream fileOS = new FileOutputStream(pdfFile);
            wb.save(fileOS, SaveFormat.PDF);
            fileOS.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * excel转img
     * @param input
     * @param out
     */
    public static void excelToImg(InputStream input, OutputStream out) {
        if (!getLicense()) { // 验证License 若不验证则转化出的pdf文档会有水印产生
            return;
        }
        try {
            Workbook wb = new Workbook(input);
            Worksheet sheet = wb.getWorksheets().get(0);
            /*********关闭网格线start***********/
            sheet.getPageSetup().setPrintGridlines(false);
            /*********关闭网格线end***********/
            // 定义ImageOrPrintOptions
            ImageOrPrintOptions imgOptions=new ImageOrPrintOptions();
            /* 指定图像格式*/
            imgOptions.setImageFormat( ImageFormat.getJpeg() );
            imgOptions.setCellAutoFit( true );
            imgOptions.setOnePagePerSheet( true );
            // 根据指定的图像/打印选项渲染图纸
            SheetRender render=new SheetRender(sheet, imgOptions );
            render.toImage(0, out);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

excel转pdf,转换有虚线,网格线解决

            /*********关闭网格线start***********/
            WorksheetCollection worksheets = wb.getWorksheets();
            Worksheet worksheet = worksheets.get(0);
            worksheet.getPageSetup().setPrintGridlines(false);
            /*********关闭网格线end***********/

没加之前:

 

加了之后: 

 

 license.xml

<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>

aspose-cells-8.5.2.jar网盘下载地址

链接:https://pan.baidu.com/s/1bIkwR7-uqclh9Ei_muhTJA 
提取码:gmcg

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值