We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Adding background image to excel

I am following this link for adding background image to excel


https://docs.aspose.com/display/cellsjava/set+background+picture+for+a+worksheet


<pre style=“background-color: rgb(255, 255, 255); font-family: “Fira Code”; font-size: 9pt;”>ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource(“base.png”).getFile());
byte[] imageData = new byte[(int) file.length()];
FileInputStream fis = new FileInputStream(file);
fis.read(imageData);

for (int i = 0; i < workbook.getWorksheets().getCount(); i++) {
Worksheet worksheet = workbook.getWorksheets().get(i);
worksheet.setBackgroundImage(imageData);
}<pre style=“background-color: rgb(255, 255, 255); font-family: “Fira Code”; font-size: 9pt;”>
<pre style=“background-color: rgb(255, 255, 255); font-family: “Fira Code”; font-size: 9pt;”>The above code is applying background image to excel file, but the size of excel file<pre style=“background-color: rgb(255, 255, 255); font-family: “Fira Code”; font-size: 9pt;”>is becoming very large in MB (10 to 20MB).<pre style=“background-color: rgb(255, 255, 255); font-family: “Fira Code”; font-size: 9pt;”>I am not able to figure out this behavior, please inform me if there is any solution.

Hi,


Thanks for providing us code snippet and details.

Could you provide us template Excel file and image file “base.png” here, we will check your issue soon.

Thank you.