将背景图像插入 Excel
Contents
[
Hide
]
您可以通过添加图片作为工作表背景来使工作表更具吸引力。如果您有一个特殊的公司图形,可以在不遮挡工作表上的数据的情况下添加背景提示,则此功能会非常有效。您可以使用 Aspose.Cells API 为工作表设置背景图片。
在 Microsoft Excel 中设置工作表背景
要在 Microsoft Excel(例如 Microsoft Excel 2019)中设置工作表的背景图像:
-
来自页面布局菜单,找到页面设置选项,然后单击背景选项。
-
选择一张图片以设置工作表的背景图片。
设置工作表背景
使用 Aspose.Cells 设置工作表背景
下面的代码使用流中的图像设置背景图像。
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-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"); |