예제 #1
0
 public override POIXMLDocumentPart CreateDocumentPart(POIXMLRelation descriptor)
 {
     try
     {
         Type cls = descriptor.RelationClass;
         ConstructorInfo constructor = cls.GetConstructor(new Type[] { });
         return (POIXMLDocumentPart)constructor.Invoke(new object[] { });
     }
     catch (Exception e)
     {
         throw new POIXMLException(e);
     }
 }
예제 #2
0
 public override POIXMLDocumentPart CreateDocumentPart(POIXMLRelation descriptor)
 {
     try
     {
         Type cls = descriptor.RelationClass;
         ConstructorInfo constructor = cls.GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public, 
             null, Type.EmptyTypes, null);
         return constructor.Invoke(new object[] { }) as POIXMLDocumentPart;
     }
     catch (Exception e)
     {
         throw new POIXMLException(e);
     }
 }
예제 #3
0
        /**
         * Adds a picture to the document.
         *
         * @param pictureData       The picture data
         * @param format            The format of the picture.
         *
         * @return the index to this picture (0 based), the Added picture can be obtained from {@link #getAllPictures()} .
         * @throws InvalidFormatException
         */
        public String AddPictureData(byte[] pictureData, int format)
        {
            XWPFPictureData xwpfPicData = document.FindPackagePictureData(pictureData, format);
            POIXMLRelation  relDesc     = XWPFPictureData.RELATIONS[format];

            if (xwpfPicData == null)
            {
                /* Part doesn't exist, create a new one */
                int idx = document.GetNextPicNameNumber(format);
                xwpfPicData = (XWPFPictureData)CreateRelationship(relDesc, XWPFFactory.GetInstance(), idx);
                /* write bytes to new part */
                PackagePart picDataPart = xwpfPicData.GetPackagePart();
                Stream      out1        = null;
                try
                {
                    out1 = picDataPart.GetOutputStream();
                    out1.Write(pictureData, 0, pictureData.Length);
                }
                catch (IOException e)
                {
                    throw new POIXMLException(e);
                }
                finally
                {
                    try
                    {
                        out1.Close();
                    }
                    catch (IOException)
                    {
                        // ignore
                    }
                }

                document.RegisterPackagePictureData(xwpfPicData);
                pictures.Add(xwpfPicData);
                return(GetRelationId(xwpfPicData));
            }
            else if (!GetRelations().Contains(xwpfPicData))
            {
                /*
                 * Part already existed, but was not related so far. Create
                 * relationship to the already existing part and update
                 * POIXMLDocumentPart data.
                 */
                PackagePart picDataPart = xwpfPicData.GetPackagePart();
                // TODO add support for TargetMode.EXTERNAL relations.
                TargetMode          targetMode = TargetMode.Internal;
                PackagePartName     partName   = picDataPart.PartName;
                String              relation   = relDesc.Relation;
                PackageRelationship relShip    = GetPackagePart().AddRelationship(partName, targetMode, relation);
                String              id         = relShip.Id;
                AddRelation(id, xwpfPicData);
                pictures.Add(xwpfPicData);
                return(id);
            }
            else
            {
                /* Part already existed, Get relation id and return it */
                return(GetRelationId(xwpfPicData));
            }
        }
예제 #4
0
 public override POIXMLDocumentPart CreateDocumentPart(POIXMLRelation descriptor)
 {
     throw new NotSupportedException();
 }