Insert Background Image to Excel

Setting Sheet Background in Microsoft Excel

To set a sheet’s background image in Microsoft Excel (for example, Microsoft Excel 2019):

  1. From the Page Layout menu, find the Page Setup option, and then click the Background option.

  2. Select a picture to set the sheet’s background picture.

    Setting a sheet background

todo:image_alt_text

Setting Sheet Background with Aspose.Cells

The code below sets a background image using an image from a stream.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// Create a new Workbook.
Workbook workbook = new Workbook();
// Get the first worksheet.
Worksheet sheet = workbook.getWorksheets().get(0);
// Get the image file.
File file = new File("background.jpg");
// Get the picture into the streams.
byte[] imageData = new byte[(int) file.length()];
FileInputStream fis = new FileInputStream(file);
fis.read(imageData);
// Set the background image for the sheet.
sheet.setBackgroundImage(imageData);
fis.close();
// Save the excel file
workbook.save("SBPforWorksheet.xlsx");