NanoXLSX.Writer 3.2.1
Loading...
Searching...
No Matches
PackagePartDefinition.cs
1/*
2 * NanoXLSX is a small .NET library to generate and read XLSX (Microsoft Excel 2007 or newer) files in an easy and native way
3 * Copyright Raphael Stoeckli © 2026
4 * This library is licensed under the MIT License.
5 * You find a copy of the license in project folder or on: http://opensource.org/licenses/MIT
6 */
7
8using NanoXLSX.Interfaces.Writer;
9using System.Collections.Generic;
10using System.IO.Packaging;
11using System.Linq;
12
14{
19 internal class PackagePartDefinition
20 {
21
22 #region staticFields
26 internal const int WORKBOOK_PACKAGE_PART_INDEX = 0;
30 internal const int METADATA_PACKAGE_PART_START_INDEX = 1000;
34 internal const int WORKSHEET_PACKAGE_PART_START_INDEX = 10000;
38 internal const int POST_WORkSHEET_PACKAGE_PART_START_INDEX = 2000000;
39 #endregion
40
41 #region enums
45 internal enum PackagePartType
46 {
50 Root,
54 Worksheet,
58 Other,
59 }
60 #endregion
61
65 public DocumentPath Path { get; private set; }
69 public PackagePartType PartType { get; private set; }
73 public int OrderNumber { get; private set; }
77 public string ContentType { get; private set; }
81 public string RelationshipType { get; private set; }
85 internal string UniquePackagePartIndex { get; private set; }
89 internal IReadOnlyList<PackagePartRelationshipDefinition> Relationships { get; private set; }
90
100 public PackagePartDefinition(PackagePartType type, int orderNumber, string fileNameInPackage, string pathInPackage, string contentType, string relationshipType)
101 : this(type, orderNumber, new DocumentPath(fileNameInPackage, pathInPackage), contentType, relationshipType)
102 { }
103
112 internal PackagePartDefinition(PackagePartType type, int orderNumber, DocumentPath documentPath, string contentType, string relationshipType)
113 : this(type, orderNumber, documentPath, contentType, relationshipType, null)
114 {
115 }
116
126 internal PackagePartDefinition(PackagePartType type, int orderNumber, DocumentPath documentPath, string contentType, string relationshipType, string uniquePackagePartIndex)
127 : this(type, orderNumber, documentPath, contentType, relationshipType, uniquePackagePartIndex, null)
128 {
129 }
130
141 internal PackagePartDefinition(PackagePartType type, int orderNumber, DocumentPath documentPath, string contentType, string relationshipType, string uniquePackagePartIndex, IReadOnlyList<IPluginPackageRelationship> relationships)
142 {
143 this.PartType = type;
144 this.OrderNumber = orderNumber;
145 this.Path = documentPath;
146 this.ContentType = contentType;
147 this.RelationshipType = relationshipType;
148 this.UniquePackagePartIndex = uniquePackagePartIndex;
149 this.Relationships = relationships == null
150 ? new List<PackagePartRelationshipDefinition>()
151 : relationships.Select(relationship => new PackagePartRelationshipDefinition(relationship)).ToList();
152 }
153
159 internal int GetWorksheetIndex()
160 {
161 return this.OrderNumber - WORKSHEET_PACKAGE_PART_START_INDEX;
162 }
163
169 internal static List<PackagePartDefinition> Sort(List<PackagePartDefinition> packagePartDefinitions)
170 {
171 return packagePartDefinitions.OrderBy(p => p.OrderNumber).ToList();
172 }
173 }
174
178 internal sealed class PackagePartRelationshipDefinition
179 {
180 internal string RelationshipId { get; private set; }
181 internal string RelationshipType { get; private set; }
182 internal string Target { get; private set; }
183 internal TargetMode TargetMode { get; private set; }
184
185 internal PackagePartRelationshipDefinition(IPluginPackageRelationship relationship)
186 {
187 RelationshipId = relationship.RelationshipId;
188 RelationshipType = relationship.RelationshipType;
189 Target = relationship.Target;
190 TargetMode = relationship.TargetMode;
191 }
192 }
193
194}