Use aspose.cell. * The picture generated excel

First you have to download a aspose.cell. * Packages can go look at Baidu

code show as below

package com.pl.Excel;

import java.io.File;


import com.aspose.cells.*;


/**
 * Excel to PDF
 */
public class ExcelToPdf {


    public static void ConvertToImage() {
        Workbook book=null;
        try {
            book = new Workbook ( "E: \\ test .xlsx");
            String path = "E: \\ test .xlsx";
            // Get the sheet
            Worksheet sheet=book.getWorksheets().get( 5 );
            // set the scope of interception
            String area = 7 + ":" + 31; // taken place can be selected range
            System.out.println( "area: " + area );
            sheet.getPageSetup () setPrintArea (area);. // set the margin picture data
            sheet.getPageSetup () setLeftMargin (-20);. // left margin
            sheet.getPageSetup () setRightMargin (0);. // Set the right margin
            . Sheet.getPageSetup () setBottomMargin (0); // set the margin
            sheet.getPageSetup().setTopMargin( 0 );

            // define ImageOrPrintOptions
            ImageOrPrintOptions imgOptions=new ImageOrPrintOptions();
            / * Specify the image format * /
            imgOptions.setImageFormat (ImageFormat.getJpeg ());
            imgOptions.setCellAutoFit( true );
            imgOptions.setOnePagePerSheet( true );
            //imgOptions.setDesiredSize(1000,800);
            // the specified image / print options rendered drawings
            SheetRender render=new SheetRender( sheet, imgOptions );

            // Render the image for the sheet
            //render.toImage(0, dataDir + "SheetImage.jpg");
            render.toImage (0, "E: \\ reports .jpg");
        } catch (Exception e) {
            e.printStackTrace ();
        }

    }

    public static void main(String[] args) {
        ConvertToImage ();
    }
}

  

Guess you like

Origin www.cnblogs.com/1161612328qq/p/12161511.html