Insert Background Image to Excel
Contents
[
Hide
]
You can make a worksheet more appealing by adding a picture as a worksheet background. This feature can be quite effective if you have a special corporate graphic that adds a hint of the background without obscuring the data on the sheet. You can set background picture for a sheet using Aspose.Cells API.
Setting Sheet Background in Microsoft Excel
To set a sheet’s background image in Microsoft Excel (for example, Microsoft Excel 2019):
-
From the Page Layout menu, find the Page Setup option, and then click the Background option.
-
Select a picture to set the sheet’s background picture.
Setting a sheet background
Setting Sheet Background with Aspose.Cells
The code below sets a background image using an image from a stream.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Create a new Workbook. | |
Workbook workbook = new Workbook(); | |
// Get the first worksheet. | |
Worksheet sheet = workbook.Worksheets[0]; | |
// Set the background image for the worksheet. | |
sheet.BackgroundImage = File.ReadAllBytes("background.jpg"); | |
// Save the Excel file | |
workbook.Save("outputBackImageSheet.xlsx"); | |
// Save the HTML file | |
workbook.Save("outputBackImageSheet.html", SaveFormat.Html); |