internal void FeedDataChartPart(ChartPart NewPart, ChartPart ExistingPart)
        {
            using (StreamReader sr = new StreamReader(ExistingPart.GetStream()))
            {
                using (StreamWriter sw = new StreamWriter(NewPart.GetStream(FileMode.Create)))
                {
                    sw.Write(sr.ReadToEnd());
                }
            }

            ImagePart imgpNew;

            if (ExistingPart.ChartDrawingPart != null)
            {
                NewPart.AddNewPart<ChartDrawingPart>(ExistingPart.GetIdOfPart(ExistingPart.ChartDrawingPart));
                using (StreamReader sr = new StreamReader(ExistingPart.ChartDrawingPart.GetStream()))
                {
                    using (StreamWriter sw = new StreamWriter(NewPart.ChartDrawingPart.GetStream(FileMode.Create)))
                    {
                        sw.Write(sr.ReadToEnd());
                    }
                }

                // why does a ChartPart contain a ChartDrawingPart that contains a ChartPart??
                // Does it never end??
                if (ExistingPart.ChartDrawingPart.ChartPart != null)
                {
                    NewPart.ChartDrawingPart.AddNewPart<ChartPart>(ExistingPart.ChartDrawingPart.GetIdOfPart(ExistingPart.ChartDrawingPart.ChartPart));
                    this.FeedDataChartPart(NewPart.ChartDrawingPart.ChartPart, ExistingPart.ChartDrawingPart.ChartPart);
                }

                foreach (ImagePart imgp in ExistingPart.ChartDrawingPart.ImageParts)
                {
                    imgpNew = NewPart.ChartDrawingPart.AddImagePart(imgp.ContentType, ExistingPart.ChartDrawingPart.GetIdOfPart(imgp));
                    this.FeedDataImagePart(imgpNew, imgp);
                }
            }

            if (ExistingPart.EmbeddedPackagePart != null)
            {
                NewPart.AddEmbeddedPackagePart(ExistingPart.EmbeddedPackagePart.ContentType);
                this.FeedDataEmbeddedPackagePart(NewPart.EmbeddedPackagePart, ExistingPart.EmbeddedPackagePart);
            }

            foreach (ImagePart imgp in ExistingPart.ImageParts)
            {
                imgpNew = NewPart.AddImagePart(imgp.ContentType, ExistingPart.GetIdOfPart(imgp));
                this.FeedDataImagePart(imgpNew, imgp);
            }

            if (ExistingPart.ThemeOverridePart != null)
            {
                NewPart.AddNewPart<ThemeOverridePart>(ExistingPart.GetIdOfPart(ExistingPart.ThemeOverridePart));
                this.FeedDataThemeOverridePart(NewPart.ThemeOverridePart, ExistingPart.ThemeOverridePart);
            }
        }
예제 #2
0
 public void AddEmbeddedToChartPart(ChartPart part)
 {
     EmbeddedPackagePart embeddedPackagePart1 = part.AddNewPart<EmbeddedPackagePart>("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", ExternalDataId);
     BinaryStream.Position = 0;
     embeddedPackagePart1.FeedData(BinaryStream);
     BinaryStream.Close();
 }