internal void FeedDataVmlDrawingPart(VmlDrawingPart NewPart, VmlDrawingPart ExistingPart) { using (StreamReader sr = new StreamReader(ExistingPart.GetStream())) { using (StreamWriter sw = new StreamWriter(NewPart.GetStream(FileMode.Create))) { sw.Write(sr.ReadToEnd()); } } ImagePart imgpNew; foreach (ImagePart imgp in ExistingPart.ImageParts) { imgpNew = NewPart.AddImagePart(imgp.ContentType, ExistingPart.GetIdOfPart(imgp)); this.FeedDataImagePart(imgpNew, imgp); } LegacyDiagramTextPart ldtpNew; foreach (var ldtp in ExistingPart.LegacyDiagramTextParts) { ldtpNew = NewPart.AddNewPart<LegacyDiagramTextPart>(ExistingPart.GetIdOfPart(ldtp)); using (StreamReader sr = new StreamReader(ldtp.GetStream())) { using (StreamWriter sw = new StreamWriter(ldtpNew.GetStream(FileMode.Create))) { sw.Write(sr.ReadToEnd()); } } } }
// Generates content of vmlDrawingPart1. private static void GenerateVmlDrawingPartContent(VmlDrawingPart vmlDrawingPart, XLWorksheet xlWorksheet, SaveContext context) { var ms = new MemoryStream(); CopyStream(vmlDrawingPart.GetStream(FileMode.OpenOrCreate), ms); ms.Position = 0; var writer = new XmlTextWriter(vmlDrawingPart.GetStream(FileMode.Create), Encoding.UTF8); writer.WriteStartElement("xml"); const string shapeTypeId = "_x0000_t202"; // arbitrary, assigned by office new Vml.Shapetype( new Vml.Stroke {JoinStyle = Vml.StrokeJoinStyleValues.Miter}, new Vml.Path {AllowGradientShape = true, ConnectionPointType = ConnectValues.Rectangle} ) { Id = shapeTypeId, CoordinateSize = "21600,21600", OptionalNumber = 202, EdgePath = "m,l,21600r21600,l21600,xe", } .WriteTo(writer); var cellWithComments = xlWorksheet.Internals.CellsCollection.GetCells().Where(c => c.HasComment); foreach (var c in cellWithComments) { GenerateShape(c, shapeTypeId).WriteTo(writer); } if (ms.Length > 0) { ms.Position = 0; var xdoc = XDocumentExtensions.Load(ms); xdoc.Root.Elements().ForEach(e => writer.WriteRaw(e.ToString())); } writer.WriteEndElement(); writer.Flush(); writer.Close(); }
// Generates content of vmlDrawingPart1. private void GenerateVmlDrawingPart1Content(VmlDrawingPart vmlDrawingPart1) { System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(vmlDrawingPart1.GetStream(System.IO.FileMode.Create), System.Text.Encoding.UTF8); writer.WriteRaw("<xml xmlns:v=\"urn:schemas-microsoft-com:vml\"\r\n xmlns:o=\"urn:schemas-microsoft-com:office:office\"\r\n xmlns:x=\"urn:schemas-microsoft-com:office:excel\">\r\n <o:shapelayout v:ext=\"edit\">\r\n <o:idmap v:ext=\"edit\" data=\"1\"/>\r\n </o:shapelayout><v:shapetype id=\"_x0000_t202\" coordsize=\"21600,21600\" o:spt=\"202\"\r\n path=\"m,l,21600r21600,l21600,xe\">\r\n <v:stroke joinstyle=\"miter\"/>\r\n <v:path gradientshapeok=\"t\" o:connecttype=\"rect\"/>\r\n </v:shapetype><v:shape id=\"_x0000_s1025\" type=\"#_x0000_t202\" style=\'position:absolute;\r\n margin-left:1067.25pt;margin-top:247.5pt;width:108pt;height:59.25pt;\r\n z-index:1;visibility:visible\' fillcolor=\"#ffffe1\" o:insetmode=\"auto\">\r\n <v:fill color2=\"#ffffe1\"/>\r\n <v:shadow color=\"black\" obscured=\"t\"/>\r\n <v:path o:connecttype=\"none\"/>\r\n <v:textbox style=\'mso-direction-alt:auto\'>\r\n <div style=\'text-align:left\'></div>\r\n </v:textbox>\r\n <x:ClientData ObjectType=\"Note\">\r\n <x:MoveWithCells/>\r\n <x:SizeWithCells/>\r\n <x:Anchor>\r\n 22, 15, 8, 10, 24, 31, 12, 9</x:Anchor>\r\n <x:AutoFill>False</x:AutoFill>\r\n <x:Row>9</x:Row>\r\n <x:Column>21</x:Column>\r\n <x:Visible/>\r\n </x:ClientData>\r\n </v:shape></xml>"); writer.Flush(); writer.Close(); }