旨在实现: 我想改变源数据的使用VB.Net到一个名为范围在Excel中我的数据透视表。
我有:
table.ChangePivotCache(wb.PivotCaches.Create(SourceType:=Excel.XlPivotTableSourceType.xlDatabase, SourceData:= sheet.Names(name_of_NamedRange)RefersToRange))。
例外:
参数不正确。 (异常来自HRESULT:80070057(E_INVALIDARG))
解决方案
SourceData必须是包含地址,包括工作表的名称,如我的表A1字符串:B10。试试这个:
table.ChangePivotCache(wb.PivotCaches.Create(SourceType:=Excel.XlPivotTableSourceType.xlDatabase, SourceData:= sheet.Names(name_of_NamedRange)RefersToRange.Address。(外部:= TRUE)))Aim to achieve : I want to change the source data for my pivot table in Excel using VB.Net to a named range.
I have :
table.ChangePivotCache(wb.PivotCaches.Create(SourceType:=Excel.XlPivotTableSourceType.xlDatabase, SourceData:=sheet.Names("name_of_NamedRange").RefersToRange))
Exception :
The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
解决方案
SourceData needs to be a string that contains the address, including the sheet name, like 'My Sheet'!A1:B10. Try this:
table.ChangePivotCache(wb.PivotCaches.Create(SourceType:=Excel.XlPivotTableSourceType.xlDatabase, SourceData:=sheet.Names("name_of_NamedRange").RefersToRange.Address(External:=True)))