WorksheetPart Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Defines the WorksheetPart
public class WorksheetPart : DocumentFormat.OpenXml.Packaging.OpenXmlPart, DocumentFormat.OpenXml.Packaging.IFixedContentTypePart
public class WorksheetPart : DocumentFormat.OpenXml.Packaging.TypedOpenXmlPart, DocumentFormat.OpenXml.Packaging.IFixedContentTypePart
[DocumentFormat.OpenXml.OfficeAvailability(DocumentFormat.OpenXml.FileFormatVersions.Office2007)]
public class WorksheetPart : DocumentFormat.OpenXml.Packaging.OpenXmlPart, DocumentFormat.OpenXml.Packaging.IFixedContentTypePart
public class WorksheetPart : DocumentFormat.OpenXml.Packaging.OpenXmlPart, DocumentFormat.OpenXml.Packaging.IFixedContentTypePart, DocumentFormat.OpenXml.Packaging.ISupportedRelationship<DocumentFormat.OpenXml.Packaging.CustomPropertyPart>, DocumentFormat.OpenXml.Packaging.ISupportedRelationship<DocumentFormat.OpenXml.Packaging.EmbeddedControlPersistenceBinaryDataPart>, DocumentFormat.OpenXml.Packaging.ISupportedRelationship<DocumentFormat.OpenXml.Packaging.EmbeddedControlPersistencePart>, DocumentFormat.OpenXml.Packaging.ISupportedRelationship<DocumentFormat.OpenXml.Packaging.EmbeddedObjectPart>, DocumentFormat.OpenXml.Packaging.ISupportedRelationship<DocumentFormat.OpenXml.Packaging.EmbeddedPackagePart>, DocumentFormat.OpenXml.Packaging.ISupportedRelationship<DocumentFormat.OpenXml.Packaging.ImagePart>
type WorksheetPart = class
inherit OpenXmlPart
interface IFixedContentTypePart
type WorksheetPart = class
inherit TypedOpenXmlPart
interface IFixedContentTypePart
[<DocumentFormat.OpenXml.OfficeAvailability(DocumentFormat.OpenXml.FileFormatVersions.Office2007)>]
type WorksheetPart = class
inherit OpenXmlPart
interface IFixedContentTypePart
type WorksheetPart = class
inherit OpenXmlPart
interface IFixedContentTypePart
interface ISupportedRelationship<CustomPropertyPart>
interface ISupportedRelationship<EmbeddedControlPersistenceBinaryDataPart>
interface ISupportedRelationship<EmbeddedControlPersistencePart>
interface ISupportedRelationship<EmbeddedObjectPart>
interface ISupportedRelationship<EmbeddedPackagePart>
interface ISupportedRelationship<ImagePart>
Public Class WorksheetPart
Inherits OpenXmlPart
Implements IFixedContentTypePart
Public Class WorksheetPart
Inherits TypedOpenXmlPart
Implements IFixedContentTypePart
Public Class WorksheetPart
Inherits OpenXmlPart
Implements IFixedContentTypePart, ISupportedRelationship(Of CustomPropertyPart), ISupportedRelationship(Of EmbeddedControlPersistenceBinaryDataPart), ISupportedRelationship(Of EmbeddedControlPersistencePart), ISupportedRelationship(Of EmbeddedObjectPart), ISupportedRelationship(Of EmbeddedPackagePart), ISupportedRelationship(Of ImagePart)
- Inheritance
- Inheritance
- Attributes
- Implements
-
IFixedContentTypePart ISupportedRelationship<CustomPropertyPart> ISupportedRelationship<EmbeddedControlPersistenceBinaryDataPart> ISupportedRelationship<EmbeddedControlPersistencePart> ISupportedRelationship<EmbeddedObjectPart> ISupportedRelationship<EmbeddedPackagePart> ISupportedRelationship<ImagePart>
Examples
The following code example opens a zip file and creates a spreadsheet document into it.
using System;
using System.IO.Packaging;
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;
namespace WorkSheetPartEx
{
class Program
{
// Create a spreadsheet by Package.
static void Main(string[] args)
{
string fileName = @"C:\users\public\documents\WorkSheetPartEx.zip";
// Open a package file.
Package package = Package.Open(fileName);
// Create the spreadsheet document.
SpreadsheetDocument spreadsheetDocument =
SpreadsheetDocument.Create(package, SpreadsheetDocumentType.Template);
// Add a WorkbookPart.
WorkbookPart workbookpart = spreadsheetDocument.AddWorkbookPart();
workbookpart.Workbook = new Workbook();
// Add a WorksheetPart.
WorksheetPart worksheetPart = workbookpart.AddNewPart<WorksheetPart>();
worksheetPart.Worksheet = new Worksheet(new SheetData());
// Add a sheets list.
Sheets sheets = spreadsheetDocument.WorkbookPart.Workbook
.AppendChild<Sheets>(new Sheets());
// Append the new worksheet and associate it with the workbook.
Sheet sheet = new Sheet() { Id = spreadsheetDocument.WorkbookPart
.GetIdOfPart(worksheetPart), SheetId = 1, Name = "mySheet" };
sheets.Append(sheet);
// Close the spreadsheet and the package.
spreadsheetDocument.Close();
package.Close();
Console.WriteLine("The package has been created.\nPress a key.");
Console.ReadKey();
}
}
}
Imports System.IO.Packaging
Imports DocumentFormat.OpenXml
Imports DocumentFormat.OpenXml.Packaging
Imports DocumentFormat.OpenXml.Spreadsheet
Module Module1
' Create a spreadsheet by Package.
Sub Main(ByVal args As String())
Dim fileName As String = "C:\users\public\documents\WorkSheetPartEx.zip"
' Open a package file.
Dim package As Package = package.Open(fileName)
' Create the spreadsheet document.
Dim spreadsheetDocument As SpreadsheetDocument = spreadsheetDocument.Create(package, SpreadsheetDocumentType.Template)
' Add a WorkbookPart.
Dim workbookpart As WorkbookPart = spreadsheetDocument.AddWorkbookPart()
workbookpart.Workbook = New Workbook()
' Add a WorksheetPart.
Dim worksheetPart As WorksheetPart = workbookpart.AddNewPart(Of WorksheetPart)()
worksheetPart.Worksheet = New Worksheet(New SheetData())
' Add a sheets list.
Dim sheets As Sheets = spreadsheetDocument.WorkbookPart.Workbook.AppendChild(Of Sheets)(New Sheets())
' Append the new worksheet and associate it with the workbook.
Dim sheet As New Sheet() With { _
.Id = spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart), _
.SheetId = 1, _
.Name = "mySheet" _
}
sheets.Append(sheet)
' Close the spreadsheet and the package.
spreadsheetDocument.Close()
package.Close()
Console.WriteLine("The package has been created." & vbLf & "Press a key.")
Console.ReadKey()
End Sub
End Module
Constructors
WorksheetPart() |
Creates an instance of the WorksheetPart OpenXmlType |
Properties
ContentType |
Gets the ContentType. |
ControlPropertiesParts |
Gets the ControlPropertiesParts of the WorksheetPart |
CustomPropertyParts |
Gets the CustomPropertyParts of the WorksheetPart |
DataPartReferenceRelationships |
Gets all DataPartReferenceRelationship relationships. (Inherited from OpenXmlPartContainer) |
DrawingsPart |
Gets the DrawingsPart of the WorksheetPart |
EmbeddedControlPersistenceBinaryDataParts |
Gets the EmbeddedControlPersistenceBinaryDataParts of the WorksheetPart |
EmbeddedControlPersistenceParts |
Gets the EmbeddedControlPersistenceParts of the WorksheetPart |
EmbeddedObjectParts |
Gets the EmbeddedObjectParts of the WorksheetPart |
EmbeddedPackageParts |
Gets the EmbeddedPackageParts of the WorksheetPart |
ExternalRelationships |
Gets all external relationships. Hyperlink relationships are not included, use HyperlinkRelationship property to enumerate hyperlink relationships. (Inherited from OpenXmlPartContainer) |
Features |
Gets the features associated with this part. |
Features |
Gets the features associated with this part. (Inherited from OpenXmlPart) |
HyperlinkRelationships |
Gets all hyperlink relationships. (Inherited from OpenXmlPartContainer) |
ImageParts |
Gets the ImageParts of the WorksheetPart |
IsRootElementLoaded |
Gets a value indicating whether the root element is loaded from the part or it has been set. (Inherited from OpenXmlPart) |
Model3DReferenceRelationshipParts |
Gets the Model3DReferenceRelationshipParts of the WorksheetPart |
NamedSheetViewsParts |
Gets the NamedSheetViewsParts of the WorksheetPart |
OpenXmlPackage |
Gets the OpenXmlPackage which contains the current part. (Inherited from OpenXmlPart) |
Parts |
Gets all parts which are relationship targets of this part. (Inherited from OpenXmlPartContainer) |
PivotTableParts |
Gets the PivotTableParts of the WorksheetPart |
QueryTableParts |
Gets the QueryTableParts of the WorksheetPart |
RelationshipType |
Gets the RelationshipType. |
RootElement |
Gets the root element of the current part. Returns null when the current part is empty or is not an XML content type. (Inherited from OpenXmlPart) |
SingleCellTablePart |
Gets the SingleCellTablePart of the WorksheetPart |
SlicersParts |
Gets the SlicersParts of the WorksheetPart |
SpreadsheetPrinterSettingsParts |
Gets the SpreadsheetPrinterSettingsParts of the WorksheetPart |
TableDefinitionParts |
Gets the TableDefinitionParts of the WorksheetPart |
TimeLineParts |
Gets the TimeLineParts of the WorksheetPart |
Uri |
Gets the internal part path in the package. (Inherited from OpenXmlPart) |
VmlDrawingParts |
Gets the VmlDrawingParts of the WorksheetPart |
Worksheet |
Gets or sets the root element of this part. |
WorksheetCommentsPart |
Gets the WorksheetCommentsPart of the WorksheetPart |
WorksheetSortMapPart |
Gets the WorksheetSortMapPart of the WorksheetPart |
WorksheetThreadedCommentsParts |
Gets the WorksheetThreadedCommentsParts of the WorksheetPart |
Methods
AddAnnotation(Object) |
Adds an object to the annotation list of this PartContainer. (Inherited from OpenXmlPartContainer) |
AddCustomPropertyPart(CustomPropertyPartType, String) |
Adds a CustomPropertyPart to the WorksheetPart |
AddCustomPropertyPart(CustomPropertyPartType) |
Adds a CustomPropertyPart to the WorksheetPart |
AddCustomPropertyPart(String, String) |
Adds a CustomPropertyPart to the WorksheetPart |
AddCustomPropertyPart(String) |
Adds a CustomPropertyPart to the WorksheetPart |
AddEmbeddedControlPersistenceBinaryDataPart(EmbeddedControlPersistenceBinaryDataPartType, String) |
Adds a EmbeddedControlPersistenceBinaryDataPart to the WorksheetPart |
AddEmbeddedControlPersistenceBinaryDataPart(EmbeddedControlPersistenceBinaryDataPartType) |
Adds a EmbeddedControlPersistenceBinaryDataPart to the WorksheetPart |
AddEmbeddedControlPersistenceBinaryDataPart(String, String) |
Adds a EmbeddedControlPersistenceBinaryDataPart to the WorksheetPart |
AddEmbeddedControlPersistenceBinaryDataPart(String) |
Adds a EmbeddedControlPersistenceBinaryDataPart to the WorksheetPart |
AddEmbeddedControlPersistencePart(EmbeddedControlPersistencePartType, String) |
Adds a EmbeddedControlPersistencePart to the WorksheetPart |
AddEmbeddedControlPersistencePart(EmbeddedControlPersistencePartType) |
Adds a EmbeddedControlPersistencePart to the WorksheetPart |
AddEmbeddedControlPersistencePart(String, String) |
Adds a EmbeddedControlPersistencePart to the WorksheetPart |
AddEmbeddedControlPersistencePart(String) |
Adds a EmbeddedControlPersistencePart to the WorksheetPart |
AddEmbeddedObjectPart(EmbeddedObjectPartType, String) | |
AddEmbeddedObjectPart(EmbeddedObjectPartType) | |
AddEmbeddedObjectPart(String, String) | |
AddEmbeddedObjectPart(String) |
Adds a EmbeddedObjectPart to the WorksheetPart |
AddEmbeddedPackagePart(EmbeddedPackagePartType, String) | |
AddEmbeddedPackagePart(EmbeddedPackagePartType) | |
AddEmbeddedPackagePart(String, String) | |
AddEmbeddedPackagePart(String) |
Adds a EmbeddedPackagePart to the WorksheetPart |
AddExtendedPart(String, String, String, String) |
Adds an extended part ( Application specific part ). (Inherited from OpenXmlPartContainer) |
AddExtendedPart(String, String, String) |
Adds an extended part ( Application specific part ). (Inherited from OpenXmlPartContainer) |
AddExternalRelationship(String, Uri, String) |
Adds an external relationship. Do not add hyperlink relationships through this method. Use AddHyperlinkRelationship() instead. (Inherited from OpenXmlPartContainer) |
AddExternalRelationship(String, Uri) |
Adds an external relationship. Do not add hyperlink relationships through this method. Use AddHyperlinkRelationship() instead. (Inherited from OpenXmlPartContainer) |
AddHyperlinkRelationship(Uri, Boolean, String) |
Adds a new hyperlink relationship. (Inherited from OpenXmlPartContainer) |
AddHyperlinkRelationship(Uri, Boolean) |
Adds a new hyperlink relationship. (Inherited from OpenXmlPartContainer) |
AddImagePart(ImagePartType, String) |
Adds a ImagePart to the WorksheetPart |
AddImagePart(ImagePartType) |
Adds a ImagePart to the WorksheetPart |
AddImagePart(String, String) |
Adds a ImagePart to the WorksheetPart |
AddImagePart(String) |
Adds a ImagePart to the WorksheetPart |
AddNewPart<T>() |
Adds a new part of type T. (Inherited from OpenXmlPartContainer) |
AddNewPart<T>(String, String) |
Adds a new part of type T. (Inherited from OpenXmlPartContainer) |
AddNewPart<T>(String) |
Adds a new part of type T. (Inherited from OpenXmlPartContainer) |
AddPart<T>(T, String) |
Adds the part to the document with a given relationship identifier (ID). Must use the returned part to operate on the part added to the document (Inherited from OpenXmlPartContainer) |
AddPart<T>(T) |
Adds the part to the document. Must use the returned part to operate on the part added to the document. (Inherited from OpenXmlPartContainer) |
Annotation(Type) |
Get the first annotation object of the specified type from this PartContainer. (Inherited from OpenXmlPartContainer) |
Annotation<T>() |
Get the first annotation object of the specified type from this PartContainer. (Inherited from OpenXmlPartContainer) |
Annotations(Type) |
Gets a collection of annotations of the specified type for this PartContainer. (Inherited from OpenXmlPartContainer) |
Annotations<T>() |
Gets a collection of annotations of the specified type for this PartContainer. (Inherited from OpenXmlPartContainer) |
ChangeIdOfPart(OpenXmlPart, String) |
Changes the relationship ID of the part. (Inherited from OpenXmlPartContainer) |
CreateRelationshipToPart(OpenXmlPart, String) |
Adds a relationship for the specified part to this part. (Inherited from OpenXmlPartContainer) |
CreateRelationshipToPart(OpenXmlPart) |
Adds a relationship for the specified part to this part. (Inherited from OpenXmlPartContainer) |
DeleteExternalRelationship(ExternalRelationship) |
Deletes the specified external relationship. (Inherited from OpenXmlPartContainer) |
DeleteExternalRelationship(String) |
Deletes the specified ExternalRelationship. (Inherited from OpenXmlPartContainer) |
DeletePart(OpenXmlPart) |
Deletes a specified part in the package root layer. (Inherited from OpenXmlPartContainer) |
DeletePart(String) |
Deletes the specified child part from this part. (Inherited from OpenXmlPartContainer) |
DeleteParts<T>(IEnumerable<T>) |
Deletes all the parts which are in the passed in collection from the document. (Inherited from OpenXmlPartContainer) |
DeleteReferenceRelationship(ReferenceRelationship) |
Deletes the specified reference relationship. (Inherited from OpenXmlPartContainer) |
DeleteReferenceRelationship(String) |
Deletes the specified reference relationship. (Inherited from OpenXmlPartContainer) |
FeedData(Stream) |
Feeds data into the part stream. The stream of the part will be truncated at first. (Inherited from OpenXmlPart) |
GetExternalRelationship(String) |
Gets the specified ExternalRelationship. (Inherited from OpenXmlPartContainer) |
GetIdOfPart(OpenXmlPart) |
Gets the relationship ID of the part. (Inherited from OpenXmlPartContainer) |
GetParentParts() |
Enumerates all parents that reference this part anywhere in the document. (Inherited from OpenXmlPart) |
GetPartById(String) |
Gets the child part through the relationship ID. (Inherited from OpenXmlPartContainer) |
GetPartsCountOfType<T>() |
Obsolete.
Gets the count of all parts of type T. (Inherited from OpenXmlPartContainer) |
GetPartsOfType<T>() |
Enumerates all the children parts of the specified type |
GetPartsOfType<T>(ICollection<T>) |
Obsolete.
Gets all the children parts of the specified type |
GetReferenceRelationship(String) |
Gets the specified ReferenceRelationship. (Inherited from OpenXmlPartContainer) |
GetStream() |
Returns the part content data stream. (Inherited from OpenXmlPart) |
GetStream(FileMode, FileAccess) |
Returns the part content stream that was opened using a specified FileMode and FileAccess. (Inherited from OpenXmlPart) |
GetStream(FileMode) |
Returns the content stream that was opened using a specified I/O FileMode. (Inherited from OpenXmlPart) |
RemoveAnnotations(Type) |
Removes the annotations of the specified type from this PartContainer. (Inherited from OpenXmlPartContainer) |
RemoveAnnotations<T>() |
Removes the annotations of the specified type from this PartContainer. (Inherited from OpenXmlPartContainer) |
ThrowIfObjectDisposed() |
Indicates whether the object is already disposed. (Inherited from OpenXmlPart) |
TryGetPartById(String, OpenXmlPart) |
Try to get the child part by the relationship ID. (Inherited from OpenXmlPartContainer) |
UnloadRootElement() |
Unloads the RootElement. (Inherited from OpenXmlPart) |
ValidateXml(String, ValidationEventHandler) |
Obsolete.
Validates the XML content of the part by using the specified schema. (Inherited from OpenXmlPart) |
ValidateXml(XmlSchemaSet, ValidationEventHandler) |
Obsolete.
Validates the XML content of the part by using the specified schema. (Inherited from OpenXmlPart) |
Extension Methods
AddDisposableFeature(OpenXmlPart) | |
AddPartRootEventsFeature(OpenXmlPartContainer) |
Adds a feature to track eventing for package life cycle events. |
CreateUnknownElement(OpenXmlPartContainer, String) |
Creates a new OpenXmlUnknownElement class by using the outer XML. |
GetXDocument(OpenXmlPart) |
Gets an XDocument representation of the |
GetXElement(OpenXmlPart) |
Gets an XElement representation of the |
IsRootXElementLoaded(OpenXmlPart) |
Gets a value indicating whether the root XElement is loaded from the part or it has been set. |
SaveXDocument(OpenXmlPart) |
Saves the current XDocument to the part if it and its Root
element is not |
SaveXElement(OpenXmlPart) |
Saves the current XDocument to the part if it and its Root
element is not |
SetXDocument(OpenXmlPart, XDocument) |
Sets the OpenXmlPart's XDocument to the given XDocument, serializes and writes the XDocument to the OpenXmlPart, and reloads the OpenXmlPart's OpenXmlPartRootElement if it was previously loaded. |
SetXElement(OpenXmlPart, XElement) |
Sets the OpenXmlPart's root XElement to the given XElement, serializes and writes the XElement to the OpenXmlPart, and reloads the OpenXmlPart's OpenXmlPartRootElement if it was previously loaded. |