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 Sheet Background with Aspose.Cells

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

import jpype
import asposecells
jpype.startJVM()
from asposecells.api import Workbook
# Create a new Workbook.
workbook = Workbook()
# Get the first worksheet.
worksheet = workbook.getWorksheets().get(0)
# Get the background picture.
with open('Background.jpg', 'rb') as f:
data = f.read()
# Set the background image for the sheet.
worksheet.setBackgroundImage(data)
# Save the excel file
workbook.save("output.xlsx")
jpype.shutdownJVM()