Java Excel Insertion and Image Extraction

Spire.XLS supports a wealth of image processing features. Addition, rotation, extraction, deletion, etc. In this paper, I will show you how to insert and extract images into an Excel document using Spire.XLS for Java.

Tools used: Free Spire.XLS for Java (free version) https://www.e-iceblue.com/Introduce/free-xls-for-java.html

Getting and installing Jar files:

Method 1: Download the jar file bag through the homepage. After downloading, unzip the file and install the Spire.xls.jar file under the lib folder into your Java program. https://www.e-iceblue.com/Download/xls-for-java-free.html

Method 2: Introduced by installing maven warehouse.

https://www.e-iceblue.com/Tutorials/Licensing/How-to-install-Spire.PDF-for-Java-from-Maven-Repository.html

Insert image into excel

import com.spire.xls.ExcelPicture;
import com.spire.xls.ExcelVersion;
import com.spire.xls.Workbook;
import com.spire.xls.Worksheet;

public class InsertImage {
    public static void main(String[] args){
        //Import an Excel document
        Workbook workbook = new Workbook();
        workbook.loadFromFile("Input.xlsx");

        //Get the first sheet
        Worksheet sheet = workbook.getWorksheets().get(0);

        //Adds an image at the specified position on the sheet
        ExcelPicture pic = sheet.getPictures().add(4, 1,"image.jpg ");
        //Set the width and height of the image
        pic.setWidth(500);
        pic.setHeight(300);

        //Save document
        workbook.saveToFile("InsertImage.xlsx", ExcelVersion.Version2013);
    }
}

Insert Image to Excel.png

Extract image

import com.spire.xls.ExcelPicture;
import com.spire.xls.Workbook;
import com.spire.xls.Worksheet;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

public class ReadImage {
    public static void main(String[] args) throws IOException {
          //Import an Excel document
        Workbook workbook = new Workbook();
        workbook.loadFromFile("InsertImage.xlsx");

        //Get the first sheet
        Worksheet sheet = workbook.getWorksheets().get(0);

        //Gets the first image of the sheet and saves it in the specified path
        ExcelPicture pic = sheet.getPictures().get(0);
        BufferedImage loImage = pic.getPicture();
        ImageIO.write(loImage,"jpg",new File("output/ReadImage.jpg "));
    }
}

Extract Image from Excel.png

Recommended Posts

Java Excel Insertion and Image Extraction
Java Excel settings background color and background image
Java adds and reads Excel formulas
Java and JavaScript
XXE and Java
java insertion sort
Add, read, and delete Excel comments in Java
Java enables extraction of PDF text and images
Getters and setters (Java)
[Java] Thread and Runnable
Java true and false
Vectorize and image MNIST handwritten digit image data in Java
[Java] String comparison and && and ||
Excel sheet and set Tab colors to rename Java
Print Java Excel Worksheet
Java --Serialization and Deserialization
[Java] Arguments and parameters
timedatectl and Java TimeZone
[Java] Branch and repeat
[Java] Variables and types
java (classes and instances)
[Java] Overload and override
Java sets the background color and background image for PowerPoint documents
Study Java # 2 (\ mark and operator)
Java version 8 and later features
Save Java PDF in Excel
[Java] Difference between == and equals
Java merge & unmerge Excel cell
[Java] Stack area and static area
[Java] Generics classes and generics methods
Java programming (variables and data)
Java encryption and decryption PDF
Java and Iterator Part 1 External Iterator
Let's operate Excel with Java! !!
Importing Excel data in Java 2
Java if and switch statements
Java class definition and instantiation
Java turns Excel into PDF
Apache Hadoop and Java 9 (Part 1)
[Java] About String and StringBuilder
[Java] HashCode and equals overrides
Import Excel data in Java
Java addition excel data validation
☾ Java / Iterative statement and iterative control statement
Java creates an Excel document
Java methods and method overloads
java Generics T and? Difference
Advantages and disadvantages of Java
java (conditional branching and repetition)
About Java Packages and imports
Importing Excel data in Java 3
[Java] Upload images and base64
Java sets Excel document properties
C # and Java Overrides Story
Java abstract methods and classes
Java while and for statements
Java encapsulation and getters and setters