WorksheetPart 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
定义 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)
- 继承
- 继承
- 属性
- 实现
-
IFixedContentTypePart ISupportedRelationship<CustomPropertyPart> ISupportedRelationship<EmbeddedControlPersistenceBinaryDataPart> ISupportedRelationship<EmbeddedControlPersistencePart> ISupportedRelationship<EmbeddedObjectPart> ISupportedRelationship<EmbeddedPackagePart> ISupportedRelationship<ImagePart>
示例
下面的代码示例打开一个 zip 文件,并在其中创建电子表格文档。
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
构造函数
WorksheetPart() |
创建 WorksheetPart OpenXmlType 的实例 |
属性
ContentType |
获取 ContentType。 |
ControlPropertiesParts |
获取 WorksheetPart 的 ControlPropertiesParts |
CustomPropertyParts |
获取 WorksheetPart 的 CustomPropertyParts |
DataPartReferenceRelationships |
获取所有 DataPartReferenceRelationship 关系。 (继承自 OpenXmlPartContainer) |
DrawingsPart |
获取 WorksheetPart 的绘图部分 |
EmbeddedControlPersistenceBinaryDataParts |
获取 WorksheetPart 的 EmbeddedControlPersistenceBinaryDataParts |
EmbeddedControlPersistenceParts |
获取 WorksheetPart 的 EmbeddedControlPersistenceParts |
EmbeddedObjectParts |
获取 WorksheetPart 的 EmbeddedObjectParts |
EmbeddedPackageParts |
获取 WorksheetPart 的 EmbeddedPackageParts |
ExternalRelationships |
获取所有外部关系。 不包括超链接关系,请使用 HyperlinkRelationship 属性枚举超链接关系。 (继承自 OpenXmlPartContainer) |
Features |
获取与此部件关联的特征。 |
Features |
获取与此部件关联的特征。 (继承自 OpenXmlPart) |
HyperlinkRelationships |
获取所有超链接关系。 (继承自 OpenXmlPartContainer) |
ImageParts |
获取 WorksheetPart 的 ImageParts |
IsRootElementLoaded |
获取一个值,该值指示根元素是从部件加载还是已设置。 (继承自 OpenXmlPart) |
Model3DReferenceRelationshipParts |
获取 WorksheetPart 的 Model3DReferenceRelationshipParts |
NamedSheetViewsParts |
获取 WorksheetPart 的 NamedSheetViewsParts |
OpenXmlPackage |
获取包含当前部件的 OpenXmlPackage。 (继承自 OpenXmlPart) |
Parts |
获取属于此部件的关系目标的所有部分。 (继承自 OpenXmlPartContainer) |
PivotTableParts |
获取 WorksheetPart 的数据透视表部分 |
QueryTableParts |
获取 WorksheetPart 的 QueryTableParts |
RelationshipType |
获取 RelationshipType。 |
RootElement |
获取当前部件的根元素。 当当前部件为空或不是 XML 内容类型时,返回 null。 (继承自 OpenXmlPart) |
SingleCellTablePart |
获取 WorksheetPart 的 SingleCellTablePart |
SlicersParts |
获取 WorksheetPart 的 SlicersParts |
SpreadsheetPrinterSettingsParts |
获取 WorksheetPart 的 SpreadsheetPrinterSettingsParts |
TableDefinitionParts |
获取 WorksheetPart 的 TableDefinitionParts |
TimeLineParts |
获取 WorksheetPart 的 TimeLineParts |
Uri |
获取包中的内部部件路径。 (继承自 OpenXmlPart) |
VmlDrawingParts |
获取 WorksheetPart 的 VmlDrawingParts |
Worksheet |
获取或设置此部件的根元素。 |
WorksheetCommentsPart |
获取 WorksheetPart 的 WorksheetCommentsPart |
WorksheetSortMapPart |
获取 WorksheetPart 的 WorksheetSortMapPart |
WorksheetThreadedCommentsParts |
获取 WorksheetPart 的 WorksheetThreadedCommentsParts |
方法
扩展方法
AddDisposableFeature(OpenXmlPart) |
定义 WorksheetPart |
AddPartRootEventsFeature(OpenXmlPartContainer) |
添加了一项功能,用于跟踪包生命周期事件的事件。 |
CreateUnknownElement(OpenXmlPartContainer, String) |
使用外部 XML 创建新的 OpenXmlUnknownElement 类。 |
GetXDocument(OpenXmlPart) |
获取 XDocument 的 |
GetXElement(OpenXmlPart) |
获取 XElement 的 |
IsRootXElementLoaded(OpenXmlPart) |
获取一个值, XElement 该值指示根是从部件加载还是已设置。 |
SaveXDocument(OpenXmlPart) | |
SaveXElement(OpenXmlPart) | |
SetXDocument(OpenXmlPart, XDocument) |
将 OpenXmlPart的 XDocument 设置为给定的 XDocument,序列化 XDocument 并将其写入 OpenXmlPart,如果之前已加载,则重新加载 OpenXmlPart 的 OpenXmlPartRootElement 。 |
SetXElement(OpenXmlPart, XElement) |
将 OpenXmlPart的根 XElement 设置为给定的 XElement,序列化 XElement 并将其写入 OpenXmlPart,如果之前已加载,则重新加载 OpenXmlPart OpenXmlPartRootElement 。 |