This documentation is archived and is not being maintained.

SpreadsheetDocument.AddNewPart<T> Method (String, String)

Adds a new part of type .

Namespace:  DocumentFormat.OpenXml.Packaging
Assembly:  DocumentFormat.OpenXml (in DocumentFormat.OpenXml.dll)

public override T AddNewPart<T>(
	string contentType,
	string id
)
where T : OpenXmlPart

Type Parameters

T

The class of the part.

Parameters

contentType
Type: System.String
The content type of the part. Must match the defined content type if the part is fixed content type.
id
Type: System.String
The relationship id. The id will be automaticly generated if this param is null.

Return Value

Type: T
The added part.

ExceptionCondition
OpenXmlPackageException

When the part is not allowed to be referenced by this part.

ArgumentOutOfRangeException

When the part is fixed content type and the passed in contentType does not match the defined content type.

ArgumentNullException

Thrown when "contentType" is null reference.

Mainly used for adding not-fixed content type part - ImagePart, VideoPart, AudioPart, etc

Show: