News Category

Other

Other (3)

This article shows you how to embed a zip file as an OLE object in a PowerPoint document using Spire.Presentation for Java.

import com.spire.presentation.*;
import com.spire.presentation.drawing.IImageData;

import javax.imageio.ImageIO;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;

public class InsertZip {

    public static void main(String[] args) throws Exception {

        //Create a Presentation object
        Presentation presentation = new Presentation();
        presentation.getSlideSize().setType(SlideSizeType.SCREEN_16_X_9);

        //Get the first slide
        ISlide slide = presentation.getSlides().get(0);

        //Load a zip file and convert it to a byte[] object
        String filePath = "C:\\Users\\Administrator\\Desktop\\sample.zip";
        File zipFile = new File(filePath);
        FileInputStream inputStream = new FileInputStream(zipFile);
        byte[] data = new byte[(int) zipFile.length()];
        inputStream.read(data, 0, data.length);

        //Load an image file as the display icon
        File file = new File("C:\\Users\\Administrator\\Desktop\\winrar-icon.png");
        BufferedImage image = ImageIO.read(file);
        IImageData oleImage = presentation.getImages().append(image);
        
        //Insert the zip file as an OLE object to the first slide
        Rectangle2D rect = new Rectangle2D.Float(60, 60, image.getWidth(), image.getHeight());
        IOleObject oleObject = slide.getShapes().appendOleObject("zip", data, rect);
        oleObject.getSubstituteImagePictureFillFormat().getPicture().setEmbedImage(oleImage);
        oleObject.setProgId("Package");
        
        //Save to file
        presentation.saveToFile("output/InsertZip.pptx", FileFormat.PPTX_2013);
    }
}

 

Embed a Zip File in PowerPoint in Java

This article demonstrates how to insert an Excel file as an OEL object into a PowerPoint document using Spire.Presentation for Java.

import com.spire.presentation.FileFormat;
import com.spire.presentation.IOleObject;
import com.spire.presentation.Presentation;
import com.spire.presentation.SlideSizeType;
import com.spire.presentation.drawing.IImageData;
import javax.imageio.ImageIO;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;

public class EmbedExcel {

    public static void main(String[] args) throws Exception {

        //Create a Presentation object
        Presentation ppt = new Presentation();
        ppt.getSlideSize().setType(SlideSizeType.SCREEN_16_X_9);

        //Load an image file and add it to the image collection of the presentation
        File file = new File("C:\\Users\\Administrator\\Desktop\\image.png");
        BufferedImage image = ImageIO.read(file);
        IImageData oleImage = ppt.getImages().append(image);

        //Load an Excel file and convert it to byte[] object
        String excelPath = "C:\\Users\\Administrator\\Desktop\\data.xlsx";
        File excelFile = new File(excelPath);
        FileInputStream inputStream = new FileInputStream(excelFile);
        byte[] data = new byte[(int) excelFile.length()];
        inputStream.read(data, 0, data.length);

        //Create a Rectangle2D object
        Rectangle2D rect = new Rectangle2D.Float(60, 60, image.getWidth(), image.getHeight());

        //Insert the Excel file as an OLE object to the first slide
        IOleObject oleObject = ppt.getSlides().get(0).getShapes().appendOleObject("excel", data, rect);
        oleObject.getSubstituteImagePictureFillFormat().getPicture().setEmbedImage(oleImage);
        oleObject.setProgId("Excel.Sheet.12");

        //Save to another file
        ppt.saveToFile("InsertOle.pptx", FileFormat.PPTX_2013);
    }
}

Embed an Excel File in a PowerPoint Document in Java

This article demonstrates how to add footer to PowerPoint document in Java application using Spire.Presentation for Java.

import com.spire.presentation.FileFormat;
import com.spire.presentation.Presentation;

public class AddFooter {
    public static void main(String[] args) throws Exception {
        //Load a PPT document
        Presentation presentation = new Presentation();
        presentation.loadFromFile("Input.pptx");

        //Add footer
        presentation.setFooterText("Demo of Spire.Presentation");
        //Set the footer visible
        presentation.setFooterVisible(true);
        //Set the page number visible
        presentation.setSlideNumberVisible(true);
        //Set the date visible
        presentation.setDateTimeVisible(true);
        
        //Save the document
        presentation.saveToFile("AddFooter.pptx", FileFormat.PPTX_2010);
    }
}

Output:

Add-Footer-to-PowerPoint-Document-in-Java