Esempio n. 1
0
        public static void supprChart(WorksheetPart worksheetPart, string titre)
        {
            DrawingsPart a = worksheetPart.DrawingsPart;

            DrawingsPart            dp  = worksheetPart.DrawingsPart;
            IEnumerable <ChartPart> cps = a.ChartParts;

            ChartPart b = null;

            foreach (ChartPart cp in cps)
            {
                if (cp.ChartSpace.Descendants <Chart.Chart>().First().Descendants <Chart.Title>().First().Descendants <DocumentFormat.OpenXml.Drawing.Run>().First().Text.Text == titre)
                {
                    b = cp;
                }
            }

            //obtention id du modèle
            string id = a.GetIdOfPart(b);

            a.DeletePart(b);

            //Suppression de l'ancre associée
            DocumentFormat.OpenXml.Drawing.Spreadsheet.WorksheetDrawing wsd = a.WorksheetDrawing;
            foreach (Draw.TwoCellAnchor tca in wsd.Elements <Draw.TwoCellAnchor>())
            {
                string tmp = tca.Descendants <Chart.ChartReference>().First().Id;
                if (tmp == id)
                {
                    tca.Remove();
                }
            }
        }
Esempio n. 2
0
        //calcul dans li et col les dimensions du plus grand chart
        public static void maxDimChart(WorksheetPart wsp, out int li, out int col)
        {
            Draw.WorksheetDrawing wsd = wsp.DrawingsPart.WorksheetDrawing;
            int maxLi = 0, maxCol = 0;

            foreach (Draw.TwoCellAnchor tca in wsd.Elements <Draw.TwoCellAnchor>())
            {
                int r = Convert.ToInt32(tca.ToMarker.RowId.Text) - Convert.ToInt32(tca.FromMarker.RowId.Text);
                int c = Convert.ToInt32(tca.ToMarker.ColumnId.Text) - Convert.ToInt32(tca.FromMarker.ColumnId.Text);

                if (r > maxLi)
                {
                    maxLi = r;
                }
                if (c > maxCol)
                {
                    maxCol = c;
                }
            }
            li  = maxLi + 1;
            col = maxCol + 1;
        }
Esempio n. 3
0
        public static ChartPart cloneChart(WorksheetPart worksheetPart, string chartTitle, int posLi, int posCol, int largeLi, int largeCol)
        {
            //Obtention de tous les ChartParts dans une enumeration
            DrawingsPart            dp  = worksheetPart.DrawingsPart;
            IEnumerable <ChartPart> cps = dp.ChartParts;

            //Recherche la ChartPart qui porte le titre correspondant
            ChartPart b = null;

            foreach (ChartPart cp in cps)
            {
                if (cp.ChartSpace.Descendants <Chart.Chart>().First().Descendants <Chart.Title>().First().Descendants <DocumentFormat.OpenXml.Drawing.Run>().First().Text.Text == chartTitle)
                {
                    b = cp;
                }
            }

            DrawingsPart a = worksheetPart.DrawingsPart;

            //Ajout de la nouvelle partie et copie
            ChartPart x      = a.AddNewPart <ChartPart>();
            Stream    stream = b.GetStream();

            x.FeedData(stream);

            string id = a.GetIdOfPart(b);

            //Copie de l'ancre associée au graph original
            Draw.TwoCellAnchor newAnchor = null;
            DocumentFormat.OpenXml.Drawing.Spreadsheet.WorksheetDrawing wsd = a.WorksheetDrawing;
            foreach (Draw.TwoCellAnchor tca in wsd.Elements <Draw.TwoCellAnchor>())
            {
                string tmp = tca.Descendants <Chart.ChartReference>().First().Id;
                if (tmp == id)
                {
                    newAnchor = (Draw.TwoCellAnchor)tca.CloneNode(true);
                }
            }

            //positionnement de la nouvelle ancre
            int r = Convert.ToInt32(newAnchor.ToMarker.RowId.Text) - Convert.ToInt32(newAnchor.FromMarker.RowId.Text);
            int c = Convert.ToInt32(newAnchor.ToMarker.ColumnId.Text) - Convert.ToInt32(newAnchor.FromMarker.ColumnId.Text);

            newAnchor.FromMarker.ColumnId = new Draw.ColumnId()
            {
                Text = "" + largeCol * posCol
            };
            newAnchor.ToMarker.ColumnId = new Draw.ColumnId()
            {
                Text = "" + (c + largeCol * posCol)
            };

            newAnchor.FromMarker.RowId = new Draw.RowId()
            {
                Text = "" + largeLi * posLi
            };
            newAnchor.ToMarker.RowId = new Draw.RowId()
            {
                Text = "" + (r + largeLi * posLi)
            };
            newAnchor.Descendants <Chart.ChartReference>().First().Id = a.GetIdOfPart(x);
            wsd.Append(newAnchor);

            return(x);
        }