Document Solutions for Excel, Java Edition | Document Solutions
Features / Shapes And Pictures / Background Image
In This Topic
    Background Image
    In This Topic

    DsExcel allows you to set background image in a worksheet using the setBackgroundPicture method of the IWorksheet interface. The background image can be saved to Excel and is rendered multiple times, side by side, to cover the whole area of the worksheet.

    Using Code

    Refer to the following example code to save sheet background image in Excel.

    Java
    Copy Code
     Workbook workbook = new Workbook();
    // Fetch default worksheet
    IWorksheet worksheet = workbook.getWorksheets().get(0);
    worksheet.getRange("A1").setValue("Documents for Excel");
    worksheet.getRange("A1").getFont().setSize(25);
    
    // Load an image from a specific file in input stream
    InputStream inputStream = new FileInputStream("background-image.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);

    The background image can also be included while exporting the worksheet to PDF documents. For more information, refer to Support Sheet Background Image in this documentation.