//create a new workbook var workbook = new GrapeCity.Documents.Excel.Workbook(); IWorksheet worksheet = workbook.Worksheets[0]; Stream stream = this.GetResourceStream("Chrome_icon.png"); byte[] imageBytes; using (MemoryStream memoryStream = new MemoryStream()) { stream.CopyTo(memoryStream); imageBytes = memoryStream.ToArray(); } worksheet.Range["A2:E2"].Value = new string[] { "Stretch", "Center", "Zoom", "None", "Default(Stretch)" }; worksheet.Range["A3:E3"].Value = "Chrome"; worksheet.Range["A3:E3"].RowHeightInPixel = 80; worksheet.Range["A3:E3"].ColumnWidthInPixel = 100; //Add cell background picture worksheet.Range["A3:E3"].BackgroundImage = imageBytes; //Set image layout worksheet.Range["A3"].BackgroundImageLayout = BackgroundImageLayout.Stretch; worksheet.Range["B3"].BackgroundImageLayout = BackgroundImageLayout.Center; worksheet.Range["C3"].BackgroundImageLayout = BackgroundImageLayout.Zoom; worksheet.Range["D3"].BackgroundImageLayout = BackgroundImageLayout.None; //Set options workbook.ActiveSheet.PageSetup.PrintGridlines = true; workbook.ActiveSheet.PageSetup.PrintHeadings = true; // Save to a pdf file workbook.Save("CellBackgroundImage.pdf");
' Create a new Workbook Dim workbook As New Workbook Dim worksheet As IWorksheet = workbook.Worksheets(0) Dim stream As Stream = Me.GetResourceStream("Chrome_icon.png") Dim imageBytes() As Byte Using memoryStream As New MemoryStream() stream.CopyTo(memoryStream) imageBytes = memoryStream.ToArray() End Using worksheet.Range("A2:E2").Value = New String() {"Stretch", "Center", "Zoom", "None", "Default"} worksheet.Range("A3:E3").Value = "Chrome" worksheet.Range("A3:E3").RowHeightInPixel = 100 worksheet.Range("A3:E3").ColumnWidthInPixel = 100 'Add cell background picture worksheet.Range("A3:E3").BackgroundImage = imageBytes 'Set image layout worksheet.Range("A3").BackgroundImageLayout = BackgroundImageLayout.Stretch worksheet.Range("B3").BackgroundImageLayout = BackgroundImageLayout.Center worksheet.Range("C3").BackgroundImageLayout = BackgroundImageLayout.Zoom worksheet.Range("D3").BackgroundImageLayout = BackgroundImageLayout.None 'Set options workbook.ActiveSheet.PageSetup.PrintGridlines = True workbook.ActiveSheet.PageSetup.PrintHeadings = True ' save to a pdf file workbook.Save("CellBackgroundImage.pdf")