Esempio n. 1
0
 /***********************************
  * CONSTRUCTORS
  ************************************/
 internal Picture(Drawing drawing, string filePath, string description, string name, int id, Size size, Point position, string blipRelationshipId)
 {
     Drawing = drawing;
     FilePath = filePath;
     Description = description;
     Name = name;
     Id = id;
     BlipRelationshipId = blipRelationshipId;
     Size = size;
     Position = position;
 }
Esempio n. 2
0
 /***********************************
  * DAL METHODS
  ************************************/
 // Read
 internal static OpenXmlPackaging.DrawingsPart GetDrawingsPartFromDrawing(Drawing drawing)
 {
     OpenXmlPackaging.WorksheetPart worksheetPart = Worksheet.GetWorksheetPartByWorksheet(drawing.Worksheet);
     OpenXmlPackaging.DrawingsPart drawingsPart = (OpenXmlPackaging.DrawingsPart)worksheetPart.GetPartById(drawing.RelationshipId);
     return drawingsPart;
 }
Esempio n. 3
0
 /***********************************
  * PUBLIC METHODS
  ************************************/
 public Drawing Clone(Worksheet worksheet)
 {
     Drawing newDrawing = new Drawing(worksheet, "");
     newDrawing.Shapes = Shapes.Clone(newDrawing);
     return newDrawing;
 }
Esempio n. 4
0
        private static void SaveDrawingData(Drawing drawing)
        {
            if (drawing._shapes != null)
            {
                OpenXmlPackaging.DrawingsPart drawingsPart = Drawing.GetDrawingsPartFromDrawing(drawing);

                OpenXmlDrawingSpreadsheet.WorksheetDrawing worksheetDrawing = drawingsPart.WorksheetDrawing;

                List<OpenXmlDrawingSpreadsheet.TwoCellAnchor> twoCellAnchors = new List<OpenXmlDrawingSpreadsheet.TwoCellAnchor>();
                List<OpenXmlDrawingSpreadsheet.AbsoluteAnchor> absoluteAnchors = new List<OpenXmlDrawingSpreadsheet.AbsoluteAnchor>();

                worksheetDrawing.RemoveAllChildren();

                foreach (Shape shape in drawing.Shapes)
                {
                    Shape.AddShapeToWorksheetDrawingElement(worksheetDrawing, shape);
                }

            }
        }
Esempio n. 5
0
        private static string CreateDrawingPartByDrawing(Drawing drawing)
        {
            OpenXmlPackaging.WorkbookPart workbookPart = drawing.Worksheet.Workbook.Document.WorkbookPart;
            OpenXmlPackaging.WorksheetPart worksheetPart = Worksheet.GetWorksheetPartByWorksheet(drawing.Worksheet);
            OpenXmlPackaging.DrawingsPart drawingsPart = OpenXmlUtilities.CreatePart<OpenXmlPackaging.WorksheetPart, OpenXmlPackaging.DrawingsPart>(worksheetPart);

            using (var writer = new CustomOpenXmlWriter<OpenXmlPackaging.DrawingsPart>(drawingsPart))
            {
                writer.WriteOpenXmlElement(new OpenXmlDrawingSpreadsheet.WorksheetDrawing(), true);
            }

            string id = worksheetPart.GetIdOfPart(drawingsPart);
            worksheetPart.CreateRelationshipToPart(drawingsPart, id);
            return id;
        }
Esempio n. 6
0
 // Write
 internal static void WriteDrawingToWorksheetWriter(CustomOpenXmlWriter<OpenXmlPackaging.WorksheetPart> writer, Drawing drawing)
 {
     writer.WriteOpenXmlElement(new OpenXmlSpreadsheet.Drawing());
     writer.WriteAttribute("id", drawing.RelationshipId, "r");
     writer.WriteEndElement();   // Drawing
 }
Esempio n. 7
0
 /***********************************
  * PUBLIC METHODS
  ************************************/
 public Picture Clone(Drawing drawing)
 {
     int id = Picture.GetNextPictureId(drawing.Worksheet.Workbook);
     return new Picture(drawing, FilePath, Description, Name, id, Size, Position, "");
 }
Esempio n. 8
0
 private static OpenXmlPackaging.OpenXmlPart GetMediaPartFromDrawing(Drawing drawing, string relationshipId)
 {
     OpenXmlPackaging.DrawingsPart drawingsPart = Drawing.GetDrawingsPartFromDrawing(drawing);
     OpenXmlPackaging.OpenXmlPart mediaPart = drawingsPart.GetPartById(relationshipId);
     return mediaPart;
 }
Esempio n. 9
0
        private static string GetFilePathFromBlip(CustomOpenXmlReader reader, Drawing drawing, string relationshipId)
        {
            OpenXmlPackaging.OpenXmlPart mediaPart = Picture.GetMediaPartFromDrawing(drawing, relationshipId);

            if (mediaPart != null)
                return mediaPart.Uri.ToString();

            return "";
        }
Esempio n. 10
0
        /***********************************
         * DAL METHODS
         ************************************/
        // Read
        internal static Picture ReadPictureFromReader(CustomOpenXmlReader reader, Drawing drawing)
        {
            string filePath = "";
            string description = "";
            string name = "";
            int id = 0;
            string blipRelationshipId = "";
            Size size = new Size();
            Point position = new Point();

            while (reader.ReadToEndElement<OpenXmlDrawingSpreadsheet.Picture>())
            {
                if (reader.IsStartElementOfType<OpenXmlDrawingSpreadsheet.NonVisualPictureProperties>())
                {
                    while (reader.ReadToEndElement<OpenXmlDrawingSpreadsheet.NonVisualPictureProperties>())
                    {
                        if (reader.IsStartElementOfType<OpenXmlDrawingSpreadsheet.NonVisualDrawingProperties>())
                        {
                            description = OpenXmlUtilities.GetAttributeValueFromReader(reader, "descr");
                            name = OpenXmlUtilities.GetAttributeValueFromReader(reader, "name");
                            id = reader.Attributes["id"].GetIntValue();
                        }
                    }
                }
                else if (reader.IsStartElementOfType<OpenXmlDrawingSpreadsheet.BlipFill>())
                {
                    while (reader.ReadToEndElement<OpenXmlDrawingSpreadsheet.BlipFill>())
                    {
                        if (reader.IsStartElementOfType<OpenXmlDrawing.Blip>())
                        {
                            blipRelationshipId = reader.Attributes["embed"].Value;
                            filePath = GetFilePathFromBlip(reader, drawing, blipRelationshipId);
                        }
                    }
                }
                else if (reader.IsStartElementOfType<OpenXmlDrawingSpreadsheet.ShapeProperties>())
                {
                    while (reader.ReadToEndElement<OpenXmlDrawingSpreadsheet.ShapeProperties>())
                    {
                        if (reader.IsStartElementOfType<OpenXmlDrawing.Offset>())
                            position = GetPositionFromReader(reader);
                        else if (reader.IsStartElementOfType<OpenXmlDrawing.Extents>())
                            size = GetSizeFromReader(reader);
                    }
                }
            }

            return new Picture(drawing, filePath, description, name, id, size, position, blipRelationshipId);//, sourceRectangle);
        }