public static void fixChartData(ChartPart cc, string nomSheet, List <int> elems, string colValeur, string colLegende) { Chart.Values v = cc.ChartSpace.Descendants <Chart.Values>().First(); //Formule de mon piechart Chart.Formula f = v.Descendants <Chart.Formula>().First(); string formulaBis = "\'" + nomSheet + "\'!$" + colValeur + "$" + elems.ElementAt(0); foreach (int i in elems.Skip(1)) { formulaBis += ",\'" + nomSheet + "\'!$" + colValeur + "$" + i; } f.Text = formulaBis; //Formule pour les legendes Chart.CategoryAxisData cad = cc.ChartSpace.Descendants <Chart.CategoryAxisData>().First(); //Formule des legendes de mon piechart Chart.Formula f2 = cad.Descendants <Chart.Formula>().First(); string formula2Bis = "\'" + nomSheet + "\'!$" + colLegende + "$" + elems.ElementAt(0); foreach (int i in elems.Skip(1)) { formula2Bis += ",\'" + nomSheet + "\'!$" + colLegende + "$" + i; } f2.Text = formula2Bis; Chart.SeriesText st = cc.ChartSpace.Descendants <Chart.SeriesText>().First(); st.StringReference.Formula.Text = ""; }
public static void fixChartData2(ChartPart cc, string nomSheet, List <int> elems, string colValeur, string colLegende) { //ChartPart cc = wsp.GetPartsOfType<DrawingsPart>().First().ChartParts.First<ChartPart>(); Charts.Values v = cc.ChartSpace.Descendants <Charts.Values>().First(); //Formule de mon piechart Charts.Formula f = v.Descendants <Charts.Formula>().First(); //string id = wbp.GetIdOfPart(wsp); //string nom = "'" + wbp.Workbook.Descendants<Sheet>().Where(s => s.Id.Value.Equals(id)).First().Name + "'!"; string formulaBis = "\'" + nomSheet + "\'!$" + colValeur + "$" + elems.ElementAt(0); foreach (int i in elems.Skip(1)) { formulaBis += ",\'" + nomSheet + "\'!$" + colValeur + "$" + i; } f.Text = formulaBis; //Formule pour les legendes Charts.CategoryAxisData cad = cc.ChartSpace.Descendants <Charts.CategoryAxisData>().First(); //Formule des legendes de mon piechart Charts.Formula f2 = cad.Descendants <Charts.Formula>().First(); string formula2Bis = "\'" + nomSheet + "\'!$" + colLegende + "$" + elems.ElementAt(0); foreach (int i in elems.Skip(1)) { formula2Bis += ",\'" + nomSheet + "\'!$" + colLegende + "$" + i; } f2.Text = formula2Bis; Charts.SeriesText st = cc.ChartSpace.Descendants <Charts.SeriesText>().First(); st.StringReference.Formula.Text = ""; }