This project has moved and is read-only. For the latest updates, please go here.

AddPicture and AddShape Error

Mar 22 at 12:40 PM
If DrawingXml already exists, AddPicture and AddShape will fail. DrawingXml seems to be created for each sheet, so we modified it to use it if it exists.

(ExcelDrawings.cs 429 line ver4.1.0)

        private XmlElement CreateDrawingXml()
        {
            if (DrawingXml.OuterXml == "")
            {
                DrawingXml.LoadXml(string.Format("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><xdr:wsDr xmlns:xdr=\"{0}\" xmlns:a=\"{1}\" />", ExcelPackage.schemaSheetDrawings, ExcelPackage.schemaDrawings));
                _uriDrawing = new Uri(string.Format("/xl/drawings/drawing{0}.xml", Worksheet.SheetID),UriKind.Relative);

                Packaging.ZipPackage package = Worksheet._package.Package;

                // FIX ----- 
                if (package.PartExists(_uriDrawing))
                {
                    _part = package.GetPart(_uriDrawing);
                }
                else
                {
                    _part = package.CreatePart(_uriDrawing, "application/vnd.openxmlformats-officedocument.drawing+xml", _package.Compression);
                }
                // FIX -----