<c:chartSpace xmlns:c="http://schemas.openxmlformats.org/drawingml/2006/chart" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"> <c:date1904 val="1" /> <c:lang val="en-US" /> <c:chart> <c:view3D> <c:perspective val="30" /> </c:view3D> <c:plotArea> <c:layout /> <c:bar3DChart> <c:barDir val="col" /> <c:grouping val="clustered" /> <c:ser> <c:idx val="0" /> <c:order val="0" /> <c:tx> <c:strRef> <c:f>Sheet1!$B$1</c:f> <c:strCache> <c:ptCount val="1" /> <c:pt idx="0"> <c:v>Series 1</c:v> </c:pt> </c:strCache> </c:strRef> </c:tx> <c:cat> <c:strRef> <c:f>Sheet1!$A$2:$A$5</c:f> <c:strCache> <c:ptCount val="4" /> <c:pt idx="0"> <c:v>Category 1</c:v> </c:pt> <c:pt idx="1"> <c:v>Category 2</c:v> </c:pt> <c:pt idx="2"> <c:v>Category 3</c:v> </c:pt> <c:pt idx="3"> <c:v>Category 4</c:v> </c:pt> </c:strCache> </c:strRef> </c:cat> <c:val> <c:numRef> <c:f>Sheet1!$B$2:$B$5</c:f> <c:numCache> <c:formatCode>General</c:formatCode> <c:ptCount val="4" /> <c:pt idx="0"> <c:v>4.3</c:v> </c:pt> <c:pt idx="1"> <c:v>2.5</c:v> </c:pt> <c:pt idx="2"> <c:v>3.5</c:v> </c:pt> <c:pt idx="3"> <c:v>4.5</c:v> </c:pt> </c:numCache> </c:numRef> </c:val> </c:ser>
private void ModifyChartDetailed (string cellColumn, uint intRow, string cellValue, bool axisValue) { try { ChartPart c_p = this.mainDocPart.ChartParts.FirstOrDefault(); Chart chart = c_p.ChartSpace.Descendants<Chart>().FirstOrDefault(); PlotArea p_c = chart.PlotArea; Bar3DChart b3d = p_c.Descendants<Bar3DChart>().FirstOrDefault(); BarChartSeries bs1 = b3d.Descendants<BarChartSeries>().Where(s => string.Compare(s.InnerText, "Sheet1!$" + cellColumn + "$1", true) > 0).First(); if (axisValue) { CategoryAxisData v1 = bs1.Descendants<CategoryAxisData>().FirstOrDefault(); StringReference sr = v1.Descendants<StringReference>().First(); StringCache sc = sr.Descendants<StringCache>().First(); StringPoint sp = sc.Descendants<StringPoint>().First(); NumericValue nv = sp.Descendants<NumericValue>().First(); nv.Text = cellValue; } else { DocumentFormat.OpenXml.Drawing.Charts.Values v1 = bs1.Descendants; DocumentFormat.OpenXml.Drawing.Charts.Values>().FirstOrDefault(); NumberReference nr = v1.Descendants<NumberReference>().First(); NumberingCache nc = nr.Descendants<NumberingCache>().First(); NumericPoint np = nc.Descendants<NumericPoint>().ElementAt((int)intRow - 2); NumericValue nv = np.Descendants<NumericValue>().First(); nv.Text = cellValue; } } catch { // Chart Element is not in a recognizable format. // Most likely the defined Chart is incorrect. Ignore the chart creation. return; } }
private void ModifyChartSimplified (string cellColumn, uint intRow, string cellValue, bool axisValue) { try { ChartPart c_p = this.mainDocPart.ChartParts.FirstOrDefault(); BarChartSeries bs1 = c_p.ChartSpace.Descendants<BarChartSeries>().Where (s => string.Compare(s.InnerText, "Sheet1!$" + cellColumn + "$1", true) > 0).First(); if (axisValue) { NumericValue nv1 = bs1.Descendants<NumericValue>().First(); nv1.Text = cellValue; } else { DocumentFormat.OpenXml.Drawing.Charts.Values v1 = bs1.Descendants<DocumentFormat.OpenXml.Drawing.Charts.Values>().FirstOrDefault(); NumericPoint np = v1.Descendants<NumericPoint>().ElementAt((int)intRow - 2); NumericValue nv = np.Descendants<NumericValue>().First(); nv.Text = cellValue; } } catch { // Chart Element is not in a recognizable format. // Most likely the defined Chart is incorrect. Ignore the chart creation. return; } }
V1 - April 28, 2011 - 创建了应用程序并发布
【更多阅读】