Exemple #1
0
        /// <summary>
        /// Inserts a picture at the end of the text in the header or footer
        /// </summary>
        /// <param name="PictureFile">The image object containing the Picture</param>
        /// <param name="Alignment">Alignment. The image object will be inserted at the end of the Text.</param>
        public ExcelVmlDrawingPicture InsertPicture(FileInfo PictureFile, PictureAlignment Alignment)
        {
            string id = ValidateImage(Alignment);

            Image Picture;

            try
            {
                if (!PictureFile.Exists)
                {
                    throw (new FileNotFoundException(string.Format("{0} is missing", PictureFile.FullName)));
                }
                Picture = Image.FromFile(PictureFile.FullName);
            }
            catch (Exception ex)
            {
                throw (new InvalidDataException("File is not a supported image-file or is corrupt", ex));
            }

            string contentType = PictureStore.GetContentType(PictureFile.Extension);
            var    uriPic      = XmlHelper.GetNewUri(_ws._package.ZipPackage, "/xl/media/" + PictureFile.Name.Substring(0, PictureFile.Name.Length - PictureFile.Extension.Length) + "{0}" + PictureFile.Extension);

#if (Core)
            var imgBytes = ImageCompat.GetImageAsByteArray(Picture);
#else
            var    ic       = new ImageConverter();
            byte[] imgBytes = (byte[])ic.ConvertTo(Picture, typeof(byte[]));
#endif

            var ii = _ws.Workbook._package.PictureStore.AddImage(imgBytes, uriPic, contentType);

            return(AddImage(Picture, id, ii));
        }
Exemple #2
0
        private string ValidateImage(PictureAlignment Alignment)
        {
            string id = string.Concat(Alignment.ToString()[0], _hf);

            foreach (ExcelVmlDrawingPicture image in _ws.HeaderFooter.Pictures)
            {
                if (image.Id == id)
                {
                    throw (new InvalidOperationException("A picture already exists in this section"));
                }
            }
            //Add the image placeholder to the end of the text
            switch (Alignment)
            {
            case PictureAlignment.Left:
                LeftAlignedText += ExcelHeaderFooter.Image;
                break;

            case PictureAlignment.Centered:
                CenteredText += ExcelHeaderFooter.Image;
                break;

            default:
                RightAlignedText += ExcelHeaderFooter.Image;
                break;
            }
            return(id);
        }
 public FixedPicture(
     string resourceId, string filename,
     int left, int bottom, int right, int top,
     PictureAlignment alignment, PictureScaleMode scalemode, int quality)
 {
     _filename   = filename;
     _resourceId = resourceId;
     _rect       = new Rectangle(left, bottom, right, top);
     _alignment  = alignment;
     _scaleMode  = scalemode;
     _quality    = quality;
 }
        /// <summary>
        /// Inserts a picture at the end of the text in the header or footer
        /// </summary>
        /// <param name="Picture">The image object containing the Picture</param>
        /// <param name="Alignment">Alignment. The image object will be inserted at the end of the Text.</param>
        public ExcelVmlDrawingPicture InsertPicture(Image Picture, PictureAlignment Alignment)
        {
            string id = ValidateImage(Alignment);

            //Add the image
            ImageConverter ic = new ImageConverter();

            byte[] img = (byte[])ic.ConvertTo(Picture, typeof(byte[]));
            var    ii  = _ws.Workbook._package.AddImage(img);

            return(AddImage(Picture, id, ii));
        }
Exemple #5
0
        /// <summary>
        /// Inserts a picture at the end of the text in the header or footer
        /// </summary>
        /// <param name="Picture">The image object containing the Picture</param>
        /// <param name="Alignment">Alignment. The image object will be inserted at the end of the Text.</param>
        public ExcelVmlDrawingPicture InsertPicture(Image Picture, PictureAlignment Alignment)
        {
            string id = ValidateImage(Alignment);

            //Add the image

            var img = ImageCompat.GetImageAsByteArray(Picture);

            var ii = _ws.Workbook._package.AddImage(img);

            return(AddImage(Picture, id, ii));
        }
Exemple #6
0
        /// <summary>
        /// Copy constructor used during layout expansion and page break handling.
        /// </summary>
        public PictureLayout(PictureLayout src)
            : base(src)
        {
            _filename    = src._filename;
            _resourceId  = src._resourceId;
            _image       = src._image;       // OK to copy by reference because the source layout will be dropped
            _width       = src._width;
            _height      = src._height;
            _imageBounds = src._imageBounds;
            _alignment   = src._alignment;
            _scaleMode   = src._scaleMode;
            _quality     = src._quality;
//			_style = src._style;
        }
Exemple #7
0
        /// <summary>
        /// Inserts a picture at the end of the text in the header or footer
        /// </summary>
        /// <param name="Picture">The image object containing the Picture</param>
        /// <param name="Alignment">Alignment. The image object will be inserted at the end of the Text.</param>
        public ExcelVmlDrawingPicture InsertPicture(Image Picture, PictureAlignment Alignment)
        {
            string id = ValidateImage(Alignment);

            //Add the image
#if (NETSTANDARD)
            var img = ImageCompat.GetImageAsByteArray(Picture);
#else
            ImageConverter ic  = new ImageConverter();
            byte[]         img = (byte[])ic.ConvertTo(Picture, typeof(byte[]));
#endif

            var ii = _ws.Workbook._package.AddImage(img, ExcelPicture.GetImageCodecInfo(Picture));

            return(AddImage(Picture, id, ii));
        }
Exemple #8
0
        public override void Load(XElement root)
        {
            base.Load(root);
            XNamespace ns = root.GetDefaultNamespace();

//			_style = _generator.ReportDesign.LoadStyle<PhotoStyle>(root.Element(ns + "Style"));
//			if (_style == null) _style = _generator.ReportDesign.DefaultPhotoStyle;

            //	The picture can be specified either with an explicit filename or with
            //	a reference to a resource
            _filename   = _generator.ReportDesign.LoadString(root.Attribute("filename"));
            _resourceId = _generator.ReportDesign.LoadString(root.Attribute("ref"));

            _width     = _generator.ReportDesign.LoadInt(root.Element(ns + "Width")) ?? 0;
            _height    = _generator.ReportDesign.LoadInt(root.Element(ns + "Height")) ?? 0;
            _alignment = _generator.ReportDesign.LoadEnum <PictureAlignment>(root.Element(ns + "Alignment"));
            _scaleMode = _generator.ReportDesign.LoadEnum <PictureScaleMode>(root.Element(ns + "ScaleMode"));
            _quality   = _generator.ReportDesign.LoadInt(root.Element(ns + "Quality")) ?? 0;
        }
Exemple #9
0
 private string ValidateImage(PictureAlignment Alignment)
 {
     string id = string.Concat(Alignment.ToString()[0], _hf);
     foreach (ExcelVmlDrawingPicture image in _ws.HeaderFooter.Pictures)
     {
         if (image.Id == id)
         {
             throw (new InvalidOperationException("A picture already exists in this section"));
         }
     }
     //Add the image placeholder to the end of the text
     switch (Alignment)
     {
         case PictureAlignment.Left:
             LeftAlignedText += ExcelHeaderFooter.Image;
             break;
         case PictureAlignment.Centered:
             CenteredText += ExcelHeaderFooter.Image;
             break;
         default:
             RightAlignedText += ExcelHeaderFooter.Image;
             break;
     }
     return id;
 }
Exemple #10
0
        /// <summary>
        /// Inserts a picture at the end of the text in the header or footer
        /// </summary>
        /// <param name="PictureFile">The image object containing the Picture</param>
        /// <param name="Alignment">Alignment. The image object will be inserted at the end of the Text.</param>
        public ExcelVmlDrawingPicture InsertPicture(FileInfo PictureFile, PictureAlignment Alignment)
        {
            string id = ValidateImage(Alignment);

            Image Picture;
            try
            {
                if (!PictureFile.Exists)
                {
                    throw (new FileNotFoundException(string.Format("{0} is missing", PictureFile.FullName)));
                }
                Picture = Image.FromFile(PictureFile.FullName);
            }
            catch (Exception ex)
            {
                throw (new InvalidDataException("File is not a supported image-file or is corrupt", ex));
            }

            ImageConverter ic = new ImageConverter();
            string contentType = ExcelPicture.GetContentType(PictureFile.Extension);
            var uriPic = XmlHelper.GetNewUri(_ws._package.Package, "/xl/media/" + PictureFile.Name.Substring(0, PictureFile.Name.Length-PictureFile.Extension.Length) + "{0}" + PictureFile.Extension);
            byte[] imgBytes = (byte[])ic.ConvertTo(Picture, typeof(byte[]));
            var ii = _ws.Workbook._package.AddImage(imgBytes, uriPic, contentType);

            return AddImage(Picture, id, ii);
        }
Exemple #11
0
        /// <summary>
        /// Inserts a picture at the end of the text in the header or footer
        /// </summary>
        /// <param name="Picture">The image object containing the Picture</param>
        /// <param name="Alignment">Alignment. The image object will be inserted at the end of the Text.</param>
        public ExcelVmlDrawingPicture InsertPicture(Image Picture, PictureAlignment Alignment)
        {
            string id = ValidateImage(Alignment);
            
            //Add the image
            ImageConverter ic = new ImageConverter();
            byte[] img = (byte[])ic.ConvertTo(Picture, typeof(byte[]));
            var ii = _ws.Workbook._package.AddImage(img);

            return AddImage(Picture, id, ii);
        }
Exemple #12
0
        public static void AddFooter(ExcelWorksheet sheet, string imgFooterPath, int addHeightFooter, PictureAlignment footerAlign, eOrientation orientation = eOrientation.Landscape, ePaperSize pagerSize = ePaperSize.A4)
        {
            var footerPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, imgFooterPath);

            // TODO: Check this later.
            //var evenFooter = sheet.HeaderFooter.EvenFooter.InsertPicture(new FileInfo(footerPath), footerAlign);
            //evenFooter.Width = evenFooter.Width + (addHeightFooter * evenFooter.Width / evenFooter.Height);
            //evenFooter.Height = evenFooter.Height + addHeightFooter;

            //var oddFooter = sheet.HeaderFooter.OddFooter.InsertPicture(new FileInfo(footerPath), footerAlign);
            //oddFooter.Width = oddFooter.Width + (addHeightFooter * oddFooter.Width / oddFooter.Height);
            //oddFooter.Height = oddFooter.Height + addHeightFooter;

            sheet.View.PageLayoutView         = true;
            sheet.PrinterSettings.TopMargin   = 2.4M / 2.54M;
            sheet.PrinterSettings.Orientation = orientation;
            sheet.PrinterSettings.PaperSize   = pagerSize;
        }
        public override void Load(XElement root)
        {
            base.Load(root);

            XNamespace ns     = root.GetDefaultNamespace();
            XElement   header = root.Element(ns + "Header")?.Element(ns + "GroupLayout");

            if (header != null)
            {
                _headerLayout = new GroupLayout(_generator, _trackingInfo.LineNumber, _trackingInfo.LinePosition);
                _headerLayout.Load(header);
                _headerLayout.SetAsHeaderOf(this);
            }
            XElement footer = root.Element(ns + "Footer")?.Element(ns + "GroupLayout");

            if (footer != null)
            {
                _footerLayout = new GroupLayout(_generator, _trackingInfo.LineNumber, _trackingInfo.LinePosition);
                _footerLayout.Load(footer);
                _footerLayout.SetAsFooterOf(this);
            }

            PageMetrics metrics = _generator.ReportDesign.LoadPageMetrics(root.Element(ns + "PageMetrics"));

            if (metrics == null)
            {
                throw new System.InvalidOperationException($"ChapterLayout page metrics is null at {_trackingInfo}.");
            }
            _mediaBox = new Rectangle
            {
                Left   = metrics.MediaBoxLeft,
                Bottom = metrics.MediaBoxBottom,
                Right  = metrics.MediaBoxRight,
                Top    = metrics.MediaBoxTop
            };
            _bodyBox = new Rectangle
            {
                Left   = metrics.BodyBoxLeft,
                Bottom = metrics.BodyBoxBottom,
                Right  = metrics.BodyBoxRight,
                Top    = metrics.BodyBoxTop
            };
            _headerBox = new Rectangle
            {
                Left   = metrics.HeaderBoxLeft,
                Bottom = metrics.HeaderBoxBottom,
                Right  = metrics.HeaderBoxRight,
                Top    = metrics.HeaderBoxTop
            };
            _footerBox = new Rectangle
            {
                Left   = metrics.FooterBoxLeft,
                Bottom = metrics.FooterBoxBottom,
                Right  = metrics.FooterBoxRight,
                Top    = metrics.FooterBoxTop
            };

            _bounds = _bodyBox;

            //	Note that the header and footer tables are structured as part of the
            //	page layout, not as content. That is, the page layout has explicit
            //	pointers to the header and footer, and the header and footer layouts
            //	nominate no container. This allows a header or footer
            //	layout to be shared by any number of page layouts.
//			if(src.HeaderLayout != null)
//				_headerLayout = new TableLayout(src.HeaderLayout,generator);
//			if(src.FooterLayout != null)
//				_footerLayout = new TableLayout(src.FooterLayout,generator);

            //	A page layout's page break rules is always null because a page layout always
            //	starts on a new page

            //	Load any background images
            _background = new List <FixedPicture>();
            XElement background = root.Element(ns + "Background");

            if (background != null)
            {
                foreach (XElement pictureElement in background.Elements(ns + "Picture"))
                {
                    //	The picture can be specified either with an explicit filename or with
                    //	a reference to a resource
                    string filename   = _generator.ReportDesign.LoadString(pictureElement.Attribute("filename"));
                    string resourceId = _generator.ReportDesign.LoadString(pictureElement.Attribute("ref"));

                    int left   = _generator.ReportDesign.LoadInt(pictureElement.Element(ns + "Left")) ?? 0;
                    int bottom = _generator.ReportDesign.LoadInt(pictureElement.Element(ns + "Bottom")) ?? 0;
                    int right  = _generator.ReportDesign.LoadInt(pictureElement.Element(ns + "Right")) ?? 0;
                    int top    = _generator.ReportDesign.LoadInt(pictureElement.Element(ns + "Top")) ?? 0;

                    PictureAlignment alignment = _generator.ReportDesign.LoadEnum <PictureAlignment>(pictureElement.Element(ns + "Alignment"));
                    PictureScaleMode scalemode = _generator.ReportDesign.LoadEnum <PictureScaleMode>(pictureElement.Element(ns + "ScaleMode"));
                    int quality = _generator.ReportDesign.LoadInt(pictureElement.Element(ns + "Quality")) ?? 0;

                    FixedPicture picture = new FixedPicture(resourceId, filename, left, bottom, right, top, alignment, scalemode, quality);
                    _background.Add(picture);
                }
            }

            //	Load any overlay images
            _overlays = new List <FixedPicture>();
            XElement overlay = root.Element(ns + "Overlay");

            if (overlay != null)
            {
                foreach (XElement pictureElement in overlay.Elements(ns + "Picture"))
                {
                    //	The picture can be specified either with an explicit filename or with
                    //	a reference to a resource
                    string filename   = _generator.ReportDesign.LoadString(pictureElement.Attribute("filename"));
                    string resourceId = _generator.ReportDesign.LoadString(pictureElement.Attribute("ref"));

                    int left   = _generator.ReportDesign.LoadInt(pictureElement.Element(ns + "Left")) ?? 0;
                    int bottom = _generator.ReportDesign.LoadInt(pictureElement.Element(ns + "Bottom")) ?? 0;
                    int right  = _generator.ReportDesign.LoadInt(pictureElement.Element(ns + "Right")) ?? 0;
                    int top    = _generator.ReportDesign.LoadInt(pictureElement.Element(ns + "Top")) ?? 0;

                    PictureAlignment alignment = _generator.ReportDesign.LoadEnum <PictureAlignment>(pictureElement.Element(ns + "Alignment"));
                    PictureScaleMode scalemode = _generator.ReportDesign.LoadEnum <PictureScaleMode>(pictureElement.Element(ns + "ScaleMode"));
                    int quality = _generator.ReportDesign.LoadInt(pictureElement.Element(ns + "Quality")) ?? 0;

                    FixedPicture picture = new FixedPicture(resourceId, filename, left, bottom, right, top, alignment, scalemode, quality);
                    _overlays.Add(picture);
                }
            }

            _drawRules   = _generator.ReportDesign.LoadBoolean(root.Attribute("drawRules")) ?? false;
            _renderEmpty = _generator.ReportDesign.LoadBoolean(root.Attribute("renderEmpty")) ?? false;
        }