示例#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;
 }
示例#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;
 }
示例#3
0
 /***********************************
  * PUBLIC METHODS
  ************************************/
 public Drawing Clone(Worksheet worksheet)
 {
     Drawing newDrawing = new Drawing(worksheet, "");
     newDrawing.Shapes = Shapes.Clone(newDrawing);
     return newDrawing;
 }
示例#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);
                }

            }
        }
示例#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;
        }
示例#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
 }
示例#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, "");
 }
示例#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;
 }
示例#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 "";
        }
示例#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);
        }