Navnath Sanap

Navnath Sanap

  • NA
  • 3
  • 9.8k

Creating Word Interop chart in c#

May 25 2013 12:45 AM
I am working on creating a Interop.Word.Chart object dynamically & inserting it in word doc. I am done with the task but now i want to change the color for each data point in single series. I am using xl3dclustured column chart. Can anyone help me with this problem??

cursor = "Graph";                   

wrdRng = doc.Bookmarks.get_Item(ref cursor).Range;                    //doc.InlineShapes.AddPicture(chart, ref oMissing, ref save, wrdRng);                    Word.InlineShape objShape = doc.InlineShapes.AddChart(Microsoft.Office.Core.XlChartType.xl3DColumnClustered,wrdRng);  Word.Chart xlchart = objShape.Chart;

xlchart.ChartStyle = 3;

xlchart.HasLegend = false;

Workbook wb = xlchart.ChartData.Workbook;

Worksheet dataSheet = wb.Worksheets["Sheet1"];

Excel.Range tblRng = dataSheet.get_Range("A1", "B5");

Excel.ListObject tbl = dataSheet.ListObjects["Table1"]; 

tbl.Resize(tblRng);

((Excel.Range)dataSheet.Cells.get_Range("A2", oMissing)).FormulaR1C1 = "High";                  ((Excel.Range)dataSheet.Cells.get_Range("A3", oMissing)).FormulaR1C1 = "Medium";              ((Excel.Range)dataSheet.Cells.get_Range("A4", oMissing)).FormulaR1C1 = "Low";                  ((Excel.Range)dataSheet.Cells.get_Range("A5", oMissing)).FormulaR1C1 = "Info";                  ((Excel.Range)dataSheet.Cells.get_Range("B2", oMissing)).FormulaR1C1 = high;                    ((Excel.Range)dataSheet.Cells.get_Range("B3", oMissing)).FormulaR1C1 = medium;                ((Excel.Range)dataSheet.Cells.get_Range("B4", oMissing)).FormulaR1C1 = low;                    ((Excel.Range)dataSheet.Cells.get_Range("B5", oMissing)).FormulaR1C1 = info;                   Word.Series sr = xlchart.SeriesCollection("Series 1");

Word.Point pt = sr.Points("High");


Answers (2)