コード例 #1
0
        internal PackageRelationship AddPictureReference(int pictureIndex)
        {
            XSSFPictureData     allPicture = (XSSFPictureData)((XSSFWorkbook)this.GetParent().GetParent()).GetAllPictures()[pictureIndex];
            PackageRelationship rel        = this.GetPackagePart().AddRelationship(allPicture.GetPackagePart().PartName, TargetMode.Internal, XSSFRelation.IMAGES.Relation);

            this.AddRelation(rel.Id, (POIXMLDocumentPart) new XSSFPictureData(allPicture.GetPackagePart(), rel));
            return(rel);
        }
コード例 #2
0
ファイル: XSSFDrawing.cs プロジェクト: flowbywind/npoi
        //public XSSFChart CreateChart(IClientAnchor anchor)
        //{
        //    return CreateChart((XSSFClientAnchor)anchor);
        //}

        /**
         * Add the indexed picture to this Drawing relations
         *
         * @param pictureIndex the index of the picture in the workbook collection of pictures,
         *   {@link NPOI.xssf.usermodel.XSSFWorkbook#getAllPictures()} .
         */
        internal PackageRelationship AddPictureReference(int pictureIndex)
        {
            XSSFWorkbook        wb     = (XSSFWorkbook)GetParent().GetParent();
            XSSFPictureData     data   = (XSSFPictureData)wb.GetAllPictures()[pictureIndex];
            PackagePartName     ppName = data.GetPackagePart().PartName;
            PackageRelationship rel    = GetPackagePart().AddRelationship(ppName, TargetMode.Internal, XSSFRelation.IMAGES.Relation);

            AddRelation(rel.Id, new XSSFPictureData(data.GetPackagePart(), rel));
            return(rel);
        }
コード例 #3
0
ファイル: XSSFDrawing.cs プロジェクト: E-Ef/npoi
        //public XSSFChart CreateChart(IClientAnchor anchor)
        //{
        //    return CreateChart((XSSFClientAnchor)anchor);
        //}

        /**
         * Add the indexed picture to this Drawing relations
         *
         * @param pictureIndex the index of the picture in the workbook collection of pictures,
         *   {@link NPOI.xssf.usermodel.XSSFWorkbook#getAllPictures()} .
         */
        internal PackageRelationship AddPictureReference(int pictureIndex)
        {
            XSSFWorkbook    wb   = (XSSFWorkbook)GetParent().GetParent();
            XSSFPictureData data = (XSSFPictureData)wb.GetAllPictures()[pictureIndex];
            XSSFPictureData pic  = new XSSFPictureData(data.GetPackagePart());
            RelationPart    rp   = AddRelation(null, XSSFRelation.IMAGES, pic);

            return(rp.Relationship);
        }
コード例 #4
0
        public int AddPicture(Stream picStream, int format)
        {
            int             idx          = this.GetAllPictures().Count + 1;
            XSSFPictureData relationship = (XSSFPictureData)this.CreateRelationship(XSSFPictureData.RELATIONS[format], (POIXMLFactory)XSSFFactory.GetInstance(), idx, true);
            Stream          outputStream = relationship.GetPackagePart().GetOutputStream();

            IOUtils.Copy(picStream, outputStream);
            outputStream.Close();
            this.pictures.Add(relationship);
            return(idx - 1);
        }
コード例 #5
0
        public int AddPicture(byte[] pictureData, PictureType format)
        {
            int             idx          = this.GetAllPictures().Count + 1;
            XSSFPictureData relationship = (XSSFPictureData)this.CreateRelationship(XSSFPictureData.RELATIONS[(int)format], (POIXMLFactory)XSSFFactory.GetInstance(), idx, true);

            try
            {
                Stream outputStream = relationship.GetPackagePart().GetOutputStream();
                outputStream.Write(pictureData, 0, pictureData.Length);
                outputStream.Close();
            }
            catch (IOException ex)
            {
                throw new POIXMLException((Exception)ex);
            }
            this.pictures.Add(relationship);
            return(idx - 1);
        }
コード例 #6
0
ファイル: XSSFPicture.cs プロジェクト: thachgiasoft/shuijin
        public IClientAnchor GetPreferredSize(double scale)
        {
            XSSFClientAnchor anchor         = (XSSFClientAnchor)this.GetAnchor();
            XSSFPictureData  pictureData    = (XSSFPictureData)this.PictureData;
            Size             imageDimension = XSSFPicture.GetImageDimension(pictureData.GetPackagePart(), pictureData.GetPictureType());
            double           num1           = (double)imageDimension.Width * scale;
            double           num2           = (double)imageDimension.Height * scale;
            float            num3           = 0.0f;
            int col1 = anchor.Col1;
            int num4 = 0;

            while (true)
            {
                num3 += this.GetColumnWidthInPixels(col1);
                if ((double)num3 <= num1)
                {
                    ++col1;
                }
                else
                {
                    break;
                }
            }
            if ((double)num3 > num1)
            {
                double columnWidthInPixels = (double)this.GetColumnWidthInPixels(col1);
                double num5 = (double)num3 - num1;
                num4 = (int)((double)XSSFShape.EMU_PER_PIXEL * (columnWidthInPixels - num5));
            }
            anchor.Col2 = col1;
            anchor.Dx2  = num4;
            double num6 = 0.0;
            int    row1 = anchor.Row1;
            int    num7 = 0;

            while (true)
            {
                num6 += (double)this.GetRowHeightInPixels(row1);
                if (num6 <= num2)
                {
                    ++row1;
                }
                else
                {
                    break;
                }
            }
            if (num6 > num2)
            {
                double rowHeightInPixels = (double)this.GetRowHeightInPixels(row1);
                double num5 = num6 - num2;
                num7 = (int)((double)XSSFShape.EMU_PER_PIXEL * (rowHeightInPixels - num5));
            }
            anchor.Row2 = row1;
            anchor.Dy2  = num7;
            CT_PositiveSize2D ext = this.ctPicture.spPr.xfrm.ext;

            ext.cx = (long)(num1 * (double)XSSFShape.EMU_PER_PIXEL);
            ext.cy = (long)(num2 * (double)XSSFShape.EMU_PER_PIXEL);
            return((IClientAnchor)anchor);
        }
コード例 #7
0
        /**
         * Return the dimension of the embedded image in pixel
         *
         * @return image dimension in pixels
         */
        public Size GetImageDimension()
        {
            XSSFPictureData picData = PictureData as XSSFPictureData;

            return(GetImageDimension(picData.GetPackagePart(), picData.PictureType));
        }
コード例 #8
0
ファイル: XSSFPicture.cs プロジェクト: ornoand/npoi
        /**
         * Calculate the preferred size for this picture.
         *
         * @param scale the amount by which image dimensions are multiplied relative to the original size.
         * @return XSSFClientAnchor with the preferred size for this image
         */
        public IClientAnchor GetPreferredSize(double scale)
        {
            XSSFClientAnchor anchor = (XSSFClientAnchor)GetAnchor();

            XSSFPictureData data         = (XSSFPictureData)this.PictureData;
            Size            size         = GetImageDimension(data.GetPackagePart(), data.GetPictureType());
            double          scaledWidth  = size.Width * scale;
            double          scaledHeight = size.Height * scale;

            float w    = 0;
            int   col2 = anchor.Col1;
            int   dx2  = 0;

            for (; ;)
            {
                w += GetColumnWidthInPixels(col2);
                if (w > scaledWidth)
                {
                    break;
                }
                col2++;
            }

            if (w > scaledWidth)
            {
                double cw    = GetColumnWidthInPixels(col2);
                double delta = w - scaledWidth;
                dx2 = (int)(EMU_PER_PIXEL * (cw - delta));
            }
            anchor.Col2 = (col2);
            anchor.Dx2  = (dx2);

            double h    = 0;
            int    row2 = anchor.Row1;
            int    dy2  = 0;

            for (; ;)
            {
                h += GetRowHeightInPixels(row2);
                if (h > scaledHeight)
                {
                    break;
                }
                row2++;
            }

            if (h > scaledHeight)
            {
                double ch    = GetRowHeightInPixels(row2);
                double delta = h - scaledHeight;
                dy2 = (int)(EMU_PER_PIXEL * (ch - delta));
            }
            anchor.Row2 = (row2);
            anchor.Dy2  = (dy2);

            CT_PositiveSize2D size2d = ctPicture.spPr.xfrm.ext;

            size2d.cx = ((long)(scaledWidth * EMU_PER_PIXEL));
            size2d.cy = ((long)(scaledHeight * EMU_PER_PIXEL));

            return(anchor);
        }