Example #1
0
        private static void AddTransformToPictureElement(OpenXmlDrawingSpreadsheet.Picture pic, Picture picture)
        {
            var xfrm = new OpenXmlDrawing.Transform2D();

            xfrm.Offset = new OpenXmlDrawing.Offset();
            xfrm.Offset.X = picture.Position.X;
            xfrm.Offset.Y = picture.Position.Y;

            xfrm.Extents = new OpenXmlDrawing.Extents();
            xfrm.Extents.Cx = picture.Size.Width;
            xfrm.Extents.Cy = picture.Size.Height;

            pic.ShapeProperties.Transform2D = xfrm;
        }
Example #2
0
 private static void AddShapePropertiesToPictureElement(OpenXmlDrawingSpreadsheet.Picture pic, Picture picture)
 {
     pic.ShapeProperties = new OpenXmlDrawingSpreadsheet.ShapeProperties();
     pic.ShapeProperties.BlackWhiteMode = OpenXmlDrawing.BlackWhiteModeValues.Auto;
 }
Example #3
0
        private static void AddNonVisualPicturePropertiesToPictureElement(OpenXmlDrawingSpreadsheet.Picture pic, Picture picture)
        {
            pic.NonVisualPictureProperties = new OpenXmlDrawingSpreadsheet.NonVisualPictureProperties();
            var nvPicPr = pic.NonVisualPictureProperties;
            nvPicPr.NonVisualDrawingProperties = new OpenXmlDrawingSpreadsheet.NonVisualDrawingProperties();
            nvPicPr.NonVisualDrawingProperties.Description = picture.Description;
            nvPicPr.NonVisualDrawingProperties.Name = picture.Name;
            nvPicPr.NonVisualDrawingProperties.Id = (uint)picture.Id;

            nvPicPr.NonVisualPictureDrawingProperties = new OpenXmlDrawingSpreadsheet.NonVisualPictureDrawingProperties();
            var cNvPicPr = nvPicPr.NonVisualPictureDrawingProperties;
            cNvPicPr.PictureLocks = new OpenXmlDrawing.PictureLocks();
            cNvPicPr.PictureLocks.NoChangeAspect = true;
        }
Example #4
0
 private static void AddPresetGeometryToPictureElement(OpenXmlDrawingSpreadsheet.Picture pic, Picture picture)
 {
     OpenXmlDrawing.PresetGeometry prstGeom = new OpenXmlDrawing.PresetGeometry();
     prstGeom.Preset = OpenXmlDrawing.ShapeTypeValues.Rectangle;
     pic.ShapeProperties.Append(prstGeom);
 }
Example #5
0
        private static void AddBlipFillToPictureElement(OpenXmlDrawingSpreadsheet.Picture pic, Picture picture)
        {
            pic.BlipFill = new OpenXmlDrawingSpreadsheet.BlipFill();
            OpenXmlDrawingSpreadsheet.BlipFill blipFill = pic.BlipFill;
            blipFill.Blip = new OpenXmlDrawing.Blip();
            blipFill.Blip.CompressionState = OpenXmlDrawing.BlipCompressionValues.Print;

            OpenXmlPackaging.DrawingsPart drawingsPart = Drawing.GetDrawingsPartFromDrawing(picture.Drawing);

            if (picture.BlipRelationshipId == "")
            {
                // we know the url of the image, so create a relationship to it that way.
                OpenXmlPackaging.OpenXmlPart imagePart = OpenXmlUtilities.GetPartByUri(picture.Drawing.Worksheet.Workbook.Document.WorkbookPart, picture.FilePath);
                if (imagePart != null)
                {
                    // The workbook will probably be broken if an invalid file path is found. Not really a concern for now.
                    picture.BlipRelationshipId = drawingsPart.CreateRelationshipToPart(imagePart);
                }
            }

            blipFill.Blip.SetAttribute(new OpenXml.OpenXmlAttribute("r", "embed", "http://schemas.openxmlformats.org/officeDocument/2006/relationships", picture.BlipRelationshipId));

            var stretch = new OpenXmlDrawing.Stretch();
            stretch.FillRectangle = new OpenXmlDrawing.FillRectangle();
            blipFill.Append(stretch);
        }