Excel chart in Word 2007
-
Sunday, May 06, 2012 9:54 AM
Hi all, im writing Word 2007 document-level customization (VSTO). I want to generate chart into that document. I call excel charting engine and generate that chart. But in the chart is painted only first 5 rows and not all of data that i want. Can someone help me please with this? Thanks for any reply or help. Pictures and code will make this a bit more clear.
my code for generate this chart in word:
private void Chart(double[] input, int ktory) { object oRng=new object(); Microsoft.Office.Core.XlChartType type = 0; string name = ""; switch (ktory) { case 1: oRng = this.bkmrT1.Range; type = Microsoft.Office.Core.XlChartType.xlColumnStacked; name = "Histogram"; break; case 2: oRng = this.bkmrT2.Range; type = Microsoft.Office.Core.XlChartType.xlColumnClustered; name = "Polygón"; break; case 3: oRng = this.bkmrT3.Range; type = Microsoft.Office.Core.XlChartType.xlLineMarkers; name = "Kumulovaná krivka"; break; default: break; } Word.InlineShape ils = this.InlineShapes.AddChart(type, ref oRng); Word.Chart c = ils.Chart; Excel.Workbook wb = (Excel.Workbook)c.ChartData.Workbook; Excel.Worksheet ws = (Excel.Worksheet)wb.Worksheets[1]; Excel.ListObject lo = ws.ListObjects[1]; var range = ws.get_Range("A1", string.Format("B{0}", input.Length + 1)); lo.Resize(range); range = ws.get_Range("C1", "Z50"); range.Cells.ClearContents(); ws.Cells[1, 2] = name; for (int i = 1; i <= input.Length; i++) { ws.Cells[i + 1, 1] = i; ws.Cells[i + 1, 2] = input[i - 1]; } ils.Height = 200; c.Refresh(); this.Save(); c.Refresh(); wb.Close(true, missing, missing); }
All Replies
-
Sunday, May 06, 2012 10:42 AM
Yo have a named range in te workbook which is wrong. You have to change the following named range : this.bkmrT1.Range
- Edited by Joel EngineerMicrosoft Community Contributor Sunday, May 06, 2012 10:47 AM
-
Sunday, May 06, 2012 12:36 PMthanks for reply, but change to what? its not clear for me. Ondro
-
Sunday, May 06, 2012 1:11 PM
The chart range comes from this instruction
Word.InlineShape ils = this.InlineShapes.AddChart(type, ref oRng);
oRnge si from one of these three instructions
oRng = this.bkmrT1.Range;
oRng = this.bkmrT2.Range;
oRng = this.bkmrT3.Range;
So you need to find out what "this" is? "this" is another object in the class you are using.
jdweng
-
Sunday, May 06, 2012 1:35 PMThanks for reply, as i write above im writing document-level Word customization, "this" means thisdocument or something like that, and bkmrT1, bkmrT2, bkmrT3 are bookmarks in Word. I try to describe problem a bit more. I create new chart in word with VSTO, open excel chart worksheet and fill it up (all with vsto). But chart is only painted from first 5 rows, not all of i insert there. The listobject in excel is also set up well in my opinion. When i run this word customization it create chart as i want but not from all values, as i write. When i click "Change chart data" it shows excel worksheet with all values, that i want, but in chart there are only that first 5 rows. How to make that chart to show all data from excel chart-worksheet?
-
Sunday, May 06, 2012 1:45 PM
I appaear that range is not large enough. try adding one line
rng = rng.CurrentRegion; //<----add this line
Word.InlineShape ils = this.InlineShapes.AddChart(type, ref oRng);jdweng
- Marked As Answer by Quist ZhangMicrosoft Contingent Staff, Moderator Wednesday, May 30, 2012 7:32 AM

