Hi Team,
I am trying to add an image (.png file) to excel file (all sheets).
But looks like that image is added to each cell. I want that image to be added only once
on each sheet of excel file. Below is the code I used. Can you please help me in this regard.
package com.test;
import java.io.File;
import java.io.FileInputStream;
import com.aspose.cells.Workbook;
import com.aspose.cells.Worksheet;
public class AddWaterMarkAsImageToExcelFile {
public static void main(String[] args)throws Exception {
Workbook workbook = new Workbook(“d:\images\Test.xlsx”);
int sheets=workbook.getWorksheets().getCount();
System.out.println(“no of sheets------>”+sheets);
File file = new File(“d:\images\Demo.png”);
byte[] imageData = new byte[(int)file.length()];
FileInputStream fis = new FileInputStream(file);
fis.read(imageData);
Worksheet sheet = null;
for(int count=0;count<sheets;count++){
sheet=workbook.getWorksheets().get(count);
//Set the background image for the sheet.
sheet.setBackground(imageData);
}
//Save the excel file
workbook.save(“d:\images\Demo.xlsx”);
System.out.println(“end”);
}
}
I am attaching the excel files for your reference.