/*********************************** * 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; }
/*********************************** * 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; }
/*********************************** * PUBLIC METHODS ************************************/ public Drawing Clone(Worksheet worksheet) { Drawing newDrawing = new Drawing(worksheet, ""); newDrawing.Shapes = Shapes.Clone(newDrawing); return newDrawing; }
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); } } }
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; }
// 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 }
/*********************************** * PUBLIC METHODS ************************************/ public Picture Clone(Drawing drawing) { int id = Picture.GetNextPictureId(drawing.Worksheet.Workbook); return new Picture(drawing, FilePath, Description, Name, id, Size, Position, ""); }
private static OpenXmlPackaging.OpenXmlPart GetMediaPartFromDrawing(Drawing drawing, string relationshipId) { OpenXmlPackaging.DrawingsPart drawingsPart = Drawing.GetDrawingsPartFromDrawing(drawing); OpenXmlPackaging.OpenXmlPart mediaPart = drawingsPart.GetPartById(relationshipId); return mediaPart; }
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 ""; }
/*********************************** * 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); }