DsExcel allows you to set background image in a worksheet using the BackgroundPicture property 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.
Refer to the following example code to save sheet background image in Excel.
C# |
Copy Code |
---|---|
// Initialize workbook Workbook workbook = new Workbook(); // Fetch default worksheet IWorksheet worksheet = workbook.Worksheets[0]; worksheet.Range["A1"].Value = "Documents for Excel"; worksheet.Range["A1"].Font.Size = 25; using (FileStream pictureStream = File.Open(@"image.png", FileMode.Open, FileAccess.Read)) { MemoryStream pictureMemoryStream = new MemoryStream(); pictureStream.CopyTo(pictureMemoryStream); byte[] picturebytes = pictureMemoryStream.ToArray(); //Add background image of the worksheet worksheet.BackgroundPicture = picturebytes; } workbook.Save(@"SetBackgroundImage.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.