コード例 #1
0
 /**
  * Create a new child POIXMLDocumentPart
  *
  * @param descriptor the part descriptor
  * @param factory the factory that will create an instance of the requested relation
  * @param idx part number
  * @param noRelation if true, then no relationship is Added.
  * @return the Created child POIXMLDocumentPart
  */
 protected POIXMLDocumentPart CreateRelationship(POIXMLRelation descriptor, POIXMLFactory factory, int idx, bool noRelation)
 {
     try
     {
         PackagePartName     ppName = PackagingUriHelper.CreatePartName(descriptor.GetFileName(idx));
         PackageRelationship rel    = null;
         PackagePart         part   = packagePart.Package.CreatePart(ppName, descriptor.ContentType);
         if (!noRelation)
         {
             /* only add to relations, if according relationship is being Created. */
             rel = packagePart.AddRelationship(ppName, TargetMode.Internal, descriptor.Relation);
         }
         POIXMLDocumentPart doc = factory.CreateDocumentPart(descriptor);
         doc.packageRel  = rel;
         doc.packagePart = part;
         doc.parent      = this;
         if (!noRelation)
         {
             /* only add to relations, if according relationship is being Created. */
             AddRelation(rel.Id, doc);
         }
         return(doc);
     }
     catch (PartAlreadyExistsException pae)
     {
         // Return the specific exception so the user knows
         //  that the name is already taken
         throw pae;
     }
     catch (Exception e)
     {
         // Give a general wrapped exception for the problem
         throw new POIXMLException(e);
     }
 }
コード例 #2
0
ファイル: POIXMLDocumentPart.cs プロジェクト: zanhaipeng/npoi
 /**
  * Create a new child POIXMLDocumentPart
  *
  * @param descriptor the part descriptor
  * @param factory the factory that will create an instance of the requested relation
  * @param idx part number
  * @param noRelation if true, then no relationship is Added.
  * @return the Created child POIXMLDocumentPart
  */
 protected POIXMLDocumentPart CreateRelationship(POIXMLRelation descriptor, POIXMLFactory factory, int idx, bool noRelation)
 {
     try {
         PackagePartName     ppName = PackagingUriHelper.CreatePartName(descriptor.GetFileName(idx));
         PackageRelationship rel    = null;
         PackagePart         part   = packagePart.Package.CreatePart(ppName, descriptor.ContentType);
         if (!noRelation)
         {
             /* only add to relations, if according relationship is being Created. */
             rel = packagePart.AddRelationship(ppName, TargetMode.Internal, descriptor.Relation);
         }
         POIXMLDocumentPart doc = factory.CreateDocumentPart(descriptor);
         doc.packageRel  = rel;
         doc.packagePart = part;
         doc.parent      = this;
         if (!noRelation)
         {
             /* only add to relations, if according relationship is being Created. */
             AddRelation(rel.Id, doc);
         }
         return(doc);
     } catch (Exception e) {
         throw new POIXMLException(e);
     }
 }
コード例 #3
0
ファイル: POIXMLDocumentPart.cs プロジェクト: 89sos98/npoi
 /**
  * Create a new child POIXMLDocumentPart
  *
  * @param descriptor the part descriptor
  * @param factory the factory that will create an instance of the requested relation
  * @param idx part number
  * @param noRelation if true, then no relationship is Added.
  * @return the Created child POIXMLDocumentPart
  */
 protected POIXMLDocumentPart CreateRelationship(POIXMLRelation descriptor, POIXMLFactory factory, int idx, bool noRelation)
 {
     try
     {
         PackagePartName ppName = PackagingUriHelper.CreatePartName(descriptor.GetFileName(idx));
         PackageRelationship rel = null;
         PackagePart part = packagePart.Package.CreatePart(ppName, descriptor.ContentType);
         if (!noRelation)
         {
             /* only add to relations, if according relationship is being Created. */
             rel = packagePart.AddRelationship(ppName, TargetMode.Internal, descriptor.Relation);
         }
         POIXMLDocumentPart doc = factory.CreateDocumentPart(descriptor);
         doc.packageRel = rel;
         doc.packagePart = part;
         doc.parent = this;
         if (!noRelation)
         {
             /* only add to relations, if according relationship is being Created. */
             AddRelation(rel.Id, doc);
         }
         return doc;
     }
     catch (PartAlreadyExistsException pae)
     {
         // Return the specific exception so the user knows
         //  that the name is already taken
         throw pae;
     }
     catch (Exception e)
     {
         // Give a general wrapped exception for the problem
         throw new POIXMLException(e);
     }
 }
コード例 #4
0
ファイル: POIXMLDocumentPart.cs プロジェクト: hanwangkun/npoi
 /**
  * Create a new child POIXMLDocumentPart
  *
  * @param descriptor the part descriptor
  * @param factory the factory that will create an instance of the requested relation
  * @param idx part number
  * @param noRelation if true, then no relationship is Added.
  * @return the Created child POIXMLDocumentPart
  */
 protected POIXMLDocumentPart CreateRelationship(POIXMLRelation descriptor, POIXMLFactory factory, int idx, bool noRelation){
     try {
         PackagePartName ppName = PackagingUriHelper.CreatePartName(descriptor.GetFileName(idx));
         PackageRelationship rel = null;
         PackagePart part = packagePart.Package.CreatePart(ppName, descriptor.ContentType);
         if(!noRelation) {
             /* only add to relations, if according relationship is being Created. */
             rel = packagePart.AddRelationship(ppName, TargetMode.Internal, descriptor.Relation);
         }
         POIXMLDocumentPart doc = factory.CreateDocumentPart(descriptor);
         doc.packageRel = rel;
         doc.packagePart = part;
         doc.parent = this;
         if(!noRelation) {
             /* only add to relations, if according relationship is being Created. */
             AddRelation(rel.Id,doc);
         }
         return doc;
     } catch (Exception e){
         throw new POIXMLException(e);
     }
 }
コード例 #5
0
 protected POIXMLDocumentPart CreateRelationship(POIXMLRelation descriptor, POIXMLFactory factory, int idx, bool noRelation)
 {
     try
     {
         PackagePartName     partName            = PackagingUriHelper.CreatePartName(descriptor.GetFileName(idx));
         PackageRelationship packageRelationship = (PackageRelationship)null;
         PackagePart         part = this.packagePart.Package.CreatePart(partName, descriptor.ContentType);
         if (!noRelation)
         {
             packageRelationship = this.packagePart.AddRelationship(partName, TargetMode.Internal, descriptor.Relation);
         }
         POIXMLDocumentPart documentPart = factory.CreateDocumentPart(descriptor);
         documentPart.packageRel  = packageRelationship;
         documentPart.packagePart = part;
         documentPart.parent      = this;
         if (!noRelation)
         {
             this.AddRelation(packageRelationship.Id, documentPart);
         }
         return(documentPart);
     }
     catch (PartAlreadyExistsException ex)
     {
         throw ex;
     }
     catch (Exception ex)
     {
         throw new POIXMLException(ex);
     }
 }