[]
        
(Showing Draft Content)

背景图片

GcExcel允许您使用 IWorksheet 接口的 setBackgroundPicture 方法在工作表中设置背景图像。背景图像可以保存到Excel中,并排呈现多次,以覆盖工作表的整个区域。

用例代码

请参阅以下示例代码以在Excel中保存表单背景图像。

 Workbook workbook = new Workbook();
// Fetch default worksheet
IWorksheet worksheet = workbook.getWorksheets().get(0);
worksheet.getRange("A1").setValue("GrapeCity Documents for Excel");
worksheet.getRange("A1").getFont().setSize(25);

// Load an image from a specific file in input stream
InputStream inputStream = new FileInputStream("grapecity.png");
try {
    byte[] bytes = new byte[inputStream.available()];
    // Read an image from input stream
    inputStream.read(bytes, 0, bytes.length);

    // Add background image of the worksheet
    worksheet.setBackgroundPicture(bytes);
} catch (IOException ioe) {
    ioe.printStackTrace();
}

// Save workbook
workbook.save("PrintBackgroundPicture.xlsx", SaveFileFormat.Xlsx);

将工作表导出为PDF文档时,也可以包含背景图像。有关更多信息,请参阅本文档中的 支持表单背景图片