Free Support Forum - aspose.com

We are getting evaluation license issue while extract images from excel sheets in java

We are getting evaluation license issue while extract images from excel sheets in java.

License Type : Aspose.total.java.lic - Expiry on Aug 2020.

We can extract all the images present in a worksheet using Worksheet.getPictures() method. It will returns the collection of all the pictures.

The image is populated from table values to chart image(Not direct image paste).(PFA ImageBackgroundcheck.PNG (25.7 KB)
)

Please see the sample code below. It extracts all the images from the first worksheet of the source file.

I have attached the source xlsx file.

When we are extracting images one by one the image background the watermark displayed.

package com.image.test;

import java.awt.RenderingHints;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;


import com.aspose.cells.ImageFormat;
import com.aspose.cells.Picture;
import com.aspose.cells.Workbook;

public class ImageTest {
	public static void main(String[] args) throws Exception {
		
		
		
		String filePath = "C:/Users/test/Downloads/Figures for Import From Excel_09_26_18.xlsx";
		


		Workbook workbook = new Workbook(filePath);


		com.aspose.cells.Worksheet worksheet = workbook.getWorksheets().get(0);


		com.aspose.cells.PictureCollection pics = worksheet.getPictures();

        
		//Write all the extracted images on disk

		for(int i=0; i<pics.getCount(); i++)

		{

		Picture pic = pics.get(i);


		byte[] picBytes = pic.getData();

		String picExtension = pic.getImageFormat().getName();


		FileOutputStream fout = new FileOutputStream(“image_”+ i + “.” + picExtension);

		fout.write(picBytes);
		
		fout.close();


		}//for
		
	}

}

@krishnass,

Thanks for the sample code segment and screenshot.

Please set your license in code at the start of your program as I do not see license setting code, please see the document for your reference:
https://docs.aspose.com/display/cellsjava/Licensing

If you still find any issue, let us know with details and template file, we will check it soon.

I have enabled license in my coding,But facing same issue. Please advise.

I have one clarification Aspose.total.java.lic license support this functionality?

package com.image.test;

import java.awt.RenderingHints;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import com.aspose.cells.ImageFormat;
import com.aspose.cells.Picture;
import com.aspose.cells.Workbook;
import com.aspose.words.License;

public class ImageTest {
License license = new License();
license.setLicense(“Aspose.Total.Java.lic”);

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

  String filePath = "C:/Users/test/Downloads/Figures for Import From Excel_09_26_18.xlsx";
  


  Workbook workbook = new Workbook(filePath);


  com.aspose.cells.Worksheet worksheet = workbook.getWorksheets().get(0);


  com.aspose.cells.PictureCollection pics = worksheet.getPictures();

    
  //Write all the extracted images on disk

  for(int i=0; i<pics.getCount(); i++)

  {

  Picture pic = pics.get(i);


  byte[] picBytes = pic.getData();

  String picExtension = pic.getImageFormat().getName();


  FileOutputStream fout = new FileOutputStream(“image_”+ i + “.” + picExtension);

  fout.write(picBytes);
  
  fout.close();


  }//for

}

}

@krishnass,
It seems that you are initializing license for Aspose.Words. You may please fully qualify the license object and try the scenario again.

Please guide me - how to enable fully qualify the license object.

@krishnass,

Please change the lines of code (this will ensure that you are setting the license for Aspose.Cells as well):
i.e.,

    ......
    License license = new License();
    license.setLicense(“Aspose.Total.Java.lic”); 

to:

com.aspose.cells.License license = new com.aspose.cells.License();
license.setLicense(“Aspose.Total.Java.lic”);

Hope, this helps a bit.

I have tried full license quality too but not working.

Please let me know - Aspose.total.java.lic license support this functionality?

@krishnass,

It must be an issue with your code ( you might not be using fully qualified naming) when setting the license. Alternatively, your licensing code is not processed at all. So, kindly make sure you have written valid code (using com.aspose.cells.License object) to set the license for Aspose.Cells for Java. If you still find the issue, we would need your license file to evaluate the issue, kindly do click on my name and click on Message to post the license via a private message, we will check it soon.

Above code is working fine. Thanks a lot @ahsaniqbalsidiqui @Amjad_Sahi

@krishnass,
You are welcome.