SetSourceData正确的调用参数 [英] SetSourceData correct call parameters
问题描述
对以下sniplet的正确呼叫是什么?
//这个会抛出一个例外
Excel.Range range = worksheet.get_Range(A3,B4);
myChart.SetSourceData(range.ToString(),Excel.XlRowCol.xlColumns); //抛出
//抛出异常
异常来源:Microsoft.Office.Interop.PowerPoint
异常类型:System.Runtime.InteropServices.COMException
异常消息:错误HRESULT E_FAIL已从一个
调用COM组件。
异常目标网站:SetSourceData
------------ -------------------------------------------------
//这个不编译
myChart.SetSourceData(range, Excel.XlRowCol.xlColumns);
//编译错误
1>错误CS1502:最佳重载方法匹配'Microsoft.Office.Interop。
PowerPoint.Chart.SetSourceData(string,object)'有一些无效的参数
1>错误CS1503:参数1:无法从
'Microsoft.Office.Interop.Excel.Range'转换为'string'
SetSourceData 以完全不同的方式运行,具体取决于您是否使用Excel库或PowerPoint等其他库中的方法: / p>
Sub SetSourceData(Source As Range ,[PlotBy])
Excel.Chart的成员
Sub SetSourceData(Source As String ,[PlotBy])
PowerPoint.Chart的成员
在PowerPoint模型,该方法期待一个字符串,其中包含包含源数据的图表数据范围的地址!
https://msdn.microsoft.com/en-us/library/office/ff746759 .aspx?f = 255& MSPPError = -2147217396
相同的方法ope在两个不同的MSO对象模型中以两种不同的方式进行评级。现在这很聪明的微软!
What is the correct call for the following sniplet
// this one throws an exception
Excel.Range range = worksheet.get_Range("A3", "B4");
myChart.SetSourceData(range.ToString(), Excel.XlRowCol.xlColumns); // Throws an
// the thrown Exception
Exception Source: Microsoft.Office.Interop.PowerPoint
Exception Type: System.Runtime.InteropServices.COMException
Exception Message: Error HRESULT E_FAIL has been returned from a
call to a COM component.
Exception Target Site: SetSourceData
-------------------------------------------------------------
// this one doesnt compile
myChart.SetSourceData(range, Excel.XlRowCol.xlColumns);
// the compile errors
1> error CS1502: The best overloaded method match for 'Microsoft.Office.Interop.
PowerPoint.Chart.SetSourceData(string, object)' has some invalid arguments
1> error CS1503: Argument 1: cannot convert from
'Microsoft.Office.Interop.Excel.Range' to 'string'
SetSourceData operates in completely different ways depending if you're using the method from the Excel library or another library such as PowerPoint:
Sub SetSourceData(Source As Range, [PlotBy]) Member of Excel.Chart
Sub SetSourceData(Source As String, [PlotBy]) Member of PowerPoint.Chart
In the PowerPoint model, the method is expecting a string which holds the address of the chart data range that contains the source data!
https://msdn.microsoft.com/en-us/library/office/ff746759.aspx?f=255&MSPPError=-2147217396
Same method operating in two different ways in two different MSO object models. Now that's clever Microsoft!
这篇关于SetSourceData正确的调用参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!