Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Insert Excel Chart in Word
Message
From
19/07/2011 16:34:48
 
 
To
19/07/2011 16:04:18
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Miscellaneous
Thread ID:
01518504
Message ID:
01518544
Views:
42
>>>Hi,
>>>
>>>I am trying to create a chart in Excel and then place it in a Word document.
>>
>>When I did this for a client last year, I found that it worked best to save the chart, close Excel and then use Word's InlineShapes.AddOLEObject method to put the chart into the document. The key part of my code looks like this, where cChartFile contains the name of the chart file.
>>
>>
>>	oRange = oDoc.Bookmarks["Graph"].Range()
>>	oRange.Collapse(0)
>>	
>>	oChart = oDoc.InlineShapes.AddOLEObject(, m.cChartFile, .F., .F., , , ,m.oRange)
>>
>>
>>Tamar
>
>Thanks Tamar,
>
>that's one step closer in that the chart has been pasted next to the bookmark, but not replaced the bookmark. Also, the picture of the graph, plus the underlying worksheet is displayed whereas I just want the chart. How do you create your chart. I have code like this:
>
>
    			m.loChart1 = m.loXLSheet.ChartObjects.Add(100, 100, 200, 200)
>
>			    With m.loChart1.Chart
>	    			.ApplyCustomType(xlBuiltIn, "Lines on 2 Axes")
>					.SetSourceData(m.loXLSheet.Range("A1:D7"), xlColumns)
>					.SeriesCollection(1).Delete
>					.SeriesCollection(1).Delete
>					.Location(xlLocationAsObject, "Sheet1")
>			        .HasTitle = .T.
>			        .ChartTitle.Characters.Text = "Claims Received/Turnaround"
>			        .Axes(xlCategory, xlPrimary).HasTitle = .T.
>			        .Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Month"
>			        .Axes(xlValue, xlPrimary).HasTitle = .T.
>			        .Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Claims Received"
>*!* these are giving an error which I have not yet worked on
>*!*				        .Axes(xlCategory, xlSecondary).HasTitle = .T.
>*!*				        .Axes(xlCategory, xlSecondary).AxisTitle.Characters.Text = ""
>*!*				        .Axes(xlValue, xlSecondary).HasTitle = .T.
>*!*				        .Axes(xlValue, xlSecondary).AxisTitle.Characters.Text = "Avg. Turnaround"
>			    EndWith
>			    With m.loChart1.Chart.Axes(xlCategory)
>			        .HasMajorGridlines = .F.
>			        .HasMinorGridlines = .F.
>			    EndWith
>			    With m.loChart1.Chart.Axes(xlValue)
>			        .HasMajorGridlines = .T.
>			        .HasMinorGridlines = .F.
>			    EndWith
>			    m.loChart1.Chart.HasDataTable = .F.
>    
>				m.lcChartFile = ADDBS(m.loCommonFolder.getfolder(CSIDL_PERSONAL)) + ;
>					FORCEEXT(ALLTRIM(c_ClaimsTurnAround.cli_name) + "-Turnaround", "XLS")
>				m.loXLSheet.Saveas(m.lcChartFile)
>
>				IF !m.lHasExcel97
>					m.loXLSheet.APPLICATION.QUIT
>				ENDIF
>				RELEASE m.loXLSheet
>
>				oRange = m.loDoc.Bookmarks["TurnaroundChart"].Range()
>				oRange.Collapse(0)
>				
>				oChart = m.loDoc.InlineShapes.AddOLEObject(, m.lcChartFile, .F., .F., , , ,m.oRange)
>
>What does the Range.Collapse(0) do?

I was creating the workbook on the fly, pulling data from VFP. The key lines are:
	oChart = oWorkbook.Charts.Add()
	oChart.ChartWizard(m.oSourceRange,  -4102, 4 , 2, 1, 0, .T., [My Chart Title])
Collapse(0) collapses the range to a point at the end of the range. Ah, just looked at the code again. Later on, I delete the bookmark.

Tamar
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform