Image in footer

I am trying to put an image in the footer. at the left side position. I follow the documentation as follows


PageSetup ps = sheet.getPageSetup();
String script1 = “&“Arial, Bold”&14&K1F69AA&A”;
ps.setHeader(0, script1);
ps.setFooter(0, “&G”);
FileInputStream fis = new FileInputStream(basePath + “\resources\images\driSteem_logo.png”);
byte[] picData = new byte[fis.available()];
fis.read(picData);
ps.setFooterPicture(1, picData);
Picture pic = wb.getWorksheets().get(0).getPageSetup().getPicture(false, 1);
pic.setHeight(20);
pic.setWidth(40);
fis.close();

But no image comes no space for an image and no image. Please advise on what I am doing wrong.


Hi David,

Thank you for using Aspose products.

You are specifying different positions for the footer image to appear while calling PageSetup.setFooter and PageSetup.setFooterPicture methods. Please make the following change to your code, and give it a try at your end.

Java



PageSetup ps = sheet.getPageSetup();
String script1 = “&“Arial, Bold”&14&K1F69AA&A”;
ps.setHeader(0, script1);
ps.setFooter(0, “&G”);
FileInputStream fis = new FileInputStream(basePath + “\resources\images\driSteem_logo.png”);
byte[] picData = new byte[fis.available()];
fis.read(picData);
ps.setFooterPicture(0, picData); //Changed from 1 to 0 for left side


Complete Source


//Creating a Workbook object
Workbook workbook = new Workbook();
//Creating a string variable to store the url of the logo/picture
String logo_url = “d:\temp\sample.bmp”;
//Creating the instance of the FileInputStream object to open the logo/picture in the stream
FileInputStream inFile = new FileInputStream(logo_url);
//Insert dummy data for preview
Cells cells = workbook.getWorksheets().get(0).getCells();
cells.get(“A1”).putValue(“hello”);
//Creating a PageSetup object to get the page settings of the first worksheet of the workbook
PageSetup pageSetup = workbook.getWorksheets().get(0).getPageSetup();
//Setting the logo/picture in the central section of the page header
pageSetup.setFooter(0, “&G”);
byte[] picData = new byte[inFile.available()];
inFile.read(picData);
pageSetup.setFooterPicture(0,picData);
//Saving the workbook
workbook.save(“d:\temp\output.xlsx”);

Thank you. That was the issue. I didn’t actually know what the leading number in the setFooterImage call was for.


Hi David,

Thanks for using Aspose.Cells.

It is good to know that your issue is resolved now. Let us know if you encounter any other issue, we will be glad to look into it and help you further.