8using NanoXLSX.Interfaces.Writer;
9using System.Collections.Generic;
10using System.IO.Packaging;
19 internal class PackagePartDefinition
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;
45 internal enum PackagePartType
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; }
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)
112 internal PackagePartDefinition(PackagePartType type,
int orderNumber, DocumentPath documentPath,
string contentType,
string relationshipType)
113 : this(type, orderNumber, documentPath, contentType, relationshipType, null)
126 internal PackagePartDefinition(PackagePartType type,
int orderNumber, DocumentPath documentPath,
string contentType,
string relationshipType,
string uniquePackagePartIndex)
127 : this(type, orderNumber, documentPath, contentType, relationshipType, uniquePackagePartIndex, null)
141 internal PackagePartDefinition(PackagePartType type,
int orderNumber, DocumentPath documentPath,
string contentType,
string relationshipType,
string uniquePackagePartIndex, IReadOnlyList<IPluginPackageRelationship> relationships)
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();
159 internal int GetWorksheetIndex()
161 return this.OrderNumber - WORKSHEET_PACKAGE_PART_START_INDEX;
169 internal static List<PackagePartDefinition> Sort(List<PackagePartDefinition> packagePartDefinitions)
171 return packagePartDefinitions.OrderBy(p => p.OrderNumber).ToList();
178 internal sealed class PackagePartRelationshipDefinition
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; }
185 internal PackagePartRelationshipDefinition(IPluginPackageRelationship relationship)
187 RelationshipId = relationship.RelationshipId;
188 RelationshipType = relationship.RelationshipType;
189 Target = relationship.Target;
190 TargetMode = relationship.TargetMode;