Back to Devexpress

WorksheetHeaderFooter.AddPicture(SpreadsheetImageSource, HeaderFooterSection) Method

officefileapi-devexpress-dot-spreadsheet-dot-worksheetheaderfooter-dot-addpicture-x28-devexpress-dot-spreadsheet-dot-spreadsheetimagesource-devexpress-dot-spreadsheet-dot-headerfootersection-x29.md

latest4.5 KB
Original Source

WorksheetHeaderFooter.AddPicture(SpreadsheetImageSource, HeaderFooterSection) Method

Adds a picture to the worksheet header or footer.

Namespace : DevExpress.Spreadsheet

Assembly : DevExpress.Spreadsheet.v25.2.Core.dll

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
HeaderFooterPicture AddPicture(
    SpreadsheetImageSource imageSource,
    HeaderFooterSection section
)
vb
Function AddPicture(
    imageSource As SpreadsheetImageSource,
    section As HeaderFooterSection
) As HeaderFooterPicture

Parameters

NameTypeDescription
imageSourceSpreadsheetImageSource

An object that specifies the image source.

| | section | HeaderFooterSection |

Specifies the header or footer section to which the image should be added.

|

Returns

TypeDescription
HeaderFooterPicture

The picture added to the header or footer.

|

Remarks

The example below demonstrates how to use the AddPicture method to insert a picture into a header and footer.

csharp
// Set measurement unit to inches.
workbook.Unit = DevExpress.Office.DocumentUnit.Inch;
// Access header and footer options.
WorksheetHeaderFooterOptions options = worksheet.HeaderFooterOptions;
// Specify that the first page has a unique header and footer.
options.DifferentFirst = true;

// Insert a picture in the center of the footer.
options.FirstFooter.AddPicture("DxLogo.png", HeaderFooterSection.Center);

// Add an inline picture to the header's left section.
HeaderFooterPicture picture = options.FirstHeader.AddPicture(SpreadsheetImageSource.FromFile("DevAvLogo.png"), HeaderFooterSection.Left);
// Use the &G code to specify the picture position within text.
options.FirstHeader.Left = string.Format("{0}&BDev{1}AV &G", 
    HeaderFooterCode.FontColor(Color.FromArgb(0x05, 0x6f, 0xCE)), HeaderFooterCode.FontColor(Color.FromArgb(0x39, 0xA6, 0xF7)));
// Specify the picture size in inches.
picture.Height = 0.3f;
picture.Width = 0.3f;
vb
' Set measurement unit to inches.
workbook.Unit = DevExpress.Office.DocumentUnit.Inch
' Access header and footer options.
Dim options As WorksheetHeaderFooterOptions = worksheet.HeaderFooterOptions
' Specify that the first page has a unique header and footer.
options.DifferentFirst = True

' Insert a picture in the center of the footer.
options.FirstFooter.AddPicture("DxLogo.png", HeaderFooterSection.Center)

' Add an inline picture to the header's left section.
Dim picture As HeaderFooterPicture = options.FirstHeader.AddPicture(SpreadsheetImageSource.FromFile("DevAvLogo.png"), HeaderFooterSection.Left)
' Use the &G code to specify the picture position within text.
options.FirstHeader.Left = String.Format("{0}&BDev{1}AV &G",
                                         HeaderFooterCode.FontColor(Color.FromArgb(&H5, &H6F, &HCE)),
                                         HeaderFooterCode.FontColor(Color.FromArgb(&H39, &HA6, &HF7)))
' Specify the picture size in inches.
picture.Height = 0.3F
picture.Width = 0.3F

Note

Call the WorksheetHeaderFooter.AddPicture method before you use the &G code to insert an inline picture into a header or footer. System.InvalidOperationException occurs when the Spreadsheet cannot find the picture.

See Also

WorksheetHeaderFooter Interface

WorksheetHeaderFooter Members

DevExpress.Spreadsheet Namespace