我使用了以下链接的示例代码。 请回答我。 预付款。 我的尝试: CreateWordChart createWordChart = null ; // try { createWordChart = new CreateWordChart(p); 列表< chartsubarea> chartAreas = new List< chartsubarea>(); int j = 0 ; foreach ( var item 在图表中) { 如果(j == 5 ) {j = 0 ; } chartAreas.Add( new ChartSubArea() { Color =(SchemeColorValues)listArr [j], Label = item.Label, Value = item.Value1.ToString()}); j ++; } createWordChart.CreateChart(chartAreas); } catch (例外情况) {} 最后 { 如果(createWordChart!= null ) { createWordChart.Dispose(); } } public void CreateChart(列表< chartsubarea> chartList) { // 获取文档的MainDocumentPart MainDocumentPart mainPart = document.AddMainDocumentPart(); mainPart.Document = new 文档( new Body()); // 在Word文档中创建ChartPart对象 ChartPart chartPart = mainPart.AddNewPart< chartpart>( rId110); // chartPart的根元素 dc.ChartSpace chartSpace = new dc.ChartSpace(); chartSpace.Append( new dc.EditingLanguage(){Val = en-us}); // 创建图表 dc.Chart chart = new dc.Chart(); chart.Append( new dc.AutoTitleDeleted(){Val = true }); // 定义3D视图 dc.View3D view3D = new dc.View3D(); view3D.Append( new dc.RotateX(){Val = 30 }); view3D.Append( new dc.RotateY(){Val = 0 }); // Intiliazes PlotArea类的新实例 dc.PlotArea plotArea = new dc.PlotArea(); plotArea.Append( new dc.Layout()); // 图表类型 dc.Pie3DChart pie3DChart = new dc.Pie3DChart(); pie3DChart.Append( new dc.VaryColors(){Val = true }); dc.PieChartSeries pieChartSers = new dc.PieChartSeries(); pieChartSers.Append( new dc.Index(){Val = 0U}); pieChartSers.Append( new dc.Order(){Val = 0U}); dc.SeriesText seriesText = new dc.SeriesText(); seriesText.Append( new dc.NumericValue(){text = Series}); uint rowcount = 0 ; uint count = UInt32 .Parse(chartList.Count.ToString()); string endCell =(count + 1 )。ToString(); dc.ChartShapeProperties chartShapePros = new dc.ChartShapeProperties(); // 为标签信息定义单元格 dc.CategoryAxisData cateAxisData = new dc.CategoryAxisData(); dc.StringReference stringRef = new dc.StringReference(); stringRef.Append( new dc.Formula(){Text = Main!$ A $ 2:$ A $ + endCell}); dc.StringCache stringCache = new dc.StringCache(); stringCache.Append( new dc.PointCount(){Val = count}); // 定义价值信息的单元格 dc.Values values = new dc.Values(); dc.NumberReference numRef = new dc.NumberReference(); numRef.Append( new dc.Formula(){Text = Main!$ B $ 2:$ B $ + endCell}); dc.NumberingCache numCache = new dc.NumberingCache(); numCache.Append( new dc.FormatCode(){Text = General}); numCache.Append( new dc.PointCount(){Val = count}); // 填写图表数据 foreach ( var item in chartList) { if (count == 0 ) { chartShapePros。追加( new d.SolidFill( new d.SchemeColor(){Val = item.Color})) ; pieChartSers.Append(chartShapePros); } else { dc.DataPoint dataPoint = new dc.DataPoint(); dataPoint.Append( new dc.Index(){Val = rowcount}); chartShapePros = new dc.ChartShapeProperties(); chartShapePros.Append( new d.SolidFill( new d.SchemeColor(){Val = item.Color})); dataPoint.Append(chartShapePros); pieChartSers.Append(dataPoint); } dc.StringPoint stringPoint = new dc.StringPoint(){Index = rowcount}; stringPoint.Append( new dc.NumericValue(){Text = item.Label}); stringCache.Append(stringPoint); dc.NumericPoint numericPoint = new dc.NumericPoint(){Index = rowcount}; numericPoint.Append( new dc.NumericValue(){Text = item.Value}); numCache.Append(numericPoint); rowcount ++; } // 创建c:cat和c:val元素 stringRef.Append(stringCache); cateAxisData.Append(stringRef); numRef.Append(numCache); values.Append(numRef); // 将c:cat和c:val追加到c:ser元素的末尾 pieChartSers.Append(cateAxisData); pieChartSers.Append(values); // 将c:ser附加到c:pie3DChart元素的末尾 pie3DChart.Append(pieChartSers); // 将c:pie3DChart追加到s:plotArea元素的末尾 plotArea.Append(pie3DChart); // 创建c:legend元素的子元素 dc.Legend legend = new dc.Legend(); legend.Append( new dc.LegendPosition(){Val = LegendPositionValues.Bottom}); dc.Overlay overlay = new dc.Overlay(){Val = false }; legend.Append(overlay); dc.TextProperties textPros = new TextProperties(); textPros.Append( new d.BodyProperties()); textPros.Append( new d.ListStyle()); d.Paragraph段落= new d.Paragraph(); d.ParagraphProperties paraPros = new d.ParagraphProperties(); d.DefaultParagraphProperties defaultParaPros = new d.DefaultParagraphProperties(); defaultParaPros.Append( new d.LatinFont(){Typeface = Arial,PitchFamily = 34 ,CharacterSet = 0 }) ; defaultParaPros.Append( new d.ComplexScriptFont(){Typeface = Arial,PitchFamily = 34 ,CharacterSet = 0 }) ; paraPros.Append(defaultParaPros); paragraph.Append(paraPros); paragraph.Append( new d.EndParagraphRunProperties(){Language = en-Us}); textPros.Append(paragraph); legend.Append(textPros); // 追加c:view3D,c:plotArea和c:legend元素到最后c:图表元素 chart.Append(view3D); chart.Append(plotArea); chart.Append(传奇); // 将c:chart元素追加到c:chartSpace元素的末尾 chartSpace.Append(图表); // 创建c:spPr元素并填充其子元素 chartShapePros = new dc.ChartShapeProperties(); d.Outline outline = new d.Outline(); outline.Append( new d.NoFill()); chartShapePros.Append(outline); // 将c:spPr元素追加到c:chartSpace元素的结尾 chartSpace.Append(chartShapePros); chartPart.ChartSpace = chartSpace; // 生成MainDocumentPart的内容 GeneratePartContent(mainPart) ); } public class ChartSubArea { public SchemeColorValues Color { get ; set ; } public 字符串标签{ get ; set ; } public string 值{ get ; set ; } } < / chartpart > < / chartsubarea > < / chartsubarea > < / chartsubarea > 解决方案 A 2: A Sir, I am trying to create a pie chart, then export to word using OpenXml in c#.net. But the problem is, 1) It is exporting but nothing shows ms word 2010 only. 2) I am using ASP.NET MVC4 project, there is a google pie chart which has around 1000 data by representing with multiple color. But I cannot see all details from Word when it is exported at first time. Now it seems color only. How can I see all data when exporting word 2016 at first time?This is my Google Pie-chart. I am trying to export to word 2016 using OpenXml in ASP.NET MVC4, same as the image looking. Please see below link.I have used the sample code for this below link.Kindly answer me.Advance Thanks.What I have tried:CreateWordChart createWordChart = null;//try{ createWordChart = new CreateWordChart(p); List<chartsubarea> chartAreas = new List<chartsubarea>(); int j=0; foreach (var item in charts) { if (j == 5) { j = 0; } chartAreas.Add(new ChartSubArea() { Color = (SchemeColorValues)listArr[j], Label = item.Label, Value = item.Value1.ToString() }); j++; } createWordChart.CreateChart(chartAreas);}catch (Exception ex){}finally{ if (createWordChart != null) { createWordChart.Dispose(); }}public void CreateChart(List<chartsubarea> chartList){ // Get MainDocumentPart of Document MainDocumentPart mainPart = document.AddMainDocumentPart(); mainPart.Document = new Document(new Body()); // Create ChartPart object in Word Document ChartPart chartPart = mainPart.AddNewPart<chartpart>("rId110"); // the root element of chartPart dc.ChartSpace chartSpace = new dc.ChartSpace(); chartSpace.Append(new dc.EditingLanguage() { Val = "en-us" }); // Create Chart dc.Chart chart = new dc.Chart(); chart.Append(new dc.AutoTitleDeleted() { Val = true }); // Define the 3D view dc.View3D view3D = new dc.View3D(); view3D.Append(new dc.RotateX() { Val = 30 }); view3D.Append(new dc.RotateY() { Val = 0 }); // Intiliazes a new instance of the PlotArea class dc.PlotArea plotArea = new dc.PlotArea(); plotArea.Append(new dc.Layout()); // the type of Chart dc.Pie3DChart pie3DChart = new dc.Pie3DChart(); pie3DChart.Append(new dc.VaryColors() { Val = true }); dc.PieChartSeries pieChartSers = new dc.PieChartSeries(); pieChartSers.Append(new dc.Index() { Val = 0U }); pieChartSers.Append(new dc.Order() { Val = 0U }); dc.SeriesText seriesText = new dc.SeriesText(); seriesText.Append(new dc.NumericValue() { Text = "Series" }); uint rowcount = 0; uint count = UInt32.Parse(chartList.Count.ToString()); string endCell = (count + 1).ToString(); dc.ChartShapeProperties chartShapePros = new dc.ChartShapeProperties(); // Define cell for lable information dc.CategoryAxisData cateAxisData = new dc.CategoryAxisData(); dc.StringReference stringRef = new dc.StringReference(); stringRef.Append(new dc.Formula() { Text = "Main!$A$2:$A$" + endCell }); dc.StringCache stringCache = new dc.StringCache(); stringCache.Append(new dc.PointCount() { Val = count }); // Define cells for value information dc.Values values = new dc.Values(); dc.NumberReference numRef = new dc.NumberReference(); numRef.Append(new dc.Formula() { Text = "Main!$B$2:$B$" + endCell }); dc.NumberingCache numCache = new dc.NumberingCache(); numCache.Append(new dc.FormatCode() { Text = "General" }); numCache.Append(new dc.PointCount() { Val = count }); // Fill data for chart foreach (var item in chartList) { if (count == 0) { chartShapePros.Append(new d.SolidFill(new d.SchemeColor() { Val = item.Color })); pieChartSers.Append(chartShapePros); } else { dc.DataPoint dataPoint = new dc.DataPoint(); dataPoint.Append(new dc.Index() { Val = rowcount }); chartShapePros = new dc.ChartShapeProperties(); chartShapePros.Append(new d.SolidFill(new d.SchemeColor() { Val = item.Color })); dataPoint.Append(chartShapePros); pieChartSers.Append(dataPoint); } dc.StringPoint stringPoint = new dc.StringPoint() { Index = rowcount }; stringPoint.Append(new dc.NumericValue() { Text = item.Label }); stringCache.Append(stringPoint); dc.NumericPoint numericPoint = new dc.NumericPoint() { Index = rowcount }; numericPoint.Append(new dc.NumericValue() { Text = item.Value }); numCache.Append(numericPoint); rowcount++; } // Create c:cat and c:val element stringRef.Append(stringCache); cateAxisData.Append(stringRef); numRef.Append(numCache); values.Append(numRef); // Append c:cat and c:val to the end of c:ser element pieChartSers.Append(cateAxisData); pieChartSers.Append(values); // Append c:ser to the end of c:pie3DChart element pie3DChart.Append(pieChartSers); // Append c:pie3DChart to the end of s:plotArea element plotArea.Append(pie3DChart); // create child elements of the c:legend element dc.Legend legend = new dc.Legend(); legend.Append(new dc.LegendPosition() { Val = LegendPositionValues.Bottom }); dc.Overlay overlay = new dc.Overlay() { Val = false }; legend.Append(overlay); dc.TextProperties textPros = new TextProperties(); textPros.Append(new d.BodyProperties()); textPros.Append(new d.ListStyle()); d.Paragraph paragraph = new d.Paragraph(); d.ParagraphProperties paraPros = new d.ParagraphProperties(); d.DefaultParagraphProperties defaultParaPros = new d.DefaultParagraphProperties(); defaultParaPros.Append(new d.LatinFont() { Typeface = "Arial", PitchFamily = 34, CharacterSet = 0 }); defaultParaPros.Append(new d.ComplexScriptFont() { Typeface = "Arial", PitchFamily = 34, CharacterSet = 0 }); paraPros.Append(defaultParaPros); paragraph.Append(paraPros); paragraph.Append(new d.EndParagraphRunProperties() { Language = "en-Us" }); textPros.Append(paragraph); legend.Append(textPros); // Append c:view3D, c:plotArea and c:legend elements to the end of c:chart element chart.Append(view3D); chart.Append(plotArea); chart.Append(legend); // Append the c:chart element to the end of c:chartSpace element chartSpace.Append(chart); // Create c:spPr Elements and fill the child elements of it chartShapePros = new dc.ChartShapeProperties(); d.Outline outline = new d.Outline(); outline.Append(new d.NoFill()); chartShapePros.Append(outline); // Append c:spPr element to the end of c:chartSpace element chartSpace.Append(chartShapePros); chartPart.ChartSpace = chartSpace; // Generate content of the MainDocumentPart GeneratePartContent(mainPart);}public class ChartSubArea{ public SchemeColorValues Color { get; set; } public String Label { get; set; } public string Value { get; set; }}</chartpart></chartsubarea></chartsubarea></chartsubarea> 解决方案 A2:A 这篇关于使用C#将饼图导出到Word 2010时,为什么不显示任何内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-30 18:57