Insert Background Image to Excel with Node.js via C++

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 a sheet background

todo:image_alt_text

Setting Sheet Background with Aspose.Cells for Node.js via C++

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

const fs = require("fs");
const path = require("path");
const AsposeCells = require("aspose.cells.node");

// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
const backgroundImagePath = path.join(dataDir, "background.jpg");

// Create a new Workbook.
const workbook = new AsposeCells.Workbook();

// Get the first worksheet.
const sheet = workbook.getWorksheets().get(0);

// Set the background image for the worksheet.
sheet.setBackgroundImage(fs.readFileSync(backgroundImagePath).buffer);

// Save the Excel file
workbook.save("outputBackImageSheet.xlsx");

// Save the HTML file
workbook.save("outputBackImageSheet.html", AsposeCells.SaveFormat.Html);